1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
#! /usr/bin/perl --
#
# Postinst script for debian's Diablo distribution
#
# Version: @(#)postinst.diablo 1.00 04-Aug-1997 MvS.
#
# Directories we need to make, and their modes.
@dbldirs = ( '/var/spool/news', '0775',
'/var/spool/news/diablo', '0775',
'/var/spool/news/dqueue', '0775',
'/var/spool/news/cache', '0775',
'/var/spool/news/group', '0775',
'/var/lib/news', '0755',
'/var/log/news', '0775',
'/var/log/news/OLD', '0775' );
# Ditto for empty files we want.
@dblfiles = ( '/var/log/news/news.crit', '0644',
'/var/log/news/news.err', '0644',
'/var/log/news/news.notice', '0644' );
$|=1;
umask(022);
# Check why we were called.
if ($ARGV[0] ne 'configure') {
print STDERR "postinst: unknown action \"$ARGV[0]\"\n";
exit(0);
}
#
# Copy the sample files, if needed.
#
#©_sample('inn.conf', 'organization', 'server', 'whoami');
#&makedirs();
print "Installing crontab entries.\n";
&setcrontab;
print "Installing startup scripts in /etc/rcX.d\n";
system("update-rc.d diablo defaults 50 > /dev/null");
# Signal syslogd so the the new logfiles will be used.
system('start-stop-daemon --stop --quiet --oknodo --signal 1 --exec /sbin/syslogd');
# And start INN.
system('/etc/init.d/diablo start');
exit(0);
#
# Ask for a variable. Read the default from a file, and write the
# answer back to that file again.
#
sub askfor {
my($q, $file, $dfl) = @_;
my($tmp, $ans);
# Read the contents of the file (if any).
$tmp = "";
if ($file ne '' && open(AFD, $file)) {
chop($tmp = <AFD>);
close AFD;
}
# Do we need to get the default from the file?
$dfl = $tmp if ($tmp ne "");
# Prompt and ask for the new value.
print "$q [$dfl]: ";
chop($ans = <STDIN>);
$ans = $dfl if ($ans =~ /^$/);
# Write the answer back to the file if needed.
if ($ans ne $tmp && $file ne '') {
&writefile($file, "$ans\n");
}
# Return answer.
$ans;
}
#
# Install a new crontab file for the news user.
#
sub setcrontab {
system('crontab', '-u', 'news', '/etc/news/crontab.diablo');
$? && warn "warning: crontab failed to install news user's crontab!\n";
}
#
# Write a file. Be careful with this, first create a new file and
# then rename it to the original file.
#
sub writefile {
local ($f ,$v) = @_;
# Stat the original file for owner / uid info.
my ($dev, $ino, $mode, $nlink, $uid, $gid) = stat($f);
# Create new file.
open(F, ">$f.postinstnew") || die "failed to create $f.postinstnew: $!\n";
print(F $v) || die "failed to write to $f.postinstnew: $!\n";
close(F) || die "failed to close $f.postinstnew: $!\n";
# Set permissions.
if ($ino) {
chown($uid, $gid, $f);
chmod($mode, $f);
}
# And move new file into place.
rename("$f.postinstnew", $f) || die "failed to install new $f: $!\n";
}
#
# Make the directories.
#
sub makedirs {
my($i);
# Make the directories if they do not exist yet.
for($i = 0; $i < $#dbldirs; $i += 2) {
if (!-d "$dbldirs[$i]/.") {
system("install -d -o news -g news -m $dbldirs[$i+1] $dbldirs[$i]");
} else {
# Set up modes.
# FIXME: should we or shouldn't we? Maybe just chown, not chmod?
# system("chown news:news $dbldirs[$i]; " .
# "chmod $dbldirs[$i+1] $dbldirs[$i]");
}
}
# And See if we need to create syslog files.
for($i = 0; $i < $#dblfiles; $i += 2) {
if (!-f "$dblfiles[$i]") {
open(FX, ">$dblfiles[$i]");
close FX;
}
system("chown news:news $dblfiles[$i]; " .
"chmod $dblfiles[$i+1] $dblfiles[$i]");
}
# Do we need any symlinks (compatibility) ?
chdir("/var/spool/news");
if (! -d '.incoming' && ! -e '.incoming') {
symlink('in.coming', '.incoming');
}
if (! -d '.outgoing' && ! -e '.outgoing') {
symlink('out.going', '.outgoing');
}
1;
}
#
# Copy sample files to /etc/news.
#
sub copy_sample {
my @files = @_;
my ($i);
my ($base);
$base = "/usr/doc/$package/examples";
while ($i = shift @files) {
next if (-f "/etc/news/$i");
next if (! -f "$base/$i");
system("cp -a $base/$i /etc/news/$i; " .
"chown news:news /etc/news/$i");
}
1;
}
|