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