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