Merge tag 'upstream/1.8.5p2'
[debian/sudo] / debian / sudo-ldap.postinst
1 #!/bin/sh
2
3 set -e
4
5 # remove old link
6
7 if [ -L /etc/alternatives/sudo ]; then
8         rm /etc/alternatives/sudo
9 fi
10
11 # complain if no sudoers file is present
12 if [ ! -f /etc/sudoers ];then
13         echo "WARNING:  /etc/sudoers not present!";
14 fi
15
16 # modify nsswitch.conf if needed
17 if [ -z "`grep \"^sudoers:\" /etc/nsswitch.conf`" ]
18 then
19         echo "sudoers:  files ldap" >> /etc/nsswitch.conf
20 fi
21
22 # handle state directory transition from /var/run/sudo to /var/lib/sudo,
23 # moving any existing content over to avoid re-lecturing existing users
24 if [ -d "/var/run/sudo" ];then
25     mkdir -p /var/lib/sudo
26     (cd /var/run/sudo ; tar cf - .) | (cd /var/lib/sudo ; tar xf -)
27     rm -rf /var/run/sudo
28 fi
29
30 # make sure sudoers has the correct permissions and owner/group
31 chown root:root /etc/sudoers
32 chmod 440 /etc/sudoers
33
34 update-rc.d -f sudo remove >/dev/null 2>&1
35
36 update-rc.d sudo start 75 2 3 4 5 . >/dev/null
37
38 # create symlink to ease transition to new path for ldap config
39 # if old config file exists and new one doesn't
40 if [ -e /etc/ldap/ldap.conf -a ! -e /etc/sudo-ldap.conf ];then
41         ln -s ldap/ldap.conf /etc/sudo-ldap.conf
42 fi
43
44 # if we've gotten this far .. remove the saved, unchanged old sudoers file
45 rm -f /etc/sudoers.pre-conffile
46
47 # make sure we have a sudo group
48
49 [ -n "`getent group sudo`" ] && exit 0   # we're finished if there is a group sudo:
50
51 # start search with gid 27
52 gid="27"
53 while [ -n "`getent group $gid | cut -d: -f3`" ];do
54         gid=`expr $gid + 1`
55 done
56
57
58 if [ "$gid" -ne "27" ];then
59         echo "On Debian we normally use gid 27 for 'sudo'."
60         gname="`getent group 27 | cut -d: -f1`"
61         echo "However, on your system gid 27 is group '$gname'."
62         echo ""
63         echo "Would you like me to stop configuring sudo so that you can change this?"; 
64         while true;do
65                 echo -n "(Enter 'yes' to stop, enter to continue): "
66                 read ans
67                 [ "$ans" = "" ] && break
68                 if [ "$ans" = "yes" -o "$ans" = "YES" ];then
69                         echo "'dpkg --pending --configure' will restart the configuration."
70                         exit 1;
71                 fi
72                 echo "Please enter exactly 'yes' to stop, or press the enter key to continue without stopping"
73         done
74 fi
75
76 echo "Creating group 'sudo' with gid = $gid";
77 groupadd -g $gid sudo
78
79 echo ""
80
81 #DEBHELPER#