Skip to content

Instantly share code, notes, and snippets.

@BNoiZe
Last active December 30, 2015 06:09
Show Gist options
  • Save BNoiZe/7787346 to your computer and use it in GitHub Desktop.
Save BNoiZe/7787346 to your computer and use it in GitHub Desktop.
A simple script to update froxlor from git
#!/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.0 ***"
cd $froxlor_dir
# 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