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