first crude attempt .. doesn't handle failed upgrades yet
[debian/sudo] / debian / sudo.postinst
1 #!/usr/bin/perl
2
3 # remove old link
4
5 unlink ("/etc/alternatives/sudo") if ( -l "/etc/alternatives/sudo");
6
7 # complain if no sudoers file is present
8 if ( ! -f "/etc/sudoers") {
9         print "WARNING:  /etc/sudoers not present!\n";
10 }
11
12 # handle state directory transition from /var/run/sudo to /var/lib/sudo,
13 # moving any existing content over to avoid re-lecturing existing users
14 if ( -d "/var/run/sudo") {
15     system ('mkdir -p /var/lib/sudo');
16     system ('(cd /var/run/sudo ; tar cf - .) | (cd /var/lib/sudo ; tar xf -)');
17     system ('rm -rf /var/run/sudo');
18 }
19
20 # make sure sudoers has the correct permissions and owner/group
21 system ('chown root:root /etc/sudoers');
22 system ('chmod 440 /etc/sudoers');
23
24 # must do a remove first to un-do the "bad" links created by previous version
25 system ('update-rc.d -f sudo remove >/dev/null 2>&1');
26
27 system ('update-rc.d sudo start 75 2 3 4 5 . >/dev/null');
28
29 # make sure we have a sudo group
30
31 exit 0 if getgrnam("sudo"); # we're finished if there is a group sudo
32
33 $gid = 27;                 # start searcg with gid 27
34 setgrent;
35 while (getgrgid($gid)) {
36         ++$gid;
37 }
38 endgrent;
39
40 if ($gid != 27) {
41         print "On Debian we normally use gid 27 for 'sudo'.\n";
42         $gname = getgrgid(27);
43         print "However, on your system gid 27 is group '$gname'.\n\n";
44         print "Would you like me to stop configuring sudo so that you can change this? [n] "; 
45         $ans = <STDIN>;
46         if ($ans =~ m/^[yY].*/) {
47                 print "'dpkg --pending --configure' will restart the configuration.\n\n\n";
48                 exit 1;
49         }
50 }
51
52 print "Creating group 'sudo' with gid = $gid\n";
53 system("groupadd -g $gid sudo");
54
55 # if we've gotten this fare .. remove the saved, unchanged old sudoers file
56 if ( -f "/etc/sudoers.pre-conffile") {
57     system ('rm -f /etc/sudoers.pre-conffile');
58 }
59
60 print "";