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"
31 "$CURR_DIR"/test-gitmw.pl get_page "$@"
35 "$CURR_DIR"/test-gitmw.pl delete_page "$@"
39 "$CURR_DIR"/test-gitmw.pl edit_page "$@"
43 die_with_status 1 "$@"
54 # Check the preconditions to run git-remote-mediawiki's tests
55 test_check_precond () {
56 if ! test_have_prereq PERL
58 skip_all='skipping gateway git-mw tests, perl not available'
62 if [ ! -f "$GIT_BUILD_DIR"/git-remote-mediawiki ];
64 echo "No remote mediawiki for git found. Copying it in git"
65 echo "cp $GIT_BUILD_DIR/contrib/mw-to-git/git-remote-mediawiki $GIT_BUILD_DIR/"
66 ln -s "$GIT_BUILD_DIR"/contrib/mw-to-git/git-remote-mediawiki "$GIT_BUILD_DIR"
69 if [ ! -d "$WIKI_DIR_INST/$WIKI_DIR_NAME" ];
71 skip_all='skipping gateway git-mw tests, no mediawiki found'
76 # test_diff_directories <dir_git> <dir_wiki>
78 # Compare the contents of directories <dir_git> and <dir_wiki> with diff
79 # and errors if they do not match. The program will
80 # not look into .git in the process.
81 # Warning: the first argument MUST be the directory containing the git data
82 test_diff_directories () {
86 diff -r -b "$1_tmp" "$2"
92 # Check that <dir> contains exactly <N> files
93 test_contains_N_files () {
94 if test `ls -- "$1" | wc -l` -ne "$2"; then
95 echo "directory $1 sould contain $2 files"
96 echo "it contains these files:"
103 # wiki_check_content <file_name> <page_name>
105 # Compares the contents of the file <file_name> and the wiki page
106 # <page_name> and exits with error 1 if they do not match.
107 wiki_check_content () {
109 wiki_getpage "$2" wiki_tmp
110 # replacement of forbidden character in file name
111 page_name=$(printf "%s\n" "$2" | sed -e "s/\//%2F/g")
113 diff -b "$1" wiki_tmp/"$page_name".mw
117 error "ERROR: file $2 not found on wiki"
122 # wiki_page_exist <page_name>
124 # Check the existence of the page <page_name> on the wiki and exits
125 # with error if it is absent from it.
128 wiki_getpage "$1" wiki_tmp
129 page_name=$(printf "%s\n" "$1" | sed "s/\//%2F/g")
130 if test -f wiki_tmp/"$page_name".mw ; then
134 error "test failed: file $1 not found on wiki"
138 # wiki_getallpagename
140 # Fetch the name of each page on the wiki.
141 wiki_getallpagename () {
142 "$CURR_DIR"/test-gitmw.pl getallpagename
145 # wiki_getallpagecategory <category>
147 # Fetch the name of each page belonging to <category> on the wiki.
148 wiki_getallpagecategory () {
149 "$CURR_DIR"/test-gitmw.pl getallpagename "$@"
152 # wiki_getallpage <dest_dir> [<category>]
154 # Fetch all the pages from the wiki and place them in the directory
156 # If <category> is define, then wiki_getallpage fetch the pages included
163 wiki_getallpagecategory "$2"
166 while read -r line; do
167 wiki_getpage "$line" $1;
171 # ================= Install part =================
180 # Create the configuration files and the folders necessary to start lighttpd.
181 # Overwrite any existing file.
186 cat > $WEB/lighttpd.conf <<EOF
187 server.document-root = "$CURR_DIR/$WEB_WWW"
189 server.pid-file = "$CURR_DIR/$WEB_TMP/pid"
199 index-file.names = ("index.php" , "index.html")
202 ".pdf" => "application/pdf",
203 ".sig" => "application/pgp-signature",
204 ".spl" => "application/futuresplash",
205 ".class" => "application/octet-stream",
206 ".ps" => "application/postscript",
207 ".torrent" => "application/x-bittorrent",
208 ".dvi" => "application/x-dvi",
209 ".gz" => "application/x-gzip",
210 ".pac" => "application/x-ns-proxy-autoconfig",
211 ".swf" => "application/x-shockwave-flash",
212 ".tar.gz" => "application/x-tgz",
213 ".tgz" => "application/x-tgz",
214 ".tar" => "application/x-tar",
215 ".zip" => "application/zip",
216 ".mp3" => "audio/mpeg",
217 ".m3u" => "audio/x-mpegurl",
218 ".wma" => "audio/x-ms-wma",
219 ".wax" => "audio/x-ms-wax",
220 ".ogg" => "application/ogg",
221 ".wav" => "audio/x-wav",
222 ".gif" => "image/gif",
223 ".jpg" => "image/jpeg",
224 ".jpeg" => "image/jpeg",
225 ".png" => "image/png",
226 ".xbm" => "image/x-xbitmap",
227 ".xpm" => "image/x-xpixmap",
228 ".xwd" => "image/x-xwindowdump",
229 ".css" => "text/css",
230 ".html" => "text/html",
231 ".htm" => "text/html",
232 ".js" => "text/javascript",
233 ".asc" => "text/plain",
234 ".c" => "text/plain",
235 ".cpp" => "text/plain",
236 ".log" => "text/plain",
237 ".conf" => "text/plain",
238 ".text" => "text/plain",
239 ".txt" => "text/plain",
240 ".dtd" => "text/xml",
241 ".xml" => "text/xml",
242 ".mpeg" => "video/mpeg",
243 ".mpg" => "video/mpeg",
244 ".mov" => "video/quicktime",
245 ".qt" => "video/quicktime",
246 ".avi" => "video/x-msvideo",
247 ".asf" => "video/x-ms-asf",
248 ".asx" => "video/x-ms-asf",
249 ".wmv" => "video/x-ms-wmv",
250 ".bz2" => "application/x-bzip",
251 ".tbz" => "application/x-bzip-compressed-tar",
252 ".tar.bz2" => "application/x-bzip-compressed-tar",
256 fastcgi.server = ( ".php" =>
258 ( "socket" => "$CURR_DIR/$WEB_TMP/php.socket",
259 "bin-path" => "$PHP_DIR/php-cgi -c $CURR_DIR/$WEB/php.ini"
266 cat > $WEB/php.ini <<EOF
267 session.save_path ='$CURR_DIR/$WEB_TMP'
273 # Start or restart daemon lighttpd. If restart, rewrite configuration files.
275 if test -f "$WEB_TMP/pid"; then
276 echo "Instance already running. Restarting..."
280 "$LIGHTTPD_DIR"/lighttpd -f "$WEB"/lighttpd.conf
282 if test $? -ne 0 ; then
283 echo "Could not execute http deamon lighttpd"
290 # Kill daemon lighttpd and removes files and folders associated.
292 test -f "$WEB_TMP/pid" && kill $(cat "$WEB_TMP/pid")
296 # Create the SQLite database of the MediaWiki. If the database file already
297 # exists, it will be deleted.
298 # This script should be runned from the directory where $FILES_FOLDER is
301 rm -f "$TMP/$DB_FILE"
303 echo "Generating the SQLite database file. It can take some time ..."
304 # Run the php script to generate the SQLite database file
306 php "$FILES_FOLDER/$DB_INSTALL_SCRIPT" $(basename "$DB_FILE" .sqlite) \
307 "$WIKI_ADMIN" "$WIKI_PASSW" "$TMP" "$PORT"
309 if [ ! -f "$TMP/$DB_FILE" ] ; then
310 error "Can't create database file $TMP/$DB_FILE. Try to run ./install-wiki.sh delete first."
313 # Copy the generated database file into the directory the
315 cp "$TMP/$DB_FILE" "$FILES_FOLDER" ||
316 error "Unable to copy $TMP/$DB_FILE to $FILES_FOLDER"
319 # Install a wiki in your web server directory.
321 if test $LIGHTTPD = "true" ; then
325 SERVER_ADDR=$SERVER_ADDR:$PORT
326 # In this part, we change directory to $TMP in order to download,
327 # unpack and copy the files of MediaWiki
329 mkdir -p "$WIKI_DIR_INST/$WIKI_DIR_NAME"
330 if [ ! -d "$WIKI_DIR_INST/$WIKI_DIR_NAME" ] ; then
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
337 if [ ! -f "$MW_VERSION.tar.gz" ] ; then
338 echo "Downloading $MW_VERSION sources ..."
339 wget "http://download.wikimedia.org/mediawiki/1.19/mediawiki-1.19.0.tar.gz" ||
340 error "Unable to download "\
341 "http://download.wikimedia.org/mediawiki/1.19/"\
342 "mediawiki-1.19.0.tar.gz. "\
343 "Please fix your connection and launch the script again."
344 echo "$MW_VERSION.tar.gz downloaded in `pwd`. "\
345 "You can delete it later if you want."
347 echo "Reusing existing $MW_VERSION.tar.gz downloaded in `pwd`."
349 archive_abs_path=$(pwd)/"$MW_VERSION.tar.gz"
350 cd "$WIKI_DIR_INST/$WIKI_DIR_NAME/" ||
351 error "can't cd to $WIKI_DIR_INST/$WIKI_DIR_NAME/"
352 tar xzf "$archive_abs_path" --strip-components=1 ||
353 error "Unable to extract WikiMedia's files from $archive_abs_path to "\
354 "$WIKI_DIR_INST/$WIKI_DIR_NAME"
359 # Copy the generic LocalSettings.php in the web server's directory
360 # And modify parameters according to the ones set at the top
362 # Note that LocalSettings.php is never modified.
363 if [ ! -f "$FILES_FOLDER/LocalSettings.php" ] ; then
364 error "Can't find $FILES_FOLDER/LocalSettings.php " \
365 "in the current folder. "\
366 "Please run the script inside its folder."
368 cp "$FILES_FOLDER/LocalSettings.php" \
369 "$FILES_FOLDER/LocalSettings-tmp.php" ||
370 error "Unable to copy $FILES_FOLDER/LocalSettings.php " \
371 "to $FILES_FOLDER/LocalSettings-tmp.php"
373 # Parse and set the LocalSettings file of the user according to the
374 # CONFIGURATION VARIABLES section at the beginning of this script
375 file_swap="$FILES_FOLDER/LocalSettings-swap.php"
376 sed "s,@WG_SCRIPT_PATH@,/$WIKI_DIR_NAME," \
377 "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
378 mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
379 sed "s,@WG_SERVER@,http://$SERVER_ADDR," \
380 "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
381 mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
382 sed "s,@WG_SQLITE_DATADIR@,$TMP," \
383 "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
384 mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
385 sed "s,@WG_SQLITE_DATAFILE@,$( basename $DB_FILE .sqlite)," \
386 "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
387 mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
389 mv "$FILES_FOLDER/LocalSettings-tmp.php" \
390 "$WIKI_DIR_INST/$WIKI_DIR_NAME/LocalSettings.php" ||
391 error "Unable to move $FILES_FOLDER/LocalSettings-tmp.php" \
392 "in $WIKI_DIR_INST/$WIKI_DIR_NAME"
393 echo "File $FILES_FOLDER/LocalSettings.php is set in" \
394 " $WIKI_DIR_INST/$WIKI_DIR_NAME"
396 echo "Your wiki has been installed. You can check it at
397 http://$SERVER_ADDR/$WIKI_DIR_NAME"
400 # Reset the database of the wiki and the password of the admin
402 # Warning: This function must be called only in a subdirectory of t/ directory
404 # Copy initial database of the wiki
405 if [ ! -f "../$FILES_FOLDER/$DB_FILE" ] ; then
406 error "Can't find ../$FILES_FOLDER/$DB_FILE in the current folder."
408 cp "../$FILES_FOLDER/$DB_FILE" "$TMP" ||
409 error "Can't copy ../$FILES_FOLDER/$DB_FILE in $TMP"
410 echo "File $FILES_FOLDER/$DB_FILE is set in $TMP"
413 # Delete the wiki created in the web server's directory and all its content
414 # saved in the database.
416 if test $LIGHTTPD = "true"; then
419 # Delete the wiki's directory.
420 rm -rf "$WIKI_DIR_INST/$WIKI_DIR_NAME" ||
421 error "Wiki's directory $WIKI_DIR_INST/" \
422 "$WIKI_DIR_NAME could not be deleted"
423 # Delete the wiki's SQLite database.
424 rm -f "$TMP/$DB_FILE" ||
425 error "Database $TMP/$DB_FILE could not be deleted."
428 # Delete the wiki's SQLite database
429 rm -f "$TMP/$DB_FILE" || error "Database $TMP/$DB_FILE could not be deleted."
430 rm -f "$FILES_FOLDER/$DB_FILE"
431 rm -rf "$TMP/$MW_VERSION"