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 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
|
#!/bin/sh
# Postinst script for Dokuwiki.
set -e
# Create an apache configuration file for dokuwiki
write_apache2_conf()
{
apacheconf=`mktemp`
# Get config options
db_get dokuwiki/system/documentroot
docroot=$RET;
cat >> $apacheconf <<-EOF
AliasMatch ^$docroot/sites/[^/]+$ /usr/share/dokuwiki/
AliasMatch ^$docroot/sites/[^/]+/(.*)$ /usr/share/dokuwiki/\$1
Alias $docroot /usr/share/dokuwiki/
EOF
# Print directory options for /usr/share/dokuwiki
cat >> $apacheconf <<-EOF
<Directory /usr/share/dokuwiki/>
Options +FollowSymLinks
AllowOverride All
order allow,deny
EOF
db_get dokuwiki/system/accessible
if [ "$RET" = "global" ]; then # Globally accessible
echo " Allow from all" >> $apacheconf
elif [ "$RET" = "localhost only" ]; then # Access only from localhost
echo " Allow from localhost 127.0.0.1 ::1" >> $apacheconf
else # Access from localnet
db_get dokuwiki/system/localnet
echo " Allow from localhost 127.0.0.1 ::1" >> $apacheconf
echo " Allow from $RET" >> $apacheconf
fi
cat >> $apacheconf <<-EOF
<IfModule mod_rewrite.c>
# Uncomment to implement server-side URL rewriting
# (cf. <http://www.dokuwiki.org/config:userewrite>).
# Do *not* mix that with multisite!
#RewriteEngine on
#RewriteBase /$docroot
#RewriteRule ^lib - [L]
#RewriteRule ^doku.php - [L]
#RewriteRule ^feed.php - [L]
#RewriteRule ^_media/(.*) lib/exe/fetch.php?media=\$1 [QSA,L]
#RewriteRule ^_detail/(.*) lib/exe/detail.php?media=\$1 [QSA,L]
#RewriteRule ^_export/([^/]+)/(.*) doku.php?do=export_\$1&id=\$2 [QSA,L]
#RewriteRule ^$ doku.php [L]
#RewriteRule (.*) doku.php?id=\$1 [QSA,L]
</IfModule>
</Directory>
<Directory /usr/share/dokuwiki/bin>
Require all denied
</Directory>
<Directory /var/lib/dokuwiki/data>
Require all denied
</Directory>
EOF
ucf --debconf-ok $apacheconf /etc/dokuwiki/apache.conf
ucfr dokuwiki /etc/dokuwiki/apache.conf
# Remove temporary file
rm $apacheconf;
if [ -e /etc/dokuwiki/apache.conf ]; then
chmod 0644 /etc/dokuwiki/apache.conf
fi
}
# Create a local dokuwiki configuration file
write_dokuwiki_conf()
{
dokuwikiconf=$(mktemp)
cat >> $dokuwikiconf << EOF
<?php
/**
* Dokuwiki's Main Configuration File - Local Settings
* Auto-generated by Debian postinst script
*/
EOF
db_get dokuwiki/wiki/title
title="$(printf "%s" "$RET" | sed -e 's/\\/\\\\/g;'"s/'/\\\\'/g")"
echo "\$conf['title'] = '$title';" >> $dokuwikiconf
db_get dokuwiki/wiki/license
case "$RET" in
"")
LICENSE="$RET"
;;
none)
LICENSE=""
;;
esac
echo "\$conf['license'] = '$LICENSE';" >> $dokuwikiconf
echo "#\$conf['lang'] = 'en';" >> $dokuwikiconf
db_get dokuwiki/wiki/acl
if [ "$RET" = "true" ]; then
echo "\$conf['useacl'] = 1;" >> $dokuwikiconf
echo "\$conf['superuser'] = '@admin';" >> $dokuwikiconf
fi
ucf --debconf-ok $dokuwikiconf /etc/dokuwiki/local.php
ucfr dokuwiki /etc/dokuwiki/local.php
# Remove temporary file
rm $dokuwikiconf
if [ -e /etc/dokuwiki/local.php ]; then
chmod 0644 /etc/dokuwiki/local.php
fi
# Set permissions according to the user's wishes
db_get dokuwiki/system/writeconf
if [ "$RET" = "true" ]; then
if [ -e /etc/dokuwiki/local.php ]; then
chown root:www-data /etc/dokuwiki/local.php
chmod 0664 /etc/dokuwiki/local.php
if ! dpkg-statoverride --list /etc/dokuwiki >/dev/null 2>&1; then
dpkg-statoverride --update --add root www-data 0775 /etc/dokuwiki
fi
fi
fi
db_get dokuwiki/system/writeplugins
if [ "$RET" = "true" ]; then
if ! dpkg-statoverride --list /var/lib/dokuwiki/lib/plugins >/dev/null 2>&1; then
dpkg-statoverride --update --add root www-data 0775 /var/lib/dokuwiki/lib/plugins
fi
fi
}
# Set up an initial access control system
setup_acl()
{
# Do not touch ACLs of existing installationq
if [ ! -e /var/lib/dokuwiki/acl/acl.auth.php ]; then
aclauth=`mktemp`
cat >> $aclauth << EOF
# acl.auth.php
# <?php exit()?>
# Don't modify the lines above
#
# Access Control Lists
#
# Auto-generated by Debian postinst script
EOF
db_get dokuwiki/wiki/policy
if [ "$RET" = "closed" ]; then
echo "* @ALL 0" >> $aclauth
echo "* @user 8" >> $aclauth
elif [ "$RET" = "public" ]; then
echo "* @ALL 1" >> $aclauth
echo "* @user 8" >> $aclauth
else
echo "* @ALL 8" >> $aclauth
fi
ucf --debconf-ok $aclauth /var/lib/dokuwiki/acl/acl.auth.php
ucfr dokuwiki /var/lib/dokuwiki/acl/acl.auth.php
# Remove temporary file
rm $aclauth;
if [ -e /var/lib/dokuwiki/acl/acl.auth.php ]; then
chown www-data:root /var/lib/dokuwiki/acl/acl.auth.php
fi
fi
}
# Set up an initial administrator account
setup_superuser()
{
# Do not touch user lists of existing installations
if [ ! -e /var/lib/dokuwiki/acl/users.auth.php ]; then
usersauth=`mktemp`
db_get dokuwiki/wiki/superuser
superuser="$RET"
db_get dokuwiki/wiki/fullname
fullname="$RET"
db_get dokuwiki/wiki/email
email="$RET"
db_get dokuwiki/wiki/password
password="$RET"
db_set dokuwiki/wiki/password ""
db_set dokuwiki/wiki/confirm ""
if [ -n "${password}" ]
then
password=$(echo -n "$password" | md5sum -b | cut -d' ' -f1)
echo "$superuser:$password:$fullname:$email:admin,user" >> $usersauth
ucf --debconf-ok $usersauth /var/lib/dokuwiki/acl/users.auth.php
ucfr dokuwiki /var/lib/dokuwiki/acl/users.auth.php
# Remove temporary file
rm $usersauth;
fi
if [ -e /var/lib/dokuwiki/acl/users.auth.php ]; then
chown www-data:root /var/lib/dokuwiki/acl/users.auth.php
fi
fi
}
# Create a .htaccess sample file for dokuwiki
write_htaccess()
{
# Restore the backup of the .htaccess that used to be part of the
# package and would have been lost. See preinst.
if [ -f /usr/share/dokuwiki/.htaccess.upgrade ]
then
mv /usr/share/dokuwiki/.htaccess.upgrade /etc/dokuwiki/htaccess
fi
# A previous versions of this script, 0.0.20091225c-4, used to restore the
# backup *after* ucf. As this erased the following official modification
# after ucf, let us make it back before ucf.
if [ -e /etc/dokuwiki/local.php -a -f /etc/dokuwiki/htaccess ]; then
sed -i -e '/^php_value auto_prepend_file "\/usr\/share\/dokuwiki\/prepend.php"$/,+1d' /etc/dokuwiki/htaccess
fi
ucfr dokuwiki /etc/dokuwiki/htaccess
ucf --debconf-ok /usr/share/dokuwiki/.htaccess.dist /etc/dokuwiki/htaccess
}
# Configure Apache web servers (possibly version 1.3 or 2.x?)
configure_apache2()
{
# Remove old configuration symlink for apache 2.2
if [ -e /etc/apache2/conf.d/dokuwiki.conf ]
then
rm /etc/apache2/conf.d/dokuwiki.conf
fi
# Remove possible user compatibility symlink for apache 2.4
if [ -h /etc/apache2/conf-available/dokuwiki.conf ]
then
rm /etc/apache2/conf-available/dokuwiki.conf
fi
if [ -d /etc/apache2/conf-available -a ! -e /etc/apache2/conf-available/dokuwiki.conf ]
then
ln -s /etc/dokuwiki/apache.conf /etc/apache2/conf-available/dokuwiki.conf
if [ -e /usr/share/apache2/apache2-maintscript-helper ]
then
. /usr/share/apache2/apache2-maintscript-helper
apache2_invoke enconf dokuwiki
fi
fi
}
# Configure requested web server
configure_webservers()
{
db_get dokuwiki/system/configure-webserver
webservers="$RET"
write_apache2_conf
for webserver in $webservers; do
webserver=${webserver%,}
# Note: configure_apache2 uses functions from
# /usr/share/apache2/apache2-maintscript-helper, which require an
# unmodified environment, including maintainer script arguments "$@"
configure_$webserver "$@"
done
}
if [ $1 = "configure" ]; then
. /usr/share/debconf/confmodule
write_htaccess
write_dokuwiki_conf
db_get dokuwiki/wiki/acl
if [ "$RET" = "true" ]; then
setup_acl
db_get dokuwiki/wiki/superuser
if [ ! -z "$RET" ]; then
setup_superuser
fi
fi
# Note: configure_webservers uses functions from
# /usr/share/apache2/apache2-maintscript-helper, which require an
# unmodified environment, including maintainer script arguments "$@"
configure_webservers "$@"
db_stop
if [ -d /var/lib/dokuwiki/farm/ ]; then
for d in /var/lib/dokuwiki/farm/*/data/ ; do
# Catch case where /var/lib/dokuwiki/farm/ exists, but is
# empty and hence the wildcard is passed literally.
if [ -d "$d" ]; then
install -d -o www-data -g root -m 0700 "$d/log"
fi
done
fi
fi
#DEBHELPER#
|