2 # Charles Roussel <charles.roussel@ensimag.imag.fr>
3 # Simon Cathebras <simon.cathebras@ensimag.imag.fr>
4 # Julien Khayat <julien.khayat@ensimag.imag.fr>
5 # Guillaume Sasdy <guillaume.sasdy@ensimag.imag.fr>
6 # Simon Perrat <simon.perrat@ensimag.imag.fr>
7 # License: GPL v2 or later
10 # CONFIGURATION VARIABLES
11 # You might want to change these ones
16 WIKI_URL=http://"$SERVER_ADDR:$PORT/$WIKI_DIR_NAME"
18 TEST_OUTPUT_DIRECTORY=$(pwd)
19 TEST_DIRECTORY="$CURR_DIR"/../../../t
21 export TEST_OUTPUT_DIRECTORY TEST_DIRECTORY CURR_DIR
23 if test "$LIGHTTPD" = "false" ; then
26 WIKI_DIR_INST="$CURR_DIR/$WEB_WWW"
30 "$CURR_DIR"/test-gitmw.pl upload_file "$@"
34 "$CURR_DIR"/test-gitmw.pl get_page "$@"
38 "$CURR_DIR"/test-gitmw.pl delete_page "$@"
42 "$CURR_DIR"/test-gitmw.pl edit_page "$@"
46 die_with_status 1 "$@"
57 # Check the preconditions to run git-remote-mediawiki's tests
58 test_check_precond () {
59 if ! test_have_prereq PERL
61 skip_all='skipping gateway git-mw tests, perl not available'
65 GIT_EXEC_PATH=$(cd "$(dirname "$0")" && cd "../.." && pwd)
66 PATH="$GIT_EXEC_PATH"'/bin-wrapper:'"$PATH"
68 if ! test -d "$WIKI_DIR_INST/$WIKI_DIR_NAME"
70 skip_all='skipping gateway git-mw tests, no mediawiki found'
75 # test_diff_directories <dir_git> <dir_wiki>
77 # Compare the contents of directories <dir_git> and <dir_wiki> with diff
78 # and errors if they do not match. The program will
79 # not look into .git in the process.
80 # Warning: the first argument MUST be the directory containing the git data
81 test_diff_directories () {
85 diff -r -b "$1_tmp" "$2"
91 # Check that <dir> contains exactly <N> files
92 test_contains_N_files () {
93 if test $(ls -- "$1" | wc -l) -ne "$2"; then
94 echo "directory $1 should contain $2 files"
95 echo "it contains these files:"
102 # wiki_check_content <file_name> <page_name>
104 # Compares the contents of the file <file_name> and the wiki page
105 # <page_name> and exits with error 1 if they do not match.
106 wiki_check_content () {
108 wiki_getpage "$2" wiki_tmp
109 # replacement of forbidden character in file name
110 page_name=$(printf "%s\n" "$2" | sed -e "s/\//%2F/g")
112 diff -b "$1" wiki_tmp/"$page_name".mw
116 error "ERROR: file $2 not found on wiki"
121 # wiki_page_exist <page_name>
123 # Check the existence of the page <page_name> on the wiki and exits
124 # with error if it is absent from it.
127 wiki_getpage "$1" wiki_tmp
128 page_name=$(printf "%s\n" "$1" | sed "s/\//%2F/g")
129 if test -f wiki_tmp/"$page_name".mw ; then
133 error "test failed: file $1 not found on wiki"
137 # wiki_getallpagename
139 # Fetch the name of each page on the wiki.
140 wiki_getallpagename () {
141 "$CURR_DIR"/test-gitmw.pl getallpagename
144 # wiki_getallpagecategory <category>
146 # Fetch the name of each page belonging to <category> on the wiki.
147 wiki_getallpagecategory () {
148 "$CURR_DIR"/test-gitmw.pl getallpagename "$@"
151 # wiki_getallpage <dest_dir> [<category>]
153 # Fetch all the pages from the wiki and place them in the directory
155 # If <category> is define, then wiki_getallpage fetch the pages included
162 wiki_getallpagecategory "$2"
165 while read -r line; do
166 wiki_getpage "$line" $1;
170 # ================= Install part =================
179 # Create the configuration files and the folders necessary to start lighttpd.
180 # Overwrite any existing file.
185 cat > $WEB/lighttpd.conf <<EOF
186 server.document-root = "$CURR_DIR/$WEB_WWW"
188 server.pid-file = "$CURR_DIR/$WEB_TMP/pid"
198 index-file.names = ("index.php" , "index.html")
201 ".pdf" => "application/pdf",
202 ".sig" => "application/pgp-signature",
203 ".spl" => "application/futuresplash",
204 ".class" => "application/octet-stream",
205 ".ps" => "application/postscript",
206 ".torrent" => "application/x-bittorrent",
207 ".dvi" => "application/x-dvi",
208 ".gz" => "application/x-gzip",
209 ".pac" => "application/x-ns-proxy-autoconfig",
210 ".swf" => "application/x-shockwave-flash",
211 ".tar.gz" => "application/x-tgz",
212 ".tgz" => "application/x-tgz",
213 ".tar" => "application/x-tar",
214 ".zip" => "application/zip",
215 ".mp3" => "audio/mpeg",
216 ".m3u" => "audio/x-mpegurl",
217 ".wma" => "audio/x-ms-wma",
218 ".wax" => "audio/x-ms-wax",
219 ".ogg" => "application/ogg",
220 ".wav" => "audio/x-wav",
221 ".gif" => "image/gif",
222 ".jpg" => "image/jpeg",
223 ".jpeg" => "image/jpeg",
224 ".png" => "image/png",
225 ".xbm" => "image/x-xbitmap",
226 ".xpm" => "image/x-xpixmap",
227 ".xwd" => "image/x-xwindowdump",
228 ".css" => "text/css",
229 ".html" => "text/html",
230 ".htm" => "text/html",
231 ".js" => "text/javascript",
232 ".asc" => "text/plain",
233 ".c" => "text/plain",
234 ".cpp" => "text/plain",
235 ".log" => "text/plain",
236 ".conf" => "text/plain",
237 ".text" => "text/plain",
238 ".txt" => "text/plain",
239 ".dtd" => "text/xml",
240 ".xml" => "text/xml",
241 ".mpeg" => "video/mpeg",
242 ".mpg" => "video/mpeg",
243 ".mov" => "video/quicktime",
244 ".qt" => "video/quicktime",
245 ".avi" => "video/x-msvideo",
246 ".asf" => "video/x-ms-asf",
247 ".asx" => "video/x-ms-asf",
248 ".wmv" => "video/x-ms-wmv",
249 ".bz2" => "application/x-bzip",
250 ".tbz" => "application/x-bzip-compressed-tar",
251 ".tar.bz2" => "application/x-bzip-compressed-tar",
255 fastcgi.server = ( ".php" =>
257 ( "socket" => "$CURR_DIR/$WEB_TMP/php.socket",
258 "bin-path" => "$PHP_DIR/php-cgi -c $CURR_DIR/$WEB/php.ini"
265 cat > $WEB/php.ini <<EOF
266 session.save_path ='$CURR_DIR/$WEB_TMP'
272 # Start or restart daemon lighttpd. If restart, rewrite configuration files.
274 if test -f "$WEB_TMP/pid"; then
275 echo "Instance already running. Restarting..."
279 "$LIGHTTPD_DIR"/lighttpd -f "$WEB"/lighttpd.conf
281 if test $? -ne 0 ; then
282 echo "Could not execute http daemon lighttpd"
289 # Kill daemon lighttpd and removes files and folders associated.
291 test -f "$WEB_TMP/pid" && kill $(cat "$WEB_TMP/pid")
294 # Create the SQLite database of the MediaWiki. If the database file already
295 # exists, it will be deleted.
296 # This script should be runned from the directory where $FILES_FOLDER is
299 rm -f "$TMP/$DB_FILE"
301 echo "Generating the SQLite database file. It can take some time ..."
302 # Run the php script to generate the SQLite database file
304 php "$FILES_FOLDER/$DB_INSTALL_SCRIPT" $(basename "$DB_FILE" .sqlite) \
305 "$WIKI_ADMIN" "$WIKI_PASSW" "$TMP" "$PORT"
307 if ! test -f "$TMP/$DB_FILE"
309 error "Can't create database file $TMP/$DB_FILE. Try to run ./install-wiki.sh delete first."
312 # Copy the generated database file into the directory the
314 cp "$TMP/$DB_FILE" "$FILES_FOLDER" ||
315 error "Unable to copy $TMP/$DB_FILE to $FILES_FOLDER"
318 # Install a wiki in your web server directory.
320 if test $LIGHTTPD = "true" ; then
324 SERVER_ADDR=$SERVER_ADDR:$PORT
325 # In this part, we change directory to $TMP in order to download,
326 # unpack and copy the files of MediaWiki
328 mkdir -p "$WIKI_DIR_INST/$WIKI_DIR_NAME"
329 if ! test -d "$WIKI_DIR_INST/$WIKI_DIR_NAME"
331 error "Folder $WIKI_DIR_INST/$WIKI_DIR_NAME doesn't exist.
332 Please create it and launch the script again."
335 # Fetch MediaWiki's archive if not already present in the TMP directory
336 MW_FILENAME="mediawiki-$MW_VERSION_MAJOR.$MW_VERSION_MINOR.tar.gz"
338 if ! test -f $MW_FILENAME
340 echo "Downloading $MW_VERSION_MAJOR.$MW_VERSION_MINOR sources ..."
341 wget "http://download.wikimedia.org/mediawiki/$MW_VERSION_MAJOR/$MW_FILENAME" ||
342 error "Unable to download "\
343 "http://download.wikimedia.org/mediawiki/$MW_VERSION_MAJOR/"\
345 "Please fix your connection and launch the script again."
346 echo "$MW_FILENAME downloaded in $(pwd)/;" \
347 "you can delete it later if you want."
349 echo "Reusing existing $MW_FILENAME downloaded in $(pwd)/"
351 archive_abs_path=$(pwd)/$MW_FILENAME
352 cd "$WIKI_DIR_INST/$WIKI_DIR_NAME/" ||
353 error "can't cd to $WIKI_DIR_INST/$WIKI_DIR_NAME/"
354 tar xzf "$archive_abs_path" --strip-components=1 ||
355 error "Unable to extract WikiMedia's files from $archive_abs_path to "\
356 "$WIKI_DIR_INST/$WIKI_DIR_NAME"
361 # Copy the generic LocalSettings.php in the web server's directory
362 # And modify parameters according to the ones set at the top
364 # Note that LocalSettings.php is never modified.
365 if ! test -f "$FILES_FOLDER/LocalSettings.php"
367 error "Can't find $FILES_FOLDER/LocalSettings.php " \
368 "in the current folder. "\
369 "Please run the script inside its folder."
371 cp "$FILES_FOLDER/LocalSettings.php" \
372 "$FILES_FOLDER/LocalSettings-tmp.php" ||
373 error "Unable to copy $FILES_FOLDER/LocalSettings.php " \
374 "to $FILES_FOLDER/LocalSettings-tmp.php"
376 # Parse and set the LocalSettings file of the user according to the
377 # CONFIGURATION VARIABLES section at the beginning of this script
378 file_swap="$FILES_FOLDER/LocalSettings-swap.php"
379 sed "s,@WG_SCRIPT_PATH@,/$WIKI_DIR_NAME," \
380 "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
381 mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
382 sed "s,@WG_SERVER@,http://$SERVER_ADDR," \
383 "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
384 mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
385 sed "s,@WG_SQLITE_DATADIR@,$TMP," \
386 "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
387 mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
388 sed "s,@WG_SQLITE_DATAFILE@,$( basename $DB_FILE .sqlite)," \
389 "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
390 mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
392 mv "$FILES_FOLDER/LocalSettings-tmp.php" \
393 "$WIKI_DIR_INST/$WIKI_DIR_NAME/LocalSettings.php" ||
394 error "Unable to move $FILES_FOLDER/LocalSettings-tmp.php" \
395 "in $WIKI_DIR_INST/$WIKI_DIR_NAME"
396 echo "File $FILES_FOLDER/LocalSettings.php is set in" \
397 " $WIKI_DIR_INST/$WIKI_DIR_NAME"
399 echo "Your wiki has been installed. You can check it at
400 http://$SERVER_ADDR/$WIKI_DIR_NAME"
403 # Reset the database of the wiki and the password of the admin
405 # Warning: This function must be called only in a subdirectory of t/ directory
407 # Copy initial database of the wiki
408 if ! test -f "../$FILES_FOLDER/$DB_FILE"
410 error "Can't find ../$FILES_FOLDER/$DB_FILE in the current folder."
412 cp "../$FILES_FOLDER/$DB_FILE" "$TMP" ||
413 error "Can't copy ../$FILES_FOLDER/$DB_FILE in $TMP"
414 echo "File $FILES_FOLDER/$DB_FILE is set in $TMP"
417 # Delete the wiki created in the web server's directory and all its content
418 # saved in the database.
420 if test $LIGHTTPD = "true"; then
424 # Delete the wiki's directory.
425 rm -rf "$WIKI_DIR_INST/$WIKI_DIR_NAME" ||
426 error "Wiki's directory $WIKI_DIR_INST/" \
427 "$WIKI_DIR_NAME could not be deleted"
428 # Delete the wiki's SQLite database.
429 rm -f "$TMP/$DB_FILE" ||
430 error "Database $TMP/$DB_FILE could not be deleted."
433 # Delete the wiki's SQLite database
434 rm -f "$TMP/$DB_FILE" || error "Database $TMP/$DB_FILE could not be deleted."
435 rm -f "$FILES_FOLDER/$DB_FILE"
436 rm -rf "$TMP/mediawiki-$MW_VERSION_MAJOR.$MW_VERSION_MINOR.tar.gz"