-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
03-config.sh
125 lines (105 loc) · 3.92 KB
/
03-config.sh
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
#!/usr/bin/with-contenv sh
# shellcheck shell=sh
runas_user() {
yasu dokuwiki:dokuwiki "$@"
}
TZ=${TZ:-UTC}
MEMORY_LIMIT=${MEMORY_LIMIT:-256M}
UPLOAD_MAX_SIZE=${UPLOAD_MAX_SIZE:-16M}
CLEAR_ENV=${CLEAR_ENV:-yes}
OPCACHE_MEM_SIZE=${OPCACHE_MEM_SIZE:-128}
LISTEN_IPV6=${LISTEN_IPV6:-true}
REAL_IP_FROM=${REAL_IP_FROM:-0.0.0.0/32}
REAL_IP_HEADER=${REAL_IP_HEADER:-X-Forwarded-For}
LOG_IP_VAR=${LOG_IP_VAR:-remote_addr}
DOKUWIKI_RUN_INDEXER=${DOKUWIKI_RUN_INDEXER:-true}
# Timezone
echo "Setting timezone to ${TZ}..."
ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime
echo ${TZ} > /etc/timezone
# PHP
echo "Setting PHP-FPM configuration..."
sed -e "s/@MEMORY_LIMIT@/$MEMORY_LIMIT/g" \
-e "s/@UPLOAD_MAX_SIZE@/$UPLOAD_MAX_SIZE/g" \
-e "s/@CLEAR_ENV@/$CLEAR_ENV/g" \
/tpls/etc/php82/php-fpm.d/www.conf > /etc/php82/php-fpm.d/www.conf
echo "Setting PHP INI configuration..."
sed -i "s|memory_limit.*|memory_limit = ${MEMORY_LIMIT}|g" /etc/php82/php.ini
sed -i "s|;date\.timezone.*|date\.timezone = ${TZ}|g" /etc/php82/php.ini
sed -i "s|auto_prepend_file.*|auto_prepend_file = /var/www/inc/preload.php|g" /etc/php82/php.ini
# OpCache
echo "Setting OpCache configuration..."
sed -e "s/@OPCACHE_MEM_SIZE@/$OPCACHE_MEM_SIZE/g" \
/tpls/etc/php82/conf.d/opcache.ini > /etc/php82/conf.d/opcache.ini
# Nginx
echo "Setting Nginx configuration..."
sed -e "s/@UPLOAD_MAX_SIZE@/$UPLOAD_MAX_SIZE/g" \
-e "s#@REAL_IP_FROM@#$REAL_IP_FROM#g" \
-e "s#@REAL_IP_HEADER@#$REAL_IP_HEADER#g" \
-e "s#@LOG_IP_VAR@#$LOG_IP_VAR#g" \
/tpls/etc/nginx/nginx.conf > /etc/nginx/nginx.conf
if [ "$LISTEN_IPV6" != "true" ]; then
sed -e '/listen \[::\]:/d' -i /etc/nginx/nginx.conf
fi
# DokuWiki
echo "Initializing DokuWiki files / folders..."
runas_user mkdir -p /data/plugins /data/tpl
echo "Adding preload.php..."
cp -f /tpls/preload.php /var/www/inc/
echo "Copying global config..."
runas_user cp -Rf /var/www/conf /data/
firstInstall=0
if [ ! -f /data/conf/local.protected.php ]; then
firstInstall=1
echo "First install detected..."
sed -i "1s/.*/<?php define('DOKU_CONF', '\/data\/conf\/'); define('DOKU_LOCAL', '\/data\/conf\/');/" /var/www/install.php
fi
if [ ! -d /data/data ]; then
echo "Creating initial data folder..."
runas_user cp -Rf /var/www/data /data/
fi
echo "Bootstrapping configuration..."
runas_user cat > /data/conf/local.protected.php <<EOL
<?php
\$conf['savedir'] = '/data/data';
EOL
chown dokuwiki:dokuwiki /data/conf/local.protected.php
echo -n "Saving bundled plugins list..."
bundledPlugins=$(ls -d /var/www/lib/plugins/*/ | cut -f6 -d'/')
for bundledPlugin in ${bundledPlugins}; do
echo "${bundledPlugin}" >> /tmp/bundledPlugins.txt
done
echo " $(wc -l < /tmp/bundledPlugins.txt) found"
echo -n "Saving bundled templates list..."
bundledTpls=$(ls -d /var/www/lib/tpl/*/ | cut -f6 -d'/')
for bundledTpl in ${bundledTpls}; do
echo "${bundledTpl}" >> /tmp/bundledTpls.txt
done
echo " $(wc -l < /tmp/bundledTpls.txt) found"
echo "Checking user plugins in /data/plugins..."
userPlugins=$(ls -l /data/plugins | egrep '^d' | awk '{print $9}')
for userPlugin in ${userPlugins}; do
if [ -d "/var/www/lib/plugins/${userPlugin}" ]; then
echo "WARNING: Plugin ${userPlugin} will not be used (already bundled in DokuWiki)"
continue
fi
ln -sf "/data/plugins/${userPlugin}" "/var/www/lib/plugins/${userPlugin}"
done
echo "Checking user templates in /data/tpl..."
userTpls=$(ls -l /data/tpl | egrep '^d' | awk '{print $9}')
for userTpl in ${userTpls}; do
if [ -d "/var/www/lib/tpl/${userTpl}" ]; then
echo "WARNING: Template ${userTpl} will not be used (already bundled in DokuWiki)"
continue
fi
ln -sf "/data/tpl/${userTpl}" "/var/www/lib/tpl/${userTpl}"
done
# First install ?
if [ ${firstInstall} -eq 1 ]; then
echo ">>"
echo ">> Open your browser to install DokuWiki through the wizard (/install.php)"
echo ">>"
elif [ "$DOKUWIKI_RUN_INDEXER" = "true" ]; then
echo "Launching DokuWiki indexer..."
runas_user php /var/www/bin/indexer.php -c
fi