-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_script
executable file
·276 lines (235 loc) · 7.63 KB
/
install_script
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
#!/bin/sh
# /System/Library/CoreServices/ServerVersion.plist : OSX server
# /System/Library/CoreServices/SystemVersion.plist : OSX standard
log=/tmp/wipha.log
date=$(date "+%d_%b_%Y-%H:%M:%S")
function test_error() {
if [ $1 != "0" ]; then
cat $log
echo "... Abort ..."
exit 1
fi
}
function backupOnce() {
backupFile=$1.bak_WiPha_$date
if ! [ -f $backupFile ]; then
cp $1 $backupFile 2>$log
test_error $?
fi
}
# Script is run with admin privileges (sudo) -> whoami=root
if [ -z "$USER" ]; then
if [ -z "$LOGNAME" ]; then
echo "Can't determine user (no USER or LOGNAME variable)"
exit 1;
else
user=$LOGNAME
fi
else
user=$USER
fi
home="/Users/$user"
src="$1"
# Find out where to install WiPhA
destFile=/tmp/wiphadest
if [ -r $destFile ]; then
dests[${#dests[@]}]=$(cat $destFile);
echo "Override WiPhA default destination with content of $destFile: $dests"
else
dests[${#dests[@]}]="$home/Sites";
if [ "$home" != "$HOME" ]; then
dests[${#dests[@]}]="$HOME/Sites";
fi
fi
for testDest in "${dests[@]}"; do
if [ -d "$testDest" ]; then
dest="$testDest"
break
fi
done
if [ -z "$dest" ]; then
echo "Can't find a correct destination for WiPhA. Tried:"
for dest in "${dests[@]}"; do
echo " - $dest"
done
else
echo "Will install in: $dest"
fi
# Find out which version of OSX we run on
osver=`sw_vers | awk '/ProductVersion/ {print substr($2,0,4)}'`
webserver="apache2"
unique=$(date "+%d_%b_%Y-%H_%M_%S")
if [ -e "$dest/wipha" ]; then
ver=$(awk -F\" '/version/ {print $2}' "$dest/wipha/configs/wipha.conf")
echo
echo "Detected WiPhA installed version: $ver"
if [ -e "$dest/wipha/data" ] && [[ "$ver" > "0.7" ]]; then
echo
echo "Saving previous WiPhA data"
mv "$dest/wipha/data" "/tmp/data_$unique" 2> $log
test_error $?
else
echo
echo "Your previous preferences are too different from the current version preferences and won't be saved. Sorry."
fi
echo
echo "Saving previous WiPhA config"
mv "$dest/wipha/configs/wipha.conf" "/tmp/wipha.conf_$unique" 2> $log
test_error $?
echo
echo "Moving old version of WiPhA to the trash"
mv "$dest/wipha" "$home/.Trash/wipha_$unique" 2> $log
test_error $?
fi
echo
echo "Decompacting WiPhA in your Sites folder ($dest)"
cd $dest
tar jxf "$src/Contents/Resources/wipha.tbz" 2> $log
test_error $?
echo
echo "Setting permissions on these files"
own=$(id -ur)
chown -Rh $own wipha 2> $log
test_error $?
grp=$(id -gr)
chgrp -Rh $grp wipha 2> $log
test_error $?
find wipha -type f | xargs -I @ chmod 644 "@"
find wipha -type d | xargs -I @ chmod 755 "@"
find wipha | xargs -I @ touch "@" # force the browser cache to reload
echo
echo "Setting setuid bit ($user) on permission corrector executable"
# 4755 = -rwsr-xr-x (755 + setuid)
chmod 4755 wipha/changeperm 2> $log
test_error $?
if [ -e "/tmp/data_$unique" ]; then
echo
echo "Installing your previous WiPhA data"
mv "$dest/wipha/data" "/tmp/data_empty_$unique" 2> $log
test_error $?
mv "/tmp/data_$unique" "$dest/wipha/data" 2> $log
test_error $?
rm -r "/tmp/data_empty_$unique"
rm -f "$dest/wipha/data/cache/*"
fi
if [ -e "/tmp/wipha.conf_$unique" ]; then
echo
echo "Renaming your previous WiPhA config as wipha.conf.old"
mv "/tmp/wipha.conf_$unique" "$dest/wipha/configs/wipha.conf.old" 2> $log
test_error $?
fi
cd wipha
echo
echo "Grant write access to Apache on the WiPhA data directories"
# 3777 = drwxrwsrwt (777 + setgid + sticky)
chmod 3777 data 2> $log
test_error $?
chmod 3777 data/cache 2> $log
test_error $?
echo
echo " Remove WiPhA smarty cache files (/tmp/smarty/wipha)"
rm -rf /tmp/smarty/wipha
test_error $?
### Apache configuration ###
case "$webserver" in
apache2) webserverconf="/etc/apache2/httpd.conf";;
esac
echo
echo "Configuring Apache to handle php"
cat $webserverconf | case "$webserver" in
apache2) awk ' \
/[ \t]*#[ \t]*LoadModule[ \t]+php5_module/ {print "# Following line uncommented by WiPha installer"; print "LoadModule php5_module", $3; next} \
{print $0} \
';;
esac 1> /tmp/httpd.conf 2>$log
test_error $?
if [ "$(diff $webserverconf /tmp/httpd.conf)" != "" ]; then
backupOnce $webserverconf
# Why does mv hang ???? Let's replace it by cp+rm
# mv /tmp/httpd.conf $webserverconf 2>$log
cp /tmp/httpd.conf $webserverconf 2>$log
test_error $?
rm /tmp/httpd.conf 2>$log
test_error $?
else
rm /tmp/httpd.conf
echo " Was already done"
fi
echo
echo "Configuring Apache to take wipha access protection in account (.htaccess)"
perl -n -e 'BEGIN {undef $/;} exit m%\n\s*<Directory\s+"'$dest/wipha'">\s*\n\s*AllowOverride\s+All\s*\n\s*</Directory>%' $webserverconf
if [ "$?" != "1" ]; then
backupOnce $webserverconf
cat << EOF 1>> $webserverconf 2> $log
# Following lines added by WiPha installer to take wipha .htaccess into account
<Directory "$dest/wipha">
AllowOverride All
</Directory>
EOF
test_error $?
else
echo " Was already done"
fi
rm $log
################################## TEST PART ################################
echo
echo "Checks..."
echo
err=0
echo -n "'sips': "
if [ -x "/usr/bin/sips" ]; then echo "ok"; else echo "KO ! (sips is required for the slideshow mode)"; err=1; fi
echo -n "'data' permission is drwxrwsrwt: "
stat=$(stat -f %Sp data)
if [ "$stat" == "drwxrwsrwt" ]; then echo "ok"; else echo "KO ! ($stat)"; err=1; fi
echo -n "'data/cache' permission is drwxrwsrwt: "
stat=$(stat -f %Sp data/cache)
if [ "$stat" == "drwxrwsrwt" ]; then echo "ok"; else echo "KO ! ($stat)"; err=1; fi
echo -n "'changeperm' permission is -rwsr-xr-x: "
stat=$(stat -f %Sp changeperm)
if [ "$stat" == "-rwsr-xr-x" ]; then echo "ok"; else echo "KO ! ($stat)"; err=1; fi
echo -n "smarty cache files removed: "
if [ ! -d "/tmp/smarty/wipha" ]; then echo "ok"; else echo "KO ! (Please delete /tmp/smarty/wipha to make sure wipha new html content is properly displayed)"; err=1; fi
case "$webserver" in
apache2)
echo -n "OSX Standard PHP5 enabled: "
load=$(grep -c -E "^[ \t]*LoadModule[ \t]+php5_module[ \t]+libexec/apache2/libphp5.so" $webserverconf)
if [ "$load" == "1" ] ; then echo "ok (unless other PHP versions also installed)"; else
echo "KO !"; err=1
echo " You should have this line in $webserverconf:"
echo " LoadModule php5_module libexec/apache2/libphp5.so"
fi
;;
esac
echo -n "WiPhA access protection enabled (.htaccess): "
perl -n -e 'BEGIN {undef $/;} exit m%\n\s*<Directory\s+"'$dest/wipha'">\s*\n\s*AllowOverride\s+All\s*\n\s*</Directory>%' $webserverconf
if [ "$?" == "1" ]; then echo "ok"; else
echo "KO !"; err=1
echo " You should have these 3 lines in $webserverconf:"
echo ' <Directory "'$dest/wipha'">'
echo ' AllowOverride All'
echo ' </Directory>'
fi
################################## START ################################
if [ "$err" == "1" ]; then
echo
echo "Please correct this before using WiPhA."
else
echo
echo "Installation complete"
echo
echo
echo "Getting rights to restart Apache server"
cp "$src/Contents/Resources/apacheRestart" /tmp/ 2> $log
test_error $?
chown root /tmp/apacheRestart 2> $log
test_error $?
chmod 4755 /tmp/apacheRestart 2> $log
test_error $?
echo "Re-starting Apache server"
/tmp/apacheRestart
rm /tmp/apacheRestart
echo "Wait 5 secondes"
sleep 5
echo "Your browser should now open the WiPha login page (please bookmark this page for future use)."
open "http://localhost/~$user/wipha"
fi