Skip to content

Instantly share code, notes, and snippets.

@derhofbauer
Created November 2, 2016 15:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save derhofbauer/5547b16e7a84957bd486fc163b7c705e to your computer and use it in GitHub Desktop.
Save derhofbauer/5547b16e7a84957bd486fc163b7c705e to your computer and use it in GitHub Desktop.
Bash Moodle Upgrade Script
#!/bin/sh
echo "This script updates your moodle installation."
echo "You will need a few pieces of information to complete this process."
echo ""
echo "Warning: This will disable Web-Access to the moodle installation!"
echo "Make sure nobody is logged in at the moment or activate maintenance mode manually so no data is lost."
echo ""
echo ""
echo -n "Enter Moodle Domain and press [ENTER]: "
read MOODLE_DOMAIN
echo ""
php moodle/admin/cli/maintenance.php --enable
echo ""
echo ""
echo "###################"
echo "# Database Backup #"
echo "###################"
echo ""
echo -n "Enter Database name and press [ENTER]: "
read DB_NAME
echo -n "Enter Database user and press [ENTER]: "
read DB_USER
echo -n "Enter Database password and press [ENTER]: "
read DB_PASS
echo ""
echo "Creating database dump ..."
mysqldump -u $DB_USER -p$DB_PASS -C -Q -e --create-options $DB_NAME > dump.sql
echo "Database dump created successfully!"
echo ""
echo ""
echo "###########################"
echo "# Downloading new Version #"
echo "###########################"
echo -n "Enter Moodle direct Download URL to .tgz file and press [ENTER]: "
read DOWNLOAD_URL
# echo -n "Enter Moodle MD5-Sum and press [ENTER]: "
# read CHECKSUM
wget $DOWNLOAD_URL -O moodle-latest.tgz
echo ""
echo "File Download successful!"
echo ""
echo ""
echo "######################"
echo "# File & Data Backup #"
echo "######################"
echo ""
echo "backing up files ..."
tar czf moodle.tgz moodle
echo "backing up data ..."
tar czf moodle_data.tgz moodle_data
echo ""
echo ""
echo "#############"
echo "# Upgrading #"
echo "#############"
echo ""
echo "This will take a while."
echo ""
echo "moving old files ..."
mv moodle moodle.backup
echo "unpacking new version ..."
tar xzf moodle-latest.tgz
echo "copying config and wibs theme ..."
cp moodle.backup/config.php moodle
if [ -d "moodle.backup/theme/<yourTheme>/" ]; then
cp -pr moodle.backup/theme/<yourTheme>/ moodle/theme/
fi
if [ -d "moodle.backup/mod/<yourMod>/" ]; then
cp -pr moodle.backup/mod/<yourMod>/ moodle/mod/
fi
echo "fixing file permissions ..."
chmod 740 moodle/admin/cli/cron.php
chown www-data:www-data -R moodle moodle_data
echo "uprading ..."
php moodle/admin/cli/upgrade.php
echo "disabling maintenance mode ..."
php moodle/admin/cli/maintenance.php --disable
echo "done!"
echo ""
echo ""
echo "Open your Moodle installation in your Browser and check if everything works as expected."
echo "Maybe you need to reinstall some mods because the source of those mods have not been copied."
echo ""
echo -n "Does everything work as expected? [Y/n]: "
read WORKS
if [ "$WORKS" = "Y" ]; then
echo -n "Cleanup? [Y/n]: "
read CLEANUP
if [ "$CLEANUP" = "Y" ]; then
rm -R moodle.backup/ *.tgz *.md5 *.sql
echo "finished!"
fi
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment