Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Postinst script for Dokuwiki.
- set -e
- # Create an apache configuration file for dokuwiki
- write_apache2_conf()
- {
- apacheconf=`tempfile`
- # 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 /dokuwiki
- #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 lighttpd configuration file for dokuwiki
- write_lighttpd_conf()
- {
- lighttpdconf=$(tempfile)
- # Get document root
- db_get dokuwiki/system/documentroot
- docroot=$RET;
- # Configure lighttpd to server dokuwiki on the docroot
- echo "alias.url += (\"$docroot\" => \"/usr/share/dokuwiki\")" >> $lighttpdconf
- cat >> $lighttpdconf << EOF
- \$HTTP["url"] =~ "^$docroot" {
- server.follow-symlink = "enable"
- }
- \$HTTP["url"] =~ "/(\.|_)ht" {
- url.access-deny = ( "" )
- }
- \$HTTP["url"] =~ "^$docroot/(bin|data|inc|conf)" {
- url.access-deny = ( "" )
- }
- EOF
- # TODO: access restriction
- # Write the configuration file to its final location
- ucf --debconf-ok $lighttpdconf /etc/dokuwiki/lighttpd.conf
- ucfr dokuwiki /etc/dokuwiki/lighttpd.conf
- # Remove temporary file
- rm $lighttpdconf;
- if [ -e /etc/dokuwiki/lighttpd.conf ]; then
- chmod 0644 /etc/dokuwiki/lighttpd.conf
- fi
- }
- # Create a local dokuwiki configuration file
- write_dokuwiki_conf()
- {
- dokuwikiconf=$(tempfile)
- 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
- echo "\$conf['license'] = '$RET';" >> $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=`tempfile`
- 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=`tempfile`
- 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=$(echo -n "$RET" | md5sum -b | cut -d' ' -f1)
- db_set dokuwiki/wiki/password ""
- db_set dokuwiki/wiki/confirm ""
- 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;
- 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
- }
- # Reload apache2
- reload_apache2()
- {
- # Nothing, since `apache2_invoke enconf` already did what had to be done
- :
- }
- # Configure lighttpd web server
- configure_lighttpd()
- {
- dir="/etc/lighttpd/conf-available"
- file="$dir/50-dokuwiki.conf"
- if [ -d "$dir" ] && [ ! -e "$file" ]; then
- if ! command -v bash > /dev/null ; then
- echo "Lighttpd not installed, skipping"
- else
- echo "Installing into... [$dir]" >/dev/stderr
- ln -sf /etc/dokuwiki/lighttpd.conf "$file"
- lighty-enable-mod dokuwiki
- fi
- fi
- }
- # Reload lighttpd
- reload_lighttpd()
- {
- # That may fail if lighttpd is not running: this is not a real problem,
- # ignore it.
- invoke-rc.d lighttpd reload || true
- }
- # Configure requested web server
- configure_webservers()
- {
- db_get dokuwiki/system/configure-webserver
- webservers="$RET"
- db_get dokuwiki/system/restart-webserver
- restart="$RET"
- write_apache2_conf
- write_lighttpd_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 "$@"
- if [ "$restart" = "true" ]
- then
- reload_$webserver "$@"
- fi
- 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
- # A double transition...
- # Templates and plugins used to be under /usr/share/dokuwiki/lib.
- # They were moved to /var/lib/dokuwiki to allow additions within the FHS.
- # But some plugins need to find DokuWiki's root directory at ../../../,
- # so they are now installed under /var/lib/dokuwiki/lib to reproduce the
- # original hierarchy at /var/lib/dokuwiki.
- # Possible cases for /usr/share/dokuwiki/lib/tpl:
- # * inexistant, regular file, special file: *abnormal* cases, not handled;
- # * symlink: no transition needed;
- # * directory: transition to the new location needed.
- if [ ! -L /usr/share/dokuwiki/lib/tpl ]; then
- echo -n "Moving template directory from /usr/share/dokuwiki to /var/lib/dokuwiki/lib... " >/dev/stderr
- mv /usr/share/dokuwiki/lib/tpl/* /var/lib/dokuwiki/lib/tpl/ 2> /dev/null || true
- if ! rmdir /usr/share/dokuwiki/lib/tpl; then
- # Files left on /usr/share/dokuwiki/lib/tpl.
- # Typical case: the user added files deeply in
- # /usr/share/dokuwiki/lib/tpl/default. Requires user
- # intervention.
- echo >/dev/stderr
- echo "Some files were left on /usr/share/dokuwiki/lib/tpl:" >/dev/stderr
- echo "they are backed up on /usr/share/dokuwiki/lib/tpl.old," >/dev/stderr
- echo "please check them and consider removing them." >/dev/stderr
- mv /usr/share/dokuwiki/lib/tpl /usr/share/dokuwiki/lib/tpl.old
- fi
- ln -s /var/lib/dokuwiki/lib/tpl /usr/share/dokuwiki/lib/
- echo "[done]" >/dev/stderr
- fi
- # Possible clases for /var/lib/dokuwiki/tpl:
- # * inexistant: no transition needed;
- # * regular file, special file, symlink: *abnormal* cases, not handled;
- # * directory: transition to the new location needed.
- if [ -d /var/lib/dokuwiki/tpl ]; then
- echo -n "Moving template directory from /var/lib/dokuwiki to /var/lib/dokuwiki/lib... " >/dev/stderr
- # A previous version of this script, 0.0.20090214b-3.1, used to
- # brutally move templates from /usr/share/dokuwiki/lib to
- # /var/lib/dokuwiki, resulting in files not belonging to the package.
- # On upgrade, they are left, but can be removed safely as they are now
- # simply provided by the package.
- rm -f /var/lib/dokuwiki/tpl/default/images/bullet.gif \
- /var/lib/dokuwiki/tpl/default/images/button-cc.gif \
- /var/lib/dokuwiki/tpl/default/images/button-css.png \
- /var/lib/dokuwiki/tpl/default/images/button-debian.png \
- /var/lib/dokuwiki/tpl/default/images/button-debian.png.uue \
- /var/lib/dokuwiki/tpl/default/images/button-donate.gif \
- /var/lib/dokuwiki/tpl/default/images/button-dw.png \
- /var/lib/dokuwiki/tpl/default/images/button-php.gif \
- /var/lib/dokuwiki/tpl/default/images/button-rss.png \
- /var/lib/dokuwiki/tpl/default/images/buttonshadow.png \
- /var/lib/dokuwiki/tpl/default/images/button-xhtml.png \
- /var/lib/dokuwiki/tpl/default/images/closed.gif \
- /var/lib/dokuwiki/tpl/default/images/favicon.ico \
- /var/lib/dokuwiki/tpl/default/images/inputshadow.png \
- /var/lib/dokuwiki/tpl/default/images/link_icon.gif \
- /var/lib/dokuwiki/tpl/default/images/mail_icon.gif \
- /var/lib/dokuwiki/tpl/default/images/open.gif \
- /var/lib/dokuwiki/tpl/default/images/tocdot2.gif \
- /var/lib/dokuwiki/tpl/default/images/UWEB.png \
- /var/lib/dokuwiki/tpl/default/images/UWEBshadow.png \
- /var/lib/dokuwiki/tpl/default/images/windows.gif
- rmdir /var/lib/dokuwiki/tpl/default/images/ 2> /dev/null || true
- rm -f /var/lib/dokuwiki/tpl/default/design.css \
- /var/lib/dokuwiki/tpl/default/detail.php \
- /var/lib/dokuwiki/tpl/default/footer.html \
- /var/lib/dokuwiki/tpl/default/layout.css \
- /var/lib/dokuwiki/tpl/default/main.php \
- /var/lib/dokuwiki/tpl/default/media.css \
- /var/lib/dokuwiki/tpl/default/mediamanager.php \
- /var/lib/dokuwiki/tpl/default/print.css \
- /var/lib/dokuwiki/tpl/default/rtl.css \
- /var/lib/dokuwiki/tpl/default/style.ini
- rmdir /var/lib/dokuwiki/tpl/default/ 2> /dev/null || true
- rm -f /var/lib/dokuwiki/tpl/index.php
- mv /var/lib/dokuwiki/tpl/* /var/lib/dokuwiki/lib/tpl/ 2> /dev/null || true
- if ! rmdir /var/lib/dokuwiki/tpl; then
- # Files left on /var/lib/dokuwiki/tpl.
- # Typical case: the user added files deeply in
- # /var/lib/dokuwiki/tpl/default. Requires user
- # intervention.
- echo >/dev/stderr
- echo "Some files were left on /var/lib/dokuwiki/tpl:" >/dev/stderr
- echo "they are backed up on /var/lib/dokuwiki/tpl.old," >/dev/stderr
- echo "please check them and consider removing them." >/dev/stderr
- mv /var/lib/dokuwiki/tpl /var/lib/dokuwiki/tpl.old
- fi
- echo "[done]" >/dev/stderr
- fi
- # Possible cases for /usr/share/dokuwiki/lib/plugins:
- # * inexistant, regular file, special file: *abnormal* cases, not handled;
- # * symlink: no transition needed;
- # * directory: transition to the new location needed.
- if [ ! -L /usr/share/dokuwiki/lib/plugins ]; then
- echo -n "Moving plugins directory from /usr/share/dokuwiki to /var/lib/dokuwiki/lib... " >/dev/stderr
- mv /usr/share/dokuwiki/lib/plugins/* /var/lib/dokuwiki/lib/plugins/ 2> /dev/null || true
- if ! rmdir /usr/share/dokuwiki/lib/plugins; then
- # Files left on /usr/share/dokuwiki/lib/plugins.
- # Typical case: the user added files deeply in
- # /usr/share/dokuwiki/lib/plugins/something_provided_by_the_package.
- # Requires user intervention.
- echo >/dev/stderr
- echo "Some files were left on /usr/share/dokuwiki/lib/plugins:" >/dev/stderr
- echo "they are backed up on /usr/share/dokuwiki/lib/plugins.old," >/dev/stderr
- echo "please check them and consider removing them." >/dev/stderr
- mv /usr/share/dokuwiki/lib/plugins /usr/share/dokuwiki/lib/plugins.old
- fi
- ln -s /var/lib/dokuwiki/lib/plugins /usr/share/dokuwiki/lib/
- echo "[done]" >/dev/stderr
- fi
- # Possible cases for /var/lib/dokuwiki/plugins:
- # * inexistant: no transition needed;
- # * regular file, special file, symlink: *abnormal* cases, not handled;
- # * directory: transition to the new location needed.
- if [ -d /var/lib/dokuwiki/plugins ]; then
- echo -n "Moving plugins directory from /var/lib/dokuwiki to /var/lib/dokuwiki/lib... " >/dev/stderr
- mv /var/lib/dokuwiki/plugins/* /var/lib/dokuwiki/lib/plugins/ 2> /dev/null || true
- if ! rmdir /var/lib/dokuwiki/plugins; then
- # Files left on /var/lib/dokuwiki/plugins.
- # Typical case: the user added files deeply in
- # /var/lib/dokuwiki/plugins/something_provided_by_the_package.
- # Requires user intervention.
- echo >/dev/stderr
- echo "Some files were left on /var/lib/dokuwiki/plugins:" >/dev/stderr
- echo "they are backed up on /var/lib/dokuwiki/plugins.old," >/dev/stderr
- echo "please check them and consider removing them." >/dev/stderr
- mv /var/lib/dokuwiki/plugins /var/lib/dokuwiki/plugins.old
- fi
- echo "[done]" >/dev/stderr
- fi
- fi
- #DEBHELPER#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement