-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision_dokuwiki.sh
265 lines (221 loc) · 6.81 KB
/
provision_dokuwiki.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
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
#!/usr/bin/env bash
# Provision a blank DokuWiki install and configure it for general use.
# The root location may exist or not, depending on your needs, and you
# should aim not to change this file, instead providing a specific
# configuration script that sources this file.
# To use this in Vagrant, call your provisioning script, and set the
# shell environment variables, DW_DOWNLOAD, DW_PACKAGE, DW_PATH,
# DW_TITLE, DW_ADMIN_EMAIL, and DW_ADMIN_PASS.
# Configuration ========================================================
# Script constants -----------------------------------------------------
PROVISION_TIME=$(date '+%Y-%m-%dT%H:%M:%S%:z')
SUCCESS=0
FAILURE=1
# Script variables -----------------------------------------------------
dw_download="${DW_DOWNLOAD}"
dw_package="${DW_PACKAGE}"
dw_path="${DW_PATH}"
dw_title="${DW_TITLE}"
dw_admin_email="${DW_ADMIN_EMAIL}"
dw_admin_pass="${DW_ADMIN_PASS}"
# Installation steps ===================================================
function prepare_dokuwiki_path {
if [[ -d "${dw_path}" ]] ; then
echo "DokuWiki path ${dw_path} already exists"
return ${SUCCESS}
fi
echo "Making DokuWiki path ${dw_path}"
mkdir -p "${dw_path}"
status=$?
if [[ ${status} -gt ${SUCCESS} ]] ; then
echo "Error ${status} from mkdir while making DokuWiki path ${dw_path}"
return ${FAILURE}
fi
if [[ ! -d "${dw_path}" ]] ; then
echo "No error from mkdir, but DokuWiki path ${dw_path} doesn't exist"
return ${FAILURE}
fi
}
function download_dokuwiki {
if [[ -e "${dw_package}" ]] ; then
echo "DokuWiki package ${dw_package} is already downloaded"
echo "If you want to replace it, delete this file"
return ${SUCCESS}
fi
echo "Downloading DokuWiki from ${dw_download}"
curl --output "${dw_package}" --silent --show-error "${dw_download}"
status=$?
if [[ ${status} -gt ${SUCCESS} ]] ; then
echo "Error ${status} from curl while dowloading DokuWiki from ${dw_download}"
return ${FAILURE}
fi
if [[ -e "${dw_package}" ]] ; then
echo "Downloaded DokuWiki package ${dw_package}"
return ${SUCCESS}
else
echo "No error from curl, but ${dw_package} doesn't exist"
return ${FAILURE}
fi
}
function unpack_dokuwiki {
if [[ ! -e "${dw_package}" ]] ; then
echo "No package ${dw_package} to unpack"
return ${FAILURE}
fi
# Check for a container directory in the archive in the format dokuwiki-nnnn-nn-nnx/
contained_files=$(tar -tf "${dw_package}" | grep '^dokuwiki-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][a-z]\?/' | wc -l)
# echo "There are ${contained_files} contained files in the package"
if [[ ${contained_files} -gt 0 ]] ; then
# DokuWiki's files are in a container
strip_components=1
echo "Stripping container directory from the compressed files"
else
strip_components=0
fi
echo "Unpacking DokuWiki into ${dw_path}"
tar --strip ${strip_components} --directory="${dw_path}" -zxf "${dw_package}"
status=$?
if [[ ${status} -gt ${SUCCESS} ]] ; then
echo "Error ${status} from tar while unpacking DokuWiki from ${dw_package}"
return ${FAILURE}
fi
if [[ ! -e "${dw_path}/doku.php" ]] ; then
echo "No error from tar, but DokuWiki isn't unpacked in ${dw_path}"
return ${FAILURE}
fi
echo "DokuWiki unpacked in ${dw_path}"
return ${SUCCESS}
}
function configure_dokuwiki {
if [[ -e "${dw_path}/conf/local.php" ]] ; then
echo "DokuWiki is already configured in ${dw_path}/conf/local.php"
echo "If you want to replace the configuration, delete this file"
return ${SUCCESS}
fi
if [[ ! -d "${dw_path}/conf" ]] ; then
echo "Install didn't prepare a conf directory for DokuWiki"
return ${FAILURE}
fi
# Local configuration --------------------------------------------------
config_file="${dw_path}/conf/local.php"
cat > "${config_file}" <<EOF
<?php
/**
* Dokuwiki's Main Configuration File - Local Settings
* Auto-generated by Vagrant provisioning
* Date: ${PROVISION_TIME}
*/
\$conf['title'] = '${dw_title}';
EOF
cat >> "${config_file}" <<'EOF'
$conf['lang'] = 'en';
$conf['license'] = '0';
$conf['useacl'] = 1;
$conf['superuser'] = '@admin';
$conf['disableactions'] = 'register';
$conf['allowdebug'] = 1;
EOF
if [[ ! -e "${config_file}" ]] ; then
echo "No error from cat command, but DokuWiki isn't configured in ${config_file}"
return ${FAILURE}
fi
# ACL configuration ----------------------------------------------------
config_file="${dw_path}/conf/acl.auth.php"
cat > "${config_file}" <<EOF
# acl.auth.php
# <?php exit()?>
# Don't modify the lines above
#
# Access Control Lists
#
# Auto-generated by Vagrant provisioning
# Date: ${PROVISION_TIME}
* @ALL 1
* @user 8
EOF
if [[ ! -e "${config_file}" ]] ; then
echo "No error from cat command, but DokuWiki isn't configured in ${config_file}"
return ${FAILURE}
fi
# User configuration ---------------------------------------------------
DW_ADMIN_HASH=$(cd "${dw_path}" ; php /vagrant/dokuwiki_password.php "${DW_ADMIN_PASS}")
config_file="${dw_path}/conf/users.auth.php"
cat > "${config_file}" <<EOF
# users.auth.php
# <?php exit()?>
# Don't modify the lines above
#
# Userfile
#
# Format:
#
# login:passwordhash:Real Name:email:groups,comma,seperated
#
# Auto-generated by Vagrant provisioning
# Date: ${PROVISION_TIME}
EOF
cat >> "${config_file}" <<EOF
admin:${DW_ADMIN_HASH}:DokuWiki Administrator:${dw_admin_email}:admin,user
EOF
if [[ ! -e "${config_file}" ]] ; then
echo "No error from cat command, but DokuWiki isn't configured in ${config_file}"
return ${FAILURE}
fi
# Plugin configuration -------------------------------------------------
config_file="${dw_path}/conf/plugins.local.php"
cat > "${config_file}" <<EOF
<?php
/*
* Local plugin enable/disable settings
*
* Auto-generated by Vagrant provisioning
* Date: ${PROVISION_TIME}
*/
EOF
cat >> "${config_file}" <<'EOF'
$plugins['authad'] = 0;
$plugins['authldap'] = 0;
$plugins['authmysql'] = 0;
$plugins['authpgsql'] = 0;
EOF
if [[ ! -e "${config_file}" ]] ; then
echo "No error from cat command, but DokuWiki isn't configured in ${config_file}"
return ${FAILURE}
fi
echo "DokuWiki configured in ${dw_path}/conf"
return ${SUCCESS}
}
# Full installation function ===========================================
function install_dokuwiki {
if [[ -e "${dw_path}/doku.php" ]] ; then
echo "DokuWiki is already installed"
return ${SUCCESS}
fi
prepare_dokuwiki_path
status=$?
if [[ ${status} -gt ${SUCCESS} ]] ; then
return ${status}
fi
download_dokuwiki
status=$?
if [[ ${status} -gt ${SUCCESS} ]] ; then
return ${status}
fi
unpack_dokuwiki
status=$?
if [[ ${status} -gt ${SUCCESS} ]] ; then
return ${status}
fi
configure_dokuwiki
status=$?
if [[ ${status} -gt ${SUCCESS} ]] ; then
return ${status}
fi
return ${SUCCESS}
}
# Script ===============================================================
install_dokuwiki
status=$?
if [[ ${status} -gt ${SUCCESS} ]] ; then
exit ${status}
fi