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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
#!/usr/bin/perl -w
# vim:ft=perl:cindent:ts=8
#
# postinst for dwww
# $Id: dwww.postinst,v 1.11 2007-01-01 11:14:30 robert Exp $
#
use Debconf::Client::ConfModule qw(:all);
$stddocdir = '/var/www';
$stdcgidir = '/usr/lib/cgi-bin';
$cfgfile = '/etc/dwww/dwww.conf';
$|=1;
version('2.0');
if ($ARGV[0] eq 'configure' or $ARGV[0] eq 'reconfigure')
{
&ScanDwwwConfFile ( "$cfgfile" );
# docrootdir
$old_docdir = defined $dwwwcfg{'docrootdir'} ? canondir($dwwwcfg{'docrootdir'}) : '';
$old_cgidir = defined $dwwwcfg{'cgidir'} ? canondir($dwwwcfg{'cgidir'}): '';
$dwwwcfg{'docrootdir'} = canondir(scalar get('dwww/docrootdir'));
$dwwwcfg{'cgidir'} = canondir(scalar get('dwww/cgidir'));
$dwwwcfg{'cgiuser'} = get('dwww/cgiuser');
$dwwwcfg{'serverport'} = get('dwww/serverport');
$dwwwcfg{'servername'} = get('dwww/servername');
my $do_index = (-x '/usr/bin/index++'
and not -s '/var/cache/dwww/dwww.swish++.index'
and scalar get('dwww/index_docs') eq 'true') ? 1 : 0;
stop(); # stop debconf
&SetupDwwwLinks ("$old_docdir", "$dwwwcfg{'docrootdir'}",
"$old_cgidir", "$dwwwcfg{'cgidir'}");
&WriteDwwwConfFile( "$cfgfile" );
if ( ! -d "/var/cache/dwww" ) {
mkdir "/var/cache/dwww", 0755 or die "Cannot create directory /var/cache/dwww: $!\n";
chown 0, 0, "/var/cache/dwww";
} else {
system("rm", "-rf", "/var/cache/dwww/db");
}
mkdir "/var/cache/dwww/db", 0755 or die "Cannot create directory /var/cache/dwww/db: $!\n";
my $uid = (getpwnam("$dwwwcfg{'cgiuser'}"))[2] ;
defined $uid or die "User $dwwwcfg{'cgiuser'} does not exist\n";
$uid or die "You DON'T want to run the dwww CGI script as root!\n";
chown $uid, 0, "/var/cache/dwww/db";
if ( -r "/etc/dwww/apache.conf") {
foreach my $apache ("apache","apache-perl", "apache-ssl", "apache2") {
my $confd="/etc/$apache/conf.d";
if (-d $confd) {
symlink ("../../dwww/apache.conf", "$confd/dwww")
unless -e "$confd/dwww";
# restart the web server
system ("invoke-rc.d $apache restart 1>&2")
if (-x "/usr/sbin/invoke-rc.d" && -x "/etc/init.d/$apache");
}
}
}
if ( -x "/etc/cron.daily/dwww" )
{
print STDERR "\nBuilding dwww pages in the background...\n";
system("/etc/cron.daily/dwww &");
}
if ($do_index and -x "/usr/sbin/dwww-index++")
{
print STDERR "\nIndexing documentation files in the background...\n";
system("dwww-index++ &");
}
}
else
{
stop(); # stop debconf
}
my $dh_commands="set -- @ARGV\\n" . << 'EOF';
set -e
if [ "$1" = "upgrade" ] && dpkg --compare-versions "$2" lt-nl "1.5.0"; then
rm -f /etc/cron.daily/dwww.saved_by_dwww_preinst \
/etc/menu-methods/dwww.saved_by_dwww_preinst
fi
#DEBHELPER#
EOF
system ($dh_commands) / 256 == 0
or die "Problem with shell scripts: $!";
exit 0;
# SOUBROUTINES
sub SetupDwwwLinks
{
my ($olddocdir, $newdocdir, $oldcgidir, $newcgidir) = @_;
if (($olddocdir ne "") and ($olddocdir ne $newdocdir))
{
system("rm", "-rf", "$olddocdir/dwww");
}
if (($oldcgidir ne $stdcgidir) and ($oldcgidir ne ""))
{
unlink "$oldcgidir/dwww";
}
if (($newcgidir ne $stdcgidir) and ( -d $newcgidir ))
{
unlink "$newcgidir/dwww";
system("cp","-p","$stdcgidir/dwww", "$newcgidir/dwww");
}
}
# Subroutine to Scan Dwww configuration file
# Configfile to parse is the argument to the subroutine
sub ScanDwwwConfFile
{
if ( ! -r "$_[0]" ) { return; };
open(DWWWCONFFILE,"<$_[0]") || die "Could not open $_[0]";
# set defaults
# $dwwwcfg{'serverport'} = 80;
while (<DWWWCONFFILE>)
{
# Check for DWWW_DOCROOTDIR
if( s/^\s*DWWW_DOCROOTDIR=//)
{
chomp($dwwwcfg{'docrootdir'}=$_);
}
# Check for DWWW_CGIDIR
if( s/^\s*DWWW_CGIDIR=//)
{
chomp($dwwwcfg{'cgidir'}=$_);
}
# Check for DWWW_CGIUSER
if( s/^\s*DWWW_CGIUSER=//)
{
chomp($dwwwcfg{'cgiuser'}=$_);
}
# Check for DWWW_SERVERNAME
if( s/^\s*DWWW_SERVERNAME=//)
{
chomp($dwwwcfg{'servername'}=$_);
# some compatibility code: assume that everything after i
# the last : is a port number
if ($dwwwcfg{'servername'} =~ /^(.*):(\d+)$/)
{
$dwwwcfg{'servername'} = $1;
$dwwwcfg{'serverport'} = $2;
}
}
# Check for DWWW_SERVERPORT
if( s/^\s*DWWW_SERVERPORT=//)
{
chomp($dwwwcfg{'serverport'}=$_);
}
}
close DWWWCONFFILE;
}
# Write /etc/dwww/dwww.conf
sub WriteDwwwConfFile
{
# First, build up array of entries
my $filename = "$_[0]";
my @dwwwconffile = ();
if ( -r "$filename" )
{
open(DWWWCONFFILE,"< $filename") || die "Could not open $filename for reading";
while (<DWWWCONFFILE>)
{
next if ( /^\s*DWWW_DOCROOTDIR/ ||
/^\s*DWWW_CGIDIR/ ||
/^\s*DWWW_CGIUSER/ ||
/^\s*DWWW_SERVERNAME/ ||
/^\s*DWWW_SERVERPORT/
);
push @dwwwconffile, "$_";
}
close DWWWCONFFILE;
}
open(DWWWCONFFILE,"> $filename") ||
die "Could not open $filename for writing";
foreach $i ( @dwwwconffile )
{
print DWWWCONFFILE "$i";
}
print DWWWCONFFILE "DWWW_DOCROOTDIR=$dwwwcfg{'docrootdir'}\n";
print DWWWCONFFILE "DWWW_CGIDIR=$dwwwcfg{'cgidir'}\n";
print DWWWCONFFILE "DWWW_CGIUSER=$dwwwcfg{'cgiuser'}\n";
print DWWWCONFFILE "DWWW_SERVERNAME=$dwwwcfg{'servername'}\n";
print DWWWCONFFILE "DWWW_SERVERPORT=$dwwwcfg{'serverport'}\n";
close DWWWCONFFILE;
}
sub canondir
{
my $dir = $_[0];
$dir =~ s|/+|/|g;
$dir =~ s|/$||;
return $dir;
}
|