Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.67 KB | None | 0 0
  1. #!/bin/sh
  2. # Postinst script for Dokuwiki.
  3.  
  4. set -e
  5.  
  6. # Create an apache configuration file for dokuwiki
  7. write_apache2_conf()
  8. {
  9. apacheconf=`tempfile`
  10.  
  11. # Get config options
  12. db_get dokuwiki/system/documentroot
  13. docroot=$RET;
  14.  
  15. cat >> $apacheconf <<-EOF
  16. AliasMatch ^$docroot/sites/[^/]+$ /usr/share/dokuwiki/
  17. AliasMatch ^$docroot/sites/[^/]+/(.*)$ /usr/share/dokuwiki/\$1
  18. Alias $docroot /usr/share/dokuwiki/
  19. EOF
  20.  
  21. # Print directory options for /usr/share/dokuwiki
  22. cat >> $apacheconf <<-EOF
  23.  
  24. <Directory /usr/share/dokuwiki/>
  25. Options +FollowSymLinks
  26. AllowOverride All
  27. order allow,deny
  28. EOF
  29.  
  30. db_get dokuwiki/system/accessible
  31. if [ "$RET" = "global" ]; then # Globally accessible
  32. echo " Allow from all" >> $apacheconf
  33. elif [ "$RET" = "localhost only" ]; then # Access only from localhost
  34. echo " Allow from localhost 127.0.0.1 ::1" >> $apacheconf
  35. else # Access from localnet
  36. db_get dokuwiki/system/localnet
  37. echo " Allow from localhost 127.0.0.1 ::1" >> $apacheconf
  38. echo " Allow from $RET" >> $apacheconf
  39. fi
  40.  
  41. cat >> $apacheconf <<-EOF
  42.  
  43. <IfModule mod_rewrite.c>
  44.  
  45. # Uncomment to implement server-side URL rewriting
  46. # (cf. <http://www.dokuwiki.org/config:userewrite>).
  47. # Do *not* mix that with multisite!
  48. #RewriteEngine on
  49. #RewriteBase /dokuwiki
  50. #RewriteRule ^lib - [L]
  51. #RewriteRule ^doku.php - [L]
  52. #RewriteRule ^feed.php - [L]
  53. #RewriteRule ^_media/(.*) lib/exe/fetch.php?media=\$1 [QSA,L]
  54. #RewriteRule ^_detail/(.*) lib/exe/detail.php?media=\$1 [QSA,L]
  55. #RewriteRule ^_export/([^/]+)/(.*) doku.php?do=export_\$1&id=\$2 [QSA,L]
  56. #RewriteRule ^$ doku.php [L]
  57. #RewriteRule (.*) doku.php?id=\$1 [QSA,L]
  58. </IfModule>
  59. </Directory>
  60.  
  61. <Directory /usr/share/dokuwiki/bin>
  62. Require all denied
  63. </Directory>
  64.  
  65. <Directory /var/lib/dokuwiki/data>
  66. Require all denied
  67. </Directory>
  68. EOF
  69.  
  70. ucf --debconf-ok $apacheconf /etc/dokuwiki/apache.conf
  71. ucfr dokuwiki /etc/dokuwiki/apache.conf
  72.  
  73. # Remove temporary file
  74. rm $apacheconf;
  75.  
  76. if [ -e /etc/dokuwiki/apache.conf ]; then
  77. chmod 0644 /etc/dokuwiki/apache.conf
  78. fi
  79. }
  80.  
  81. # Create a lighttpd configuration file for dokuwiki
  82. write_lighttpd_conf()
  83. {
  84. lighttpdconf=$(tempfile)
  85.  
  86. # Get document root
  87. db_get dokuwiki/system/documentroot
  88. docroot=$RET;
  89.  
  90. # Configure lighttpd to server dokuwiki on the docroot
  91. echo "alias.url += (\"$docroot\" => \"/usr/share/dokuwiki\")" >> $lighttpdconf
  92. cat >> $lighttpdconf << EOF
  93.  
  94. \$HTTP["url"] =~ "^$docroot" {
  95. server.follow-symlink = "enable"
  96. }
  97.  
  98. \$HTTP["url"] =~ "/(\.|_)ht" {
  99. url.access-deny = ( "" )
  100. }
  101. \$HTTP["url"] =~ "^$docroot/(bin|data|inc|conf)" {
  102. url.access-deny = ( "" )
  103. }
  104. EOF
  105.  
  106. # TODO: access restriction
  107.  
  108. # Write the configuration file to its final location
  109. ucf --debconf-ok $lighttpdconf /etc/dokuwiki/lighttpd.conf
  110. ucfr dokuwiki /etc/dokuwiki/lighttpd.conf
  111.  
  112. # Remove temporary file
  113. rm $lighttpdconf;
  114.  
  115. if [ -e /etc/dokuwiki/lighttpd.conf ]; then
  116. chmod 0644 /etc/dokuwiki/lighttpd.conf
  117. fi
  118. }
  119.  
  120. # Create a local dokuwiki configuration file
  121. write_dokuwiki_conf()
  122. {
  123. dokuwikiconf=$(tempfile)
  124.  
  125. cat >> $dokuwikiconf << EOF
  126. <?php
  127. /**
  128. * Dokuwiki's Main Configuration File - Local Settings
  129. * Auto-generated by Debian postinst script
  130. */
  131.  
  132. EOF
  133.  
  134. db_get dokuwiki/wiki/title
  135. title="$(printf "%s" "$RET" | sed -e 's/\\/\\\\/g;'"s/'/\\\\'/g")"
  136. echo "\$conf['title'] = '$title';" >> $dokuwikiconf
  137.  
  138. db_get dokuwiki/wiki/license
  139. echo "\$conf['license'] = '$RET';" >> $dokuwikiconf
  140.  
  141. echo "#\$conf['lang'] = 'en';" >> $dokuwikiconf
  142.  
  143. db_get dokuwiki/wiki/acl
  144. if [ "$RET" = "true" ]; then
  145. echo "\$conf['useacl'] = 1;" >> $dokuwikiconf
  146. echo "\$conf['superuser'] = '@admin';" >> $dokuwikiconf
  147. fi
  148.  
  149. ucf --debconf-ok $dokuwikiconf /etc/dokuwiki/local.php
  150. ucfr dokuwiki /etc/dokuwiki/local.php
  151.  
  152. # Remove temporary file
  153. rm $dokuwikiconf
  154.  
  155. if [ -e /etc/dokuwiki/local.php ]; then
  156. chmod 0644 /etc/dokuwiki/local.php
  157. fi
  158.  
  159. # Set permissions according to the user's wishes
  160. db_get dokuwiki/system/writeconf
  161. if [ "$RET" = "true" ]; then
  162. if [ -e /etc/dokuwiki/local.php ]; then
  163. chown root:www-data /etc/dokuwiki/local.php
  164. chmod 0664 /etc/dokuwiki/local.php
  165. if ! dpkg-statoverride --list /etc/dokuwiki >/dev/null 2>&1; then
  166. dpkg-statoverride --update --add root www-data 0775 /etc/dokuwiki
  167. fi
  168. fi
  169. fi
  170. db_get dokuwiki/system/writeplugins
  171. if [ "$RET" = "true" ]; then
  172. if ! dpkg-statoverride --list /var/lib/dokuwiki/lib/plugins >/dev/null 2>&1; then
  173. dpkg-statoverride --update --add root www-data 0775 /var/lib/dokuwiki/lib/plugins
  174. fi
  175. fi
  176. }
  177.  
  178. # Set up an initial access control system
  179. setup_acl()
  180. {
  181. # Do not touch ACLs of existing installationq
  182. if [ ! -e /var/lib/dokuwiki/acl/acl.auth.php ]; then
  183. aclauth=`tempfile`
  184.  
  185. cat >> $aclauth << EOF
  186. # acl.auth.php
  187. # <?php exit()?>
  188. # Don't modify the lines above
  189. #
  190. # Access Control Lists
  191. #
  192. # Auto-generated by Debian postinst script
  193.  
  194. EOF
  195.  
  196. db_get dokuwiki/wiki/policy
  197. if [ "$RET" = "closed" ]; then
  198. echo "* @ALL 0" >> $aclauth
  199. echo "* @user 8" >> $aclauth
  200. elif [ "$RET" = "public" ]; then
  201. echo "* @ALL 1" >> $aclauth
  202. echo "* @user 8" >> $aclauth
  203. else
  204. echo "* @ALL 8" >> $aclauth
  205. fi
  206.  
  207. ucf --debconf-ok $aclauth /var/lib/dokuwiki/acl/acl.auth.php
  208. ucfr dokuwiki /var/lib/dokuwiki/acl/acl.auth.php
  209.  
  210. # Remove temporary file
  211. rm $aclauth;
  212.  
  213. if [ -e /var/lib/dokuwiki/acl/acl.auth.php ]; then
  214. chown www-data:root /var/lib/dokuwiki/acl/acl.auth.php
  215. fi
  216. fi
  217. }
  218.  
  219. # Set up an initial administrator account
  220. setup_superuser()
  221. {
  222. # Do not touch user lists of existing installations
  223. if [ ! -e /var/lib/dokuwiki/acl/users.auth.php ]; then
  224. usersauth=`tempfile`
  225.  
  226. db_get dokuwiki/wiki/superuser
  227. superuser="$RET"
  228. db_get dokuwiki/wiki/fullname
  229. fullname="$RET"
  230. db_get dokuwiki/wiki/email
  231. email="$RET"
  232. db_get dokuwiki/wiki/password
  233. password=$(echo -n "$RET" | md5sum -b | cut -d' ' -f1)
  234. db_set dokuwiki/wiki/password ""
  235. db_set dokuwiki/wiki/confirm ""
  236. echo "$superuser:$password:$fullname:$email:admin,user" >> $usersauth
  237.  
  238. ucf --debconf-ok $usersauth /var/lib/dokuwiki/acl/users.auth.php
  239. ucfr dokuwiki /var/lib/dokuwiki/acl/users.auth.php
  240.  
  241. # Remove temporary file
  242. rm $usersauth;
  243.  
  244. if [ -e /var/lib/dokuwiki/acl/users.auth.php ]; then
  245. chown www-data:root /var/lib/dokuwiki/acl/users.auth.php
  246. fi
  247. fi
  248. }
  249.  
  250. # Create a .htaccess sample file for dokuwiki
  251. write_htaccess()
  252. {
  253. # Restore the backup of the .htaccess that used to be part of the
  254. # package and would have been lost. See preinst.
  255. if [ -f /usr/share/dokuwiki/.htaccess.upgrade ]
  256. then
  257. mv /usr/share/dokuwiki/.htaccess.upgrade /etc/dokuwiki/htaccess
  258. fi
  259.  
  260. # A previous versions of this script, 0.0.20091225c-4, used to restore the
  261. # backup *after* ucf. As this erased the following official modification
  262. # after ucf, let us make it back before ucf.
  263. if [ -e /etc/dokuwiki/local.php -a -f /etc/dokuwiki/htaccess ]; then
  264. sed -i -e '/^php_value auto_prepend_file "\/usr\/share\/dokuwiki\/prepend.php"$/,+1d' /etc/dokuwiki/htaccess
  265. fi
  266.  
  267. ucfr dokuwiki /etc/dokuwiki/htaccess
  268. ucf --debconf-ok /usr/share/dokuwiki/.htaccess.dist /etc/dokuwiki/htaccess
  269. }
  270.  
  271. # Configure Apache web servers (possibly version 1.3 or 2.x?)
  272. configure_apache2()
  273. {
  274. # Remove old configuration symlink for apache 2.2
  275. if [ -e /etc/apache2/conf.d/dokuwiki.conf ]
  276. then
  277. rm /etc/apache2/conf.d/dokuwiki.conf
  278. fi
  279. # Remove possible user compatibility symlink for apache 2.4
  280. if [ -h /etc/apache2/conf-available/dokuwiki.conf ]
  281. then
  282. rm /etc/apache2/conf-available/dokuwiki.conf
  283. fi
  284. if [ -d /etc/apache2/conf-available -a ! -e /etc/apache2/conf-available/dokuwiki.conf ]
  285. then
  286. ln -s /etc/dokuwiki/apache.conf /etc/apache2/conf-available/dokuwiki.conf
  287. if [ -e /usr/share/apache2/apache2-maintscript-helper ]
  288. then
  289. . /usr/share/apache2/apache2-maintscript-helper
  290. apache2_invoke enconf dokuwiki
  291. fi
  292. fi
  293. }
  294.  
  295. # Reload apache2
  296. reload_apache2()
  297. {
  298. # Nothing, since `apache2_invoke enconf` already did what had to be done
  299. :
  300. }
  301.  
  302. # Configure lighttpd web server
  303. configure_lighttpd()
  304. {
  305. dir="/etc/lighttpd/conf-available"
  306. file="$dir/50-dokuwiki.conf"
  307. if [ -d "$dir" ] && [ ! -e "$file" ]; then
  308. if ! command -v bash > /dev/null ; then
  309. echo "Lighttpd not installed, skipping"
  310. else
  311. echo "Installing into... [$dir]" >/dev/stderr
  312. ln -sf /etc/dokuwiki/lighttpd.conf "$file"
  313. lighty-enable-mod dokuwiki
  314. fi
  315. fi
  316. }
  317.  
  318. # Reload lighttpd
  319. reload_lighttpd()
  320. {
  321. # That may fail if lighttpd is not running: this is not a real problem,
  322. # ignore it.
  323. invoke-rc.d lighttpd reload || true
  324. }
  325.  
  326. # Configure requested web server
  327. configure_webservers()
  328. {
  329. db_get dokuwiki/system/configure-webserver
  330. webservers="$RET"
  331. db_get dokuwiki/system/restart-webserver
  332. restart="$RET"
  333. write_apache2_conf
  334. write_lighttpd_conf
  335. for webserver in $webservers; do
  336. webserver=${webserver%,}
  337. # Note: configure_apache2 uses functions from
  338. # /usr/share/apache2/apache2-maintscript-helper, which require an
  339. # unmodified environment, including maintainer script arguments "$@"
  340. configure_$webserver "$@"
  341. if [ "$restart" = "true" ]
  342. then
  343. reload_$webserver "$@"
  344. fi
  345. done
  346. }
  347.  
  348. if [ $1 = "configure" ]; then
  349. . /usr/share/debconf/confmodule
  350.  
  351. write_htaccess
  352. write_dokuwiki_conf
  353. db_get dokuwiki/wiki/acl
  354. if [ "$RET" = "true" ]; then
  355. setup_acl
  356. db_get dokuwiki/wiki/superuser
  357. if [ ! -z "$RET" ]; then
  358. setup_superuser
  359. fi
  360. fi
  361. # Note: configure_webservers uses functions from
  362. # /usr/share/apache2/apache2-maintscript-helper, which require an
  363. # unmodified environment, including maintainer script arguments "$@"
  364. configure_webservers "$@"
  365.  
  366. db_stop
  367.  
  368. # A double transition...
  369. # Templates and plugins used to be under /usr/share/dokuwiki/lib.
  370. # They were moved to /var/lib/dokuwiki to allow additions within the FHS.
  371. # But some plugins need to find DokuWiki's root directory at ../../../,
  372. # so they are now installed under /var/lib/dokuwiki/lib to reproduce the
  373. # original hierarchy at /var/lib/dokuwiki.
  374.  
  375. # Possible cases for /usr/share/dokuwiki/lib/tpl:
  376. # * inexistant, regular file, special file: *abnormal* cases, not handled;
  377. # * symlink: no transition needed;
  378. # * directory: transition to the new location needed.
  379. if [ ! -L /usr/share/dokuwiki/lib/tpl ]; then
  380. echo -n "Moving template directory from /usr/share/dokuwiki to /var/lib/dokuwiki/lib... " >/dev/stderr
  381. mv /usr/share/dokuwiki/lib/tpl/* /var/lib/dokuwiki/lib/tpl/ 2> /dev/null || true
  382. if ! rmdir /usr/share/dokuwiki/lib/tpl; then
  383. # Files left on /usr/share/dokuwiki/lib/tpl.
  384. # Typical case: the user added files deeply in
  385. # /usr/share/dokuwiki/lib/tpl/default. Requires user
  386. # intervention.
  387. echo >/dev/stderr
  388. echo "Some files were left on /usr/share/dokuwiki/lib/tpl:" >/dev/stderr
  389. echo "they are backed up on /usr/share/dokuwiki/lib/tpl.old," >/dev/stderr
  390. echo "please check them and consider removing them." >/dev/stderr
  391. mv /usr/share/dokuwiki/lib/tpl /usr/share/dokuwiki/lib/tpl.old
  392. fi
  393. ln -s /var/lib/dokuwiki/lib/tpl /usr/share/dokuwiki/lib/
  394. echo "[done]" >/dev/stderr
  395. fi
  396. # Possible clases for /var/lib/dokuwiki/tpl:
  397. # * inexistant: no transition needed;
  398. # * regular file, special file, symlink: *abnormal* cases, not handled;
  399. # * directory: transition to the new location needed.
  400. if [ -d /var/lib/dokuwiki/tpl ]; then
  401. echo -n "Moving template directory from /var/lib/dokuwiki to /var/lib/dokuwiki/lib... " >/dev/stderr
  402. # A previous version of this script, 0.0.20090214b-3.1, used to
  403. # brutally move templates from /usr/share/dokuwiki/lib to
  404. # /var/lib/dokuwiki, resulting in files not belonging to the package.
  405. # On upgrade, they are left, but can be removed safely as they are now
  406. # simply provided by the package.
  407. rm -f /var/lib/dokuwiki/tpl/default/images/bullet.gif \
  408. /var/lib/dokuwiki/tpl/default/images/button-cc.gif \
  409. /var/lib/dokuwiki/tpl/default/images/button-css.png \
  410. /var/lib/dokuwiki/tpl/default/images/button-debian.png \
  411. /var/lib/dokuwiki/tpl/default/images/button-debian.png.uue \
  412. /var/lib/dokuwiki/tpl/default/images/button-donate.gif \
  413. /var/lib/dokuwiki/tpl/default/images/button-dw.png \
  414. /var/lib/dokuwiki/tpl/default/images/button-php.gif \
  415. /var/lib/dokuwiki/tpl/default/images/button-rss.png \
  416. /var/lib/dokuwiki/tpl/default/images/buttonshadow.png \
  417. /var/lib/dokuwiki/tpl/default/images/button-xhtml.png \
  418. /var/lib/dokuwiki/tpl/default/images/closed.gif \
  419. /var/lib/dokuwiki/tpl/default/images/favicon.ico \
  420. /var/lib/dokuwiki/tpl/default/images/inputshadow.png \
  421. /var/lib/dokuwiki/tpl/default/images/link_icon.gif \
  422. /var/lib/dokuwiki/tpl/default/images/mail_icon.gif \
  423. /var/lib/dokuwiki/tpl/default/images/open.gif \
  424. /var/lib/dokuwiki/tpl/default/images/tocdot2.gif \
  425. /var/lib/dokuwiki/tpl/default/images/UWEB.png \
  426. /var/lib/dokuwiki/tpl/default/images/UWEBshadow.png \
  427. /var/lib/dokuwiki/tpl/default/images/windows.gif
  428. rmdir /var/lib/dokuwiki/tpl/default/images/ 2> /dev/null || true
  429. rm -f /var/lib/dokuwiki/tpl/default/design.css \
  430. /var/lib/dokuwiki/tpl/default/detail.php \
  431. /var/lib/dokuwiki/tpl/default/footer.html \
  432. /var/lib/dokuwiki/tpl/default/layout.css \
  433. /var/lib/dokuwiki/tpl/default/main.php \
  434. /var/lib/dokuwiki/tpl/default/media.css \
  435. /var/lib/dokuwiki/tpl/default/mediamanager.php \
  436. /var/lib/dokuwiki/tpl/default/print.css \
  437. /var/lib/dokuwiki/tpl/default/rtl.css \
  438. /var/lib/dokuwiki/tpl/default/style.ini
  439. rmdir /var/lib/dokuwiki/tpl/default/ 2> /dev/null || true
  440. rm -f /var/lib/dokuwiki/tpl/index.php
  441. mv /var/lib/dokuwiki/tpl/* /var/lib/dokuwiki/lib/tpl/ 2> /dev/null || true
  442. if ! rmdir /var/lib/dokuwiki/tpl; then
  443. # Files left on /var/lib/dokuwiki/tpl.
  444. # Typical case: the user added files deeply in
  445. # /var/lib/dokuwiki/tpl/default. Requires user
  446. # intervention.
  447. echo >/dev/stderr
  448. echo "Some files were left on /var/lib/dokuwiki/tpl:" >/dev/stderr
  449. echo "they are backed up on /var/lib/dokuwiki/tpl.old," >/dev/stderr
  450. echo "please check them and consider removing them." >/dev/stderr
  451. mv /var/lib/dokuwiki/tpl /var/lib/dokuwiki/tpl.old
  452. fi
  453. echo "[done]" >/dev/stderr
  454. fi
  455.  
  456.  
  457. # Possible cases for /usr/share/dokuwiki/lib/plugins:
  458. # * inexistant, regular file, special file: *abnormal* cases, not handled;
  459. # * symlink: no transition needed;
  460. # * directory: transition to the new location needed.
  461. if [ ! -L /usr/share/dokuwiki/lib/plugins ]; then
  462. echo -n "Moving plugins directory from /usr/share/dokuwiki to /var/lib/dokuwiki/lib... " >/dev/stderr
  463. mv /usr/share/dokuwiki/lib/plugins/* /var/lib/dokuwiki/lib/plugins/ 2> /dev/null || true
  464. if ! rmdir /usr/share/dokuwiki/lib/plugins; then
  465. # Files left on /usr/share/dokuwiki/lib/plugins.
  466. # Typical case: the user added files deeply in
  467. # /usr/share/dokuwiki/lib/plugins/something_provided_by_the_package.
  468. # Requires user intervention.
  469. echo >/dev/stderr
  470. echo "Some files were left on /usr/share/dokuwiki/lib/plugins:" >/dev/stderr
  471. echo "they are backed up on /usr/share/dokuwiki/lib/plugins.old," >/dev/stderr
  472. echo "please check them and consider removing them." >/dev/stderr
  473. mv /usr/share/dokuwiki/lib/plugins /usr/share/dokuwiki/lib/plugins.old
  474. fi
  475. ln -s /var/lib/dokuwiki/lib/plugins /usr/share/dokuwiki/lib/
  476. echo "[done]" >/dev/stderr
  477. fi
  478. # Possible cases for /var/lib/dokuwiki/plugins:
  479. # * inexistant: no transition needed;
  480. # * regular file, special file, symlink: *abnormal* cases, not handled;
  481. # * directory: transition to the new location needed.
  482. if [ -d /var/lib/dokuwiki/plugins ]; then
  483. echo -n "Moving plugins directory from /var/lib/dokuwiki to /var/lib/dokuwiki/lib... " >/dev/stderr
  484. mv /var/lib/dokuwiki/plugins/* /var/lib/dokuwiki/lib/plugins/ 2> /dev/null || true
  485. if ! rmdir /var/lib/dokuwiki/plugins; then
  486. # Files left on /var/lib/dokuwiki/plugins.
  487. # Typical case: the user added files deeply in
  488. # /var/lib/dokuwiki/plugins/something_provided_by_the_package.
  489. # Requires user intervention.
  490. echo >/dev/stderr
  491. echo "Some files were left on /var/lib/dokuwiki/plugins:" >/dev/stderr
  492. echo "they are backed up on /var/lib/dokuwiki/plugins.old," >/dev/stderr
  493. echo "please check them and consider removing them." >/dev/stderr
  494. mv /var/lib/dokuwiki/plugins /var/lib/dokuwiki/plugins.old
  495. fi
  496. echo "[done]" >/dev/stderr
  497. fi
  498.  
  499. fi
  500.  
  501. #DEBHELPER#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement