1:5.8.1p1-3
[openssh.git] / debian / openssh-server.postrm
1 #!/bin/sh -e
2
3 #DEBHELPER#
4
5 abort_mv_conffile () {
6         CONFFILE="$1"
7
8         if [ ! -e "$CONFFILE" ]; then
9                 if [ -e "$CONFFILE.dpkg-old" ]; then
10                         mv -f "$CONFFILE.dpkg-old" "$CONFFILE"
11                 elif [ -e "$CONFFILE.moving" ]; then
12                         mv -f "$CONFFILE.moving" "$CONFFILE"
13                 fi
14         fi
15 }
16
17 finish_mv_conffile () {
18         CONFFILE="$1"
19
20         if [ -e "$CONFFILE.dpkg-old" ]; then
21                 rm -f "$CONFFILE.dpkg-old"
22         fi
23 }
24
25 abort_transfer_conffile () {
26         CONFFILE="$1"
27         if [ -e "$CONFFILE.moved-by-preinst" ]; then
28                 echo >&2 "Aborting ownership transfer of conffile $CONFFILE ..."
29                 mv -f "$CONFFILE.moved-by-preinst" "$CONFFILE"
30                 return 0
31         fi
32 }
33
34 case $1 in
35         abort-install|abort-upgrade)
36                 if dpkg --compare-versions "$2" lt 1:4.7p1-4; then
37                         abort_mv_conffile /etc/pam.d/ssh
38                 fi
39                 abort_transfer_conffile /etc/default/ssh
40                 abort_transfer_conffile /etc/init.d/ssh
41                 abort_transfer_conffile /etc/pam.d/ssh
42                 ;;
43         purge)
44                 # Remove all non-conffiles that ssh might create, so that we
45                 # can smoothly remove /etc/ssh if and only if the user
46                 # hasn't dropped some other files in there. Conffiles have
47                 # already been removed at this point.
48                 rm -f /etc/ssh/ssh_host_key /etc/ssh/ssh_host_key.pub
49                 rm -f /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_rsa_key.pub
50                 rm -f /etc/ssh/ssh_host_dsa_key /etc/ssh/ssh_host_dsa_key.pub
51                 rm -f /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ecdsa_key.pub
52                 rm -f /etc/ssh/sshd_config
53                 rm -f /etc/ssh/sshd_not_to_be_run
54                 rmdir --ignore-fail-on-non-empty /etc/ssh
55
56                 update-rc.d ssh remove >/dev/null
57
58                 if which deluser >/dev/null 2>&1; then
59                         deluser --quiet sshd > /dev/null || true
60                 fi
61
62                 finish_mv_conffile /etc/pam.d/ssh
63                 ;;
64 esac
65
66 exit 0