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_BASE_URL
=http
://$SERVER_ADDR:$PORT
17 WIKI_URL
=$WIKI_BASE_URL/$WIKI_DIR_NAME
19 TEST_OUTPUT_DIRECTORY
=$
(pwd)
20 TEST_DIRECTORY
="$CURR_DIR"/..
/..
/..
/t
22 export TEST_OUTPUT_DIRECTORY TEST_DIRECTORY CURR_DIR
24 if test "$LIGHTTPD" = "false" ; then
27 WIKI_DIR_INST
="$CURR_DIR/$WEB_WWW"
31 "$CURR_DIR"/test-gitmw.pl upload_file
"$@"
35 "$CURR_DIR"/test-gitmw.pl get_page
"$@"
39 "$CURR_DIR"/test-gitmw.pl delete_page
"$@"
43 "$CURR_DIR"/test-gitmw.pl edit_page
"$@"
47 die_with_status
1 "$@"
58 # Check the preconditions to run git-remote-mediawiki's tests
59 test_check_precond
() {
60 if ! test_have_prereq PERL
62 skip_all
='skipping gateway git-mw tests, perl not available'
66 GIT_EXEC_PATH
=$
(cd "$(dirname "$0")" && cd "../.." && pwd)
67 PATH
="$GIT_EXEC_PATH"'/bin-wrapper:'"$PATH"
69 if ! test -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 should 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 daemon lighttpd"
290 # Kill daemon lighttpd and removes files and folders associated.
292 test -f "$WEB_TMP/pid" && kill $
(cat "$WEB_TMP/pid")
297 "$FILES_FOLDER_DB"/* || error
"Couldn't delete $FILES_FOLDER_DB/"
300 wiki_delete_db_backup
() {
302 "$FILES_FOLDER_POST_INSTALL_DB"/* || error
"Couldn't delete $FILES_FOLDER_POST_INSTALL_DB/"
305 # Install MediaWiki using its install.php script. If the database file
306 # already exists, it will be deleted.
307 install_mediawiki
() {
309 localsettings
="$WIKI_DIR_INST/$WIKI_DIR_NAME/LocalSettings.php"
310 if test -f "$localsettings"
312 error
"We already installed the wiki, since $localsettings exists" \
313 "perhaps you wanted to run 'delete' first?"
317 wiki_delete_db_backup
319 "$FILES_FOLDER_DB/" \
320 "$FILES_FOLDER_POST_INSTALL_DB/"
322 install_script
="$WIKI_DIR_INST/$WIKI_DIR_NAME/maintenance/install.php"
323 echo "Installing MediaWiki using $install_script. This may take some time ..."
325 php
"$WIKI_DIR_INST/$WIKI_DIR_NAME/maintenance/install.php" \
326 --server $WIKI_BASE_URL \
330 --dbpath $PWD/$FILES_FOLDER_DB/ \
331 --pass "$WIKI_PASSW" \
334 error
"Couldn't run $install_script, see errors above. Try to run ./install-wiki.sh delete first."
335 cat <<-'EOF' >>$localsettings
336 # Custom settings added by test-gitmw-lib.sh
338 # Uploading text files is needed for
339 # t9363-mw-to-git-export-import.sh
340 $wgEnableUploads = true;
341 $wgFileExtensions[] = 'txt';
344 # Copy the initially generated database file into our backup
346 cp -R "$FILES_FOLDER_DB/"* "$FILES_FOLDER_POST_INSTALL_DB/" ||
347 error
"Unable to copy $FILES_FOLDER_DB/* to $FILES_FOLDER_POST_INSTALL_DB/*"
350 # Install a wiki in your web server directory.
352 if test $LIGHTTPD = "true" ; then
356 # In this part, we change directory to $TMP in order to download,
357 # unpack and copy the files of MediaWiki
359 mkdir
-p "$WIKI_DIR_INST/$WIKI_DIR_NAME"
360 if ! test -d "$WIKI_DIR_INST/$WIKI_DIR_NAME"
362 error
"Folder $WIKI_DIR_INST/$WIKI_DIR_NAME doesn't exist.
363 Please create it and launch the script again."
366 # Fetch MediaWiki's archive if not already present in the
368 mkdir
-p "$FILES_FOLDER_DOWNLOAD"
369 MW_FILENAME
="mediawiki-$MW_VERSION_MAJOR.$MW_VERSION_MINOR.tar.gz"
370 cd "$FILES_FOLDER_DOWNLOAD"
371 if ! test -f $MW_FILENAME
373 echo "Downloading $MW_VERSION_MAJOR.$MW_VERSION_MINOR sources ..."
374 wget
"http://download.wikimedia.org/mediawiki/$MW_VERSION_MAJOR/$MW_FILENAME" ||
375 error
"Unable to download "\
376 "http://download.wikimedia.org/mediawiki/$MW_VERSION_MAJOR/"\
378 "Please fix your connection and launch the script again."
379 echo "$MW_FILENAME downloaded in $(pwd)/;" \
380 "you can delete it later if you want."
382 echo "Reusing existing $MW_FILENAME downloaded in $(pwd)/"
384 archive_abs_path
=$
(pwd)/$MW_FILENAME
385 cd "$WIKI_DIR_INST/$WIKI_DIR_NAME/" ||
386 error
"can't cd to $WIKI_DIR_INST/$WIKI_DIR_NAME/"
387 tar xzf
"$archive_abs_path" --strip-components=1 ||
388 error
"Unable to extract WikiMedia's files from $archive_abs_path to "\
389 "$WIKI_DIR_INST/$WIKI_DIR_NAME"
391 echo Extracted
in "$WIKI_DIR_INST/$WIKI_DIR_NAME"
395 echo "Your wiki has been installed. You can check it at
399 # Reset the database of the wiki and the password of the admin
401 # Warning: This function must be called only in a subdirectory of t/ directory
403 # Copy initial database of the wiki
404 if ! test -d "../$FILES_FOLDER_DB"
406 error
"No wiki database at ../$FILES_FOLDER_DB, not installed yet?"
408 if ! test -d "../$FILES_FOLDER_POST_INSTALL_DB"
410 error
"No wiki backup database at ../$FILES_FOLDER_POST_INSTALL_DB, failed installation?"
413 cp -R "../$FILES_FOLDER_POST_INSTALL_DB/"* "../$FILES_FOLDER_DB/" ||
414 error
"Can't copy ../$FILES_FOLDER_POST_INSTALL_DB/* to ../$FILES_FOLDER_DB/*"
415 echo "File $FILES_FOLDER_DB/* has been reset"
418 # Delete the wiki created in the web server's directory and all its content
419 # saved in the database.
421 if test $LIGHTTPD = "true"; then
425 # Delete the wiki's directory.
426 rm -rf "$WIKI_DIR_INST/$WIKI_DIR_NAME" ||
427 error
"Wiki's directory $WIKI_DIR_INST/" \
428 "$WIKI_DIR_NAME could not be deleted"
431 wiki_delete_db_backup