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
|
#!/usr/bin/perl -w
# Postinst script for Dokuwiki.
# Based on postinst for PHPWiki written by Matthew Palmer.
use strict;
use Debconf::Client::ConfModule ':all';
# List of supported webservers
my @webserver = ('apache', 'apache2', 'apache-ssl', 'apache-perl');
if ($ARGV[0] eq "configure") {
if ($ARGV[1] eq '' || $ARGV[1] eq '<>')
{
}
# Create initial changelog if one does not exist
if (! -e "/var/lib/dokuwiki/data/changes.log") {
open(TMP, "> /var/lib/dokuwiki/data/changes.log")
or die("Could not create /var/lib/dokuwiki/data/changes.log");
close(TMP);
}
# Set appropriate ownership and mode for changelog
my $wwwuid = getpwnam("www-data");
my $rootuid = getpwnam("root");
chown $wwwuid, $rootuid, "/var/lib/dokuwiki/data/changes.log"
or die "Could not change ownership for /var/lib/dokuwiki/data/changes.log";
chmod 0664, "/var/lib/dokuwiki/data/changes.log"
or die "Could not change mode for /var/lib/dokuwiki/data/changes.log";
write_apache_conf();
setup_acl();
configure_webservers();
# has not to be done in postinst
#restart_webservers();
}
# Dirty hack of the year to fix a possible Perl 5.8 bug (for #163380)
system('true');
# Create an apache configuration file for dokuwiki
sub write_apache_conf
{
my $apacheconf = `tempfile`;
chomp($apacheconf);
open(CONF, "> $apacheconf")
or die("Can't open $apacheconf: $!\n");
# Get config options
my @ret = get("dokuwiki/system/documentroot");
if ($ret[0] != 0) {
die "Failed to get config item dokuwiki/system/documentroot: ".$ret[1]."\n";
}
my $docroot = $ret[1];
print CONF "Alias $docroot /usr/share/dokuwiki\n";
# Print directory options for /usr/share/dokuwiki
print CONF "<Directory /usr/share/dokuwiki/>\n";
print CONF " Options +FollowSymLinks\n";
print CONF " AllowOverride All\n";
print CONF " order allow,deny\n";
@ret = get("dokuwiki/system/accessible");
if ($ret[0] != 0) {
die "Failed to get config item dokuwiki/system/accessible: $ret[1]\n";
}
# Globally accessible
if ($ret[1] eq "global") {
print CONF " allow from all\n";
# Access only from localhost
} elsif ($ret[1] eq "localhost only") {
print CONF " allow from 127.0.0.1\n";
# Access from localnet
} else {
@ret = get("dokuwiki/system/localnet");
if ($ret[0] != 0) {
die "Failed to get config item dokuwiki/system/localnet: $ret[1]\n";
}
print CONF " allow from 127.0.0.1\n";
print CONF " allow from $ret[1]\n";
}
print CONF "</Directory>\n";
close CONF;
`/usr/bin/ucf $apacheconf /etc/dokuwiki/apache.conf < /dev/tty > /dev/tty`;
# Remove temporary file
unlink $apacheconf;
chmod(0664, "/etc/dokuwiki/apache.conf")
or die("Could not set mode for /etc/dokuwiki/apache.conf");
}
# Add a configuration file and restart the http server(s)
sub configure_webservers
{
# Should not be done in postinst
# foreach (@webserver) {
#
# if (-e "/etc/$_/conf.d/dokuwiki.conf") {
# unlink "/etc/$_/conf.d/dokuwiki.conf"
# or warn "Could not remove /etc/$_/conf.d/dokuwiki.conf";
# }
# }
# Get list of servers to install into
my @dwserver = split(", ", get("dokuwiki/webservers"));
foreach (@dwserver)
{
print STDERR "Installing into... [$_] \n";
my $dir = "/etc/$_";
# Skip servers with no configuration
if (! -d $dir)
{
next;
}
# Link the apache configuration file to the server's
# conf.d directory
if (! -f "$dir/conf.d/dokuwiki.conf") {
symlink('/etc/dokuwiki/apache.conf', "$dir/conf.d/dokuwiki.conf")
or die("Failed to link configuration file to $dir/conf.d/dokuwiki.conf\n");
}
chmod(0644, "/etc/dokuwiki/apache.conf")
or die("Failed to set permissions for /etc/dokuwiki/apache.conf\n");
}
}
# Restart the webservers after the reconfiguration
sub restart_webservers
{
foreach (@webserver) {
# If server binary does not exist, move to next one
if (! -x "/usr/sbin/$_")
{
next;
}
# Restart the server either by invoke-rc.d or init.d
if (-x "/usr/sbin/invoke-rc.d")
{
(!system("/usr/sbin/invoke-rc.d $_ restart >/dev/tty 2>&1"))
or warn "Failed to restart $_\n";
}
else
{
if (-x "/etc/init.d/$_") {
(!system("/etc/init.d/$_ restart >/dev/tty 2>&1"))
or warn "Failed to restart $_\n";
}
}
}
}
# Subroutine to set up an initial access control system
sub setup_acl
{
# By default allow everyone read access
if (! -e "/var/lib/dokuwiki/acl/acl.auth.php") {
open(AUTHFILE, "> /var/lib/dokuwiki/acl/acl.auth.php")
or warn("Could not write to /var/lib/dokuwiki/acl/acl.auth.php");
print AUTHFILE '* @ALL 4';
print AUTHFILE "\n";
close AUTHFILE;
my $wwwuid = getpwnam("www-data");
my $rootuid = getpwnam("root");
chown $wwwuid, $rootuid, "/var/lib/dokuwiki/acl/acl.auth.php"
or warn "Could not change owner for /var/lib/dokuwiki/acl/acl.auth.php";
}
if (! -e "/var/lib/dokuwiki/acl/users.auth.php") {
# "touch" user database file
open(USERFILE, "> /var/lib/dokuwiki/acl/users.auth.php")
or warn("Could not write to /var/lib/dokuwiki/acl/users.auth.php");
close USERFILE;
my $wwwuid = getpwnam("www-data");
my $rootuid = getpwnam("root");
chown $wwwuid, $rootuid, "/var/lib/dokuwiki/acl/users.auth.php"
or warn "Could not change ownership for /var/lib/dokuwiki/acl/users.auth.php";
}
}
#DEBHELPER#
|