prepare to upload
[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 # if we've gotten this far .. remove the saved, unchanged old sudoers file
30 system ('rm -f /etc/sudoers.pre-conffile');
31
32 # make sure we have a sudo group
33
34 exit 0 if getgrnam("sudo"); # we're finished if there is a group sudo
35
36 $gid = 27;                 # start searcg with gid 27
37 setgrent;
38 while (getgrgid($gid)) {
39         ++$gid;
40 }
41 endgrent;
42
43 if ($gid != 27) {
44         print "On Debian we normally use gid 27 for 'sudo'.\n";
45         $gname = getgrgid(27);
46         print "However, on your system gid 27 is group '$gname'.\n\n";
47         print "Would you like me to stop configuring sudo so that you can change this? [n] "; 
48         $ans = <STDIN>;
49         if ($ans =~ m/^[yY].*/) {
50                 print "'dpkg --pending --configure' will restart the configuration.\n\n\n";
51                 exit 1;
52         }
53 }
54
55 print "Creating group 'sudo' with gid = $gid\n";
56 system("groupadd -g $gid sudo");
57
58 print "";