13
14
. ./test.config
15
16
-WIKI_URL=http://"$SERVER_ADDR:$PORT/$WIKI_DIR_NAME"
16
+WIKI_BASE_URL=http://$SERVER_ADDR:$PORT
17
+WIKI_URL=$WIKI_BASE_URL/$WIKI_DIR_NAME
18
CURR_DIR=$(pwd)
19
TEST_OUTPUT_DIRECTORY=$(pwd)
20
TEST_DIRECTORY="$CURR_DIR"/../../../t
292
test -f "$WEB_TMP/pid" && kill $(cat "$WEB_TMP/pid")
293
}
294
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
297
-# located.
298
-create_db () {
299
- rm -f "$TMP/$DB_FILE"
295
+wiki_delete_db () {
296
+ rm -rf \
297
+ "$FILES_FOLDER_DB"/* || error "Couldn't delete $FILES_FOLDER_DB/"
298
+}
299
+
300
+wiki_delete_db_backup () {
301
+ rm -rf \
302
+ "$FILES_FOLDER_POST_INSTALL_DB"/* || error "Couldn't delete $FILES_FOLDER_POST_INSTALL_DB/"
303
+}
304
301
- echo "Generating the SQLite database file. It can take some time ..."
302
- # Run the php script to generate the SQLite database file
303
- # with cURL calls.
304
- php "$FILES_FOLDER/$DB_INSTALL_SCRIPT" $(basename "$DB_FILE" .sqlite) \
305
- "$WIKI_ADMIN" "$WIKI_PASSW" "$TMP" "$PORT"
305
+# Install MediaWiki using its install.php script. If the database file
306
+# already exists, it will be deleted.
307
+install_mediawiki () {
308
307
- if ! test -f "$TMP/$DB_FILE"
309
+ localsettings="$WIKI_DIR_INST/$WIKI_DIR_NAME/LocalSettings.php"
310
+ if test -f "$localsettings"
311
then
309
- error "Can't create database file $TMP/$DB_FILE. Try to run ./install-wiki.sh delete first."
312
+ error "We already installed the wiki, since $localsettings exists" \
313
+ "perhaps you wanted to run 'delete' first?"
314
fi
315
312
- # Copy the generated database file into the directory the
313
- # user indicated.
314
- cp "$TMP/$DB_FILE" "$FILES_FOLDER" ||
315
- error "Unable to copy $TMP/$DB_FILE to $FILES_FOLDER"
316
+ wiki_delete_db
317
+ wiki_delete_db_backup
318
+ mkdir \
319
+ "$FILES_FOLDER_DB/" \
320
+ "$FILES_FOLDER_POST_INSTALL_DB/"
321
+
322
+ install_script="$WIKI_DIR_INST/$WIKI_DIR_NAME/maintenance/install.php"
323
+ echo "Installing MediaWiki using $install_script. This may take some time ..."
324
+
325
+ php "$WIKI_DIR_INST/$WIKI_DIR_NAME/maintenance/install.php" \
326
+ --server $WIKI_BASE_URL \
327
+ --scriptpath /wiki \
328
+ --lang en \
329
+ --dbtype sqlite \
330
+ --dbpath $PWD/$FILES_FOLDER_DB/ \
331
+ --pass "$WIKI_PASSW" \
332
+ Git-MediaWiki-Test \
333
+ "$WIKI_ADMIN" ||
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
337
+#
338
+# Uploading text files is needed for
339
+# t9363-mw-to-git-export-import.sh
340
+$wgEnableUploads = true;
341
+$wgFileExtensions[] = 'txt';
342
+EOF
343
+
344
+ # Copy the initially generated database file into our backup
345
+ # folder
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/*"
348
}
349
350
# Install a wiki in your web server directory.
353
start_lighttpd
354
fi
355
324
- SERVER_ADDR=$SERVER_ADDR:$PORT
356
# In this part, we change directory to $TMP in order to download,
357
# unpack and copy the files of MediaWiki
358
(
363
Please create it and launch the script again."
364
fi
365
335
- # Fetch MediaWiki's archive if not already present in the TMP directory
366
+ # Fetch MediaWiki's archive if not already present in the
367
+ # download directory
368
+ mkdir -p "$FILES_FOLDER_DOWNLOAD"
369
MW_FILENAME="mediawiki-$MW_VERSION_MAJOR.$MW_VERSION_MINOR.tar.gz"
337
- cd "$TMP"
370
+ cd "$FILES_FOLDER_DOWNLOAD"
371
if ! test -f $MW_FILENAME
372
then
373
echo "Downloading $MW_VERSION_MAJOR.$MW_VERSION_MINOR sources ..."
388
error "Unable to extract WikiMedia's files from $archive_abs_path to "\
389
"$WIKI_DIR_INST/$WIKI_DIR_NAME"
390
) || exit 1
391
+ echo Extracted in "$WIKI_DIR_INST/$WIKI_DIR_NAME"
392
359
- create_db
360
-
361
- # Copy the generic LocalSettings.php in the web server's directory
362
- # And modify parameters according to the ones set at the top
363
- # of this script.
364
- # Note that LocalSettings.php is never modified.
365
- if ! test -f "$FILES_FOLDER/LocalSettings.php"
366
- then
367
- error "Can't find $FILES_FOLDER/LocalSettings.php " \
368
- "in the current folder. "\
369
- "Please run the script inside its folder."
370
- fi
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"
375
-
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"
391
-
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"
393
+ install_mediawiki
394
395
echo "Your wiki has been installed. You can check it at
400
- http://$SERVER_ADDR/$WIKI_DIR_NAME"
396
+ $WIKI_URL"
397
}
398
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
402
wiki_reset () {
403
# Copy initial database of the wiki
408
- if ! test -f "../$FILES_FOLDER/$DB_FILE"
404
+ if ! test -d "../$FILES_FOLDER_DB"
405
then
410
- error "Can't find ../$FILES_FOLDER/$DB_FILE in the current folder."
406
+ error "No wiki database at ../$FILES_FOLDER_DB, not installed yet?"
407
fi
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"
408
+ if ! test -d "../$FILES_FOLDER_POST_INSTALL_DB"
409
+ then
410
+ error "No wiki backup database at ../$FILES_FOLDER_POST_INSTALL_DB, failed installation?"
411
+ fi
412
+ wiki_delete_db
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"
416
}
417
418
# Delete the wiki created in the web server's directory and all its content
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"
428
- # Delete the wiki's SQLite database.
429
- rm -f "$TMP/$DB_FILE" ||
430
- error "Database $TMP/$DB_FILE could not be deleted."
429
fi
432
-
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"
430
+ wiki_delete_db
431
+ wiki_delete_db_backup
432
}