From 89c467d0ba7770f092bad8d21e0a62ea1399cc63 Mon Sep 17 00:00:00 2001 From: Robbie Ferguson Date: Thu, 21 Aug 2025 18:21:30 +0000 Subject: [PATCH] Make installer work with mountpoint /var/www/html, backup pre-existing files. --- installer.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/installer.sh b/installer.sh index 48f8e56..a921406 100755 --- a/installer.sh +++ b/installer.sh @@ -73,9 +73,23 @@ else exit 1 fi +if [[ -d "$MW_DIR" && "$(ls -A "$MW_DIR")" ]]; then + TIMESTAMP=$(date +%Y%m%d-%H%M%S) + ARCHIVE_DIR="${MW_DIR}~old-${TIMESTAMP}" + echo "[*] Existing files detected in $MW_DIR." + + mkdir -p "$ARCHIVE_DIR" + shopt -s dotglob nullglob + mv "$MW_DIR"/* "$ARCHIVE_DIR"/ 2>/dev/null || true + shopt -u dotglob nullglob + + echo "[*] Moved existing contents to $ARCHIVE_DIR" +fi +if [[ ! -e "$MW_DIR" ]]; then + mkdir -p "$MW_DIR" +fi tar -xzf "mediawiki-${MW_VERSION}.tar.gz" -rm -rf "$MW_DIR" -mv "mediawiki-${MW_VERSION}" "$MW_DIR" +cp -a "mediawiki-${MW_VERSION}/." "$MW_DIR/" ### AUTO-CONFIGURE MEDIAWIKI ### echo "[*] Generating LocalSettings.php..."