Skip to content

Instantly share code, notes, and snippets.

@BNoiZe
Last active August 29, 2015 14:01
Show Gist options
  • Save BNoiZe/621ab1925a939d798379 to your computer and use it in GitHub Desktop.
Save BNoiZe/621ab1925a939d798379 to your computer and use it in GitHub Desktop.
Froxlor Update Script
#!/bin/bash
# Define your settings here
froxlor_dir="/var/www/froxlor"
backup_dir="/var/backups/hetznerftp/froxlor"
### DON'T CHANGE ANYTHING BELOW ###
now=$(date +"%Y_%m_%d_%H_%M")
if [ $# == 0 ]; then
force="no"
else
force=$1
fi
# FUNCTIONS #
function okay () {
echo -en "\r"
echo -e "[ \e[0;32mOK\e[0m ]"
}
echo "*** Froxlor Update Script 1.2 ***"
cd $froxlor_dir
# Get local and remote version
local_version=$(php -r 'include "lib/tables.inc.php"; echo $version;')
wget https://raw.githubusercontent.com/Froxlor/Froxlor/master/lib/tables.inc.php -O /tmp/froxlor_tables.inc.php --quiet
remote_version=$(php -r 'include "/tmp/froxlor_tables.inc.php"; echo $version;')
echo "Current froxlor version: $local_version"
# Compare version on github
if [ $force != "--force" ] && [ $local_version != $remote_version ]; then
echo "Remote version ($remote_version) is newer than the installed one and requires manual update steps. Use --force to start the update."
elif [ $local_version != $remote_version ]; then
echo "Updating froxlor files to version $remote_version"
fi
# Read userdata.inc.php
froxlor_db=$(php -r 'include "lib/userdata.inc.php"; echo $sql["db"];')
db_host=$(php -r 'include "lib/userdata.inc.php"; echo $sql["host"];')
db_root_user=$(php -r 'include "lib/userdata.inc.php"; echo $sql_root[0]["user"];')
db_root_pw=$(php -r 'include "lib/userdata.inc.php"; echo $sql_root[0]["password"];')
# Check if we need to update before we do anything
git fetch origin > /dev/null
reslog=$(git log HEAD..origin/master --oneline)
if [[ "${reslog}" != "" ]] || [ $force == "--force" ]; then
if [ $force == "--force" ]; then
echo "Forcing update."
else
echo "There are updates on Github. Applying them now."
fi
echo -n "[ .. ] Backing up database to ${backup_dir}/database_${now}.sql"
mysqldump -u $db_root_user -p$db_root_pw $froxlor_db > $backup_dir/database_$now.sql
okay
echo -n "[ .. ] Backing up userdata.inc.php"
cp $froxlor_dir/lib/userdata.inc.php /tmp/
okay
echo -n "[ .. ] Updating froxlor from Github"
git merge origin/master > /dev/null
okay
echo -n "[ .. ] Moving back userdata.inc.php"
mv /tmp/userdata.inc.php $froxlor_dir/lib/
okay
echo -n "[ .. ] Fixing permissions"
chown -R froxlorlocal:froxlorlocal $froxlor_dir
okay
echo "Update successfull."
else
echo "Already up-to-date."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment