All Downloads are FREE. Search and download functionalities are using the official Maven repository.

refcodes-batch.1.0.2.source-code.upgrade-mediawiki-version.job Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
#!/bin/bash

if [[ $HELP = y ]] ; then
	echo "The switch \"-j $JOB\" uses a given configuration to                            " >&2
	echo "upgrade a given Mediawiki based website to the Medaiwiki version as specified in" >&2
	echo "the \"MEDIAWIKI_VERSION\" property of your config file.                         " >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
fi

. $SCRIPT_DIR/validate-website-config.job
. $SCRIPT_DIR/validate-mediawiki-config.job

exitOnConfigOff "MEDIAWIKI"
exitOnConfigOff "WEBSITE"

LOCAL_CONFIG_NAME="LocalConfig.php"
CONFIG_NAME="config"
MW_CONFIG_NAME="mw-config"
IMAGES_NAME="images"
FAVICON_NAME="favicon.ico"
MEDIAWIKI_RELEASE_NOTES_FILE="$MEDIAWIKI_DIR/RELEASE-NOTES"

if [[ $VERBOSE = y ]] ; then
	echo "Upgrading the Mediawiki version for \"$WEBSITE_DOMAIN_NAME\" to Mediawiki $MEDIAWIKI_VERSION ... " >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
fi

if [[ $VERBOSE = y ]] ; then
	echo "Assuming the path \"$WEBSITE_DIR\" to exist ..." >&2
	echo "Assuming the path \"$MEDIAWIKI_DIR\" to exist ..." >&2
	echo "Assuming the path \"$MEDIAWIKI_RELEASE_NOTES_FILE\" to exist ..." >&2
fi

exitOnMissingVariablePath "WEBSITE_DIR"
exitOnMissingPropertyPath "MEDIAWIKI_DIR"
exitOnMissingVariablePath "MEDIAWIKI_RELEASE_NOTES_FILE"

if ! grep -q "== MediaWiki $MEDIAWIKI_VERSION" $MEDIAWIKI_RELEASE_NOTES_FILE ; then
	showError "Did not detect a Mediawiki $MEDIAWIKI_VERSION.X in path \"$MEDIAWIKI_DIR\" !!!"
	exit $EXIT_FAILURE
fi

if [[ $VERBOSE = y ]] ; then
	echo "Deleting obsolete or outdated files at \"$WEBSITE_DIR\"... " >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
fi

PROCESSED=n

FILELIST=$(ls -1 $WEBSITE_DIR)
exitOnError "Unable to get file list from \"$WEBSITE_DIR\" !!!"

for FILENAME in $FILELIST ; do

	PROCESSED=y

	WEBSITE_FILE="$WEBSITE_DIR/$FILENAME"
	DELETE=y

	if [[ "$FILENAME" = "$LOCAL_CONFIG_NAME" ]] ; then
		DELETE=n
	fi

	if [[ "$FILENAME" = "$FAVICON_NAME" ]] ; then
		DELETE=n
	fi

	if [[ "$FILENAME" = "$IMAGES_NAME" ]] ; then
		DELETE=n
	fi

	if [[ $DELETE = n ]] ; then
		if [[ $VERBOSE = y ]] ; then
			echo "% Ignoring: \"$WEBSITE_FILE\" ..." >&2
		fi
	fi

	if [[ $DELETE = y ]] ; then
		if [ ! -L $WEBSITE_FILE ] && [ ! -e $WEBSITE_FILE ] ; then
			if [[ $VERBOSE = y ]] ; then
				echo "? Deleting: \"$WEBSITE_FILE\" ... (skipped)" >&2
			fi
		fi
		if [ -L $WEBSITE_FILE ] || [ -e $WEBSITE_FILE ] ; then
			if [[ $VERBOSE = y ]] ; then
				echo "- Deleting: \"$WEBSITE_FILE\" ..." >&2
			fi
			if [ ! -d $WEBSITE_FILE ] ; then
				rm $WEBSITE_FILE
				exitOnError "Unable to remove \"$WEBSITE_FILE\" !!!"
			fi
			if [ -d $WEBSITE_FILE ] ; then
				rm -R $WEBSITE_FILE
				exitOnError "Unable to remove \"$WEBSITE_FILE\" !!!"
			fi
		fi
	fi
done
if [[ $PROCESSED = y ]] ; then
	if [[ $VERBOSE = y ]] ; then
		# echo "--------------------------------------------------------------------------------" >&2
		logSeparator
	fi
fi
if [[ $PROCESSED = n ]] ; then
	if [[ $VERBOSE = y ]] ; then
		echo "(none found to delete)" >&2
		# echo "--------------------------------------------------------------------------------" >&2
		logSeparator
	fi
fi


if [[ $VERBOSE = y ]] ; then
	echo "Copying or linking files from \"$MEDIAWIKI_DIR\" to \"$WEBSITE_DIR\"... " >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
fi

PROCESSED=n

FILELIST=$(ls -1 $MEDIAWIKI_DIR)
exitOnError "Unable to get file list from \"$MEDIAWIKI_DIR\" !!!"

for FILENAME in $FILELIST ; do

	PROCESSED=y

	MEDIAWIKI_FILE="$MEDIAWIKI_DIR/$FILENAME"
	WEBSITE_FILE="$WEBSITE_DIR/$FILENAME"

	COPY=n
	LINK=y

	if [[ "$FILENAME" = "$LOCAL_CONFIG_NAME" ]] ; then
		COPY=n
		LINK=n
	fi

	if [[ "$FILENAME" = "$FAVICON_NAME" ]] ; then
		COPY=n
		LINK=n
	fi

	if [[ "$FILENAME" = "$IMAGES_NAME" ]] ; then
		COPY=y
		LINK=n
	fi

	if [[ "$FILENAME" = "$CONFIG_NAME" ]] ; then
		COPY=y
		LINK=n
	fi

if [[ "$FILENAME" = "$MW_CONFIG_NAME" ]] ; then
		COPY=y
		LINK=n
	fi

	if [[ $COPY = n ]] && [[ $LINK = n ]] ; then
		if [[ $VERBOSE = y ]] ; then
			echo "% Ignoring: \"$WEBSITE_FILE\" ..." >&2
		fi
	fi

	if [[ $COPY = y ]] ; then
		if [[ $VERBOSE = y ]] ; then
			echo "+  Copying: \"$WEBSITE_FILE\" ..." >&2
		fi
		cp -aR $MEDIAWIKI_FILE $WEBSITE_FILE
		exitOnError "Unable to copy \"$MEDIAWIKI_FILE\" to \"$WEBSITE_FILE\" !!!"
	fi

	if [[ $LINK = y ]] ; then
		if [[ $VERBOSE = y ]] ; then
			echo "*  Linking: \"$WEBSITE_FILE\" ..." >&2
		fi
		ln -s $MEDIAWIKI_FILE $WEBSITE_FILE
		exitOnError "Unable link \"$MEDIAWIKI_FILE\" to \"$WEBSITE_FILE\" !!!"
	fi
done
if [[ $PROCESSED = y ]] ; then
	if [[ $VERBOSE = y ]] ; then
		# echo "--------------------------------------------------------------------------------" >&2
		logSeparator
	fi
fi
if [[ $PROCESSED = n ]] ; then
	showError "Warning: No files found at \"$MEDIAWIKI_DIR\" to link or copy to \"$WEBSITE_DIR\"."
	exit $EXIT_ERROR
fi

showSuccess "\"$WEBSITE_DOMAIN_NAME\" upgraded to Mediawiki $MEDIAWIKI_VERSION.x !"




© 2015 - 2024 Weber Informatics LLC | Privacy Policy