#!/bin/bash ############################################################################### #The MIT License (MIT)######################################################### ############################################################################### #Copyright (c) 2015 ROUTE-TO-PA CONSORTIUM##################################### ############################################################################### #Permission is hereby granted, free of charge, to any person obtaining a copy## #of this software and associated documentation files (the "Software"), to deal# #in the Software without restriction, including without limitation the rights## #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell##### #copies of the Software, and to permit persons to whom the Software is######### #furnished to do so, subject to the following conditions:###################### ############################################################################### #The above copyright notice and this permission notice shall be included in#### #all copies or substantial portions of the Software.########################### ############################################################################### #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR#### #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,###### #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE### #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER######## #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,# #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN##### #THE SOFTWARE.################################################################# ############################################################################### ############################################################################### #SPOD INSTALLATION SCRIPT###################################################### #FIRST VERSION 29/09/2015###################################################### ############################################################################### ################OXWALL CONFIGURATION DATA###################################### CONFIG0=" > /var/www/ow_includes/config.php service apache2 restart wget -q -O /dev/null http://localhost/ rm -f /var/www/ow_includes/config.php echo $CONFIG0$HOSTNAMESPOD$CONFIG1$CONFIG3 >> /var/www/ow_includes/config.php CRONCHECK=$(crontab -l); if [[ $CRONCHECK == *"http://localhost/ow_cron/run.php"* ]]; then echo "Cron job already exists"; else crontab -l | { cat; echo "* * * * * wget -q -O /dev/null http://localhost/ow_cron/run.php"; } | crontab - fi ;; "uninstall") if [ -z "$MYSQLUSERNAME" ] || [ -z "$MYSQLPASSWORD" ] ; then echo "You must specify the mysql password and username to unistall SPOD." echo " sudo ./spod-manager.sh -a uninstall -m user -n password" exit -2 fi mysql -u $MYSQLUSERNAME -p$MYSQLPASSWORD --host=$MYSQLHOST -e "drop database oxwall;" rm -rf /var/www/* rm -rf /var/www/.[^.]* crontab -l | sed '/http:\/\/localhost\/ow_cron\/run\.php/d' | crontab - ;; "backup") if [ -z "$MYSQLUSERNAME" ] || [ -z "$MYSQLPASSWORD" ] ; then echo "You must specify the mysql password and username to unistall SPOD." exit -2 fi service apache2 stop DATEDIR=$(date +%Y-%m-%d-%N) IP=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}') mkdir -p $BACKUPDIR/$DATEDIR mysqldump -u $MYSQLUSERNAME -p$MYSQLPASSWORD --host=$MYSQLHOST oxwall | gzip > $BACKUPDIR/$DATEDIR/db_backup_spod.sql.gz mkdir $BACKUPDIR/$DATEDIR/var cp -r /var/www $BACKUPDIR/$DATEDIR/var service apache2 start ;; "restoredb") if [ -z "$MYSQLUSERNAME" ] || [ -z "$MYSQLPASSWORD" ] || [ -z "$DB" ]; then echo "You must specify the mysql password and username, db dump path to restore SPOD." exit -2 fi service apache2 stop mysql -u $MYSQLUSERNAME -p$MYSQLPASSWORD --host=$MYSQLHOST -e "drop database oxwall;" mysql -u $MYSQLUSERNAME -p$MYSQLPASSWORD --host=$MYSQLHOST -e "create database if not exists oxwall;" mysql -u $MYSQLUSERNAME -p$MYSQLPASSWORD --host=$MYSQLHOST --database=oxwall < $DB service apache2 start ;; "restoreall") if [ -z "$MYSQLUSERNAME" ] || [ -z "$MYSQLPASSWORD" ] || [ -z "$SPODWWW" ] || [ -z "$GITUSER" ] || [ -z "$GITPASSWORD" ] || [ -z "$GITEMAIL" ] || [ -z "$GITSPOD" ]; then echo "You must specify the mysql password and username, SPOD backup dir and DB dump path to restore SPOD." exit -2 fi service apache2 stop mysql -u $MYSQLUSERNAME -p$MYSQLPASSWORD --host=$MYSQLHOST -e "drop database oxwall;" mysql -u $MYSQLUSERNAME -p$MYSQLPASSWORD --host=$MYSQLHOST -e "create database if not exists oxwall;" mysql -u $MYSQLUSERNAME -p$MYSQLPASSWORD --host=$MYSQLHOST --database=oxwall < $DB rm -rf /var/www/* rm -rf /var/www/.[^.]* cp -r $SPODWWW /var cd /var/www git remote rm origin git init git remote add origin http://$GITUSER:$GITPASSWORD@$GITSPOD/isislab/spod-core.git cd /var/www/ow_plugins git remote rm origin git init git remote add origin http://$GITUSER:$GITPASSWORD@$GITSPOD/isislab/spod-plugins.git cd /var/www/ow_themes git remote rm origin git init git remote add origin http://$GITUSER:$GITPASSWORD@$GITSPOD/isislab/spod-themes.git chown www-data:www-data -R /var/www service apache2 start ;; "update") if [ -z "$GITUSER" ] || [ -z "$GITEMAIL" ] || [ -z "$GITPASSWORD" ] || [ -z "$HOSTNAMESPOD" ]; then echo "You must specify the SPOD git credentials." exit -2 fi git config --global user.name "$GITUSER" git config --global user.email "$GITEMAIL" if [ -x /var/www/.git ] && [ -x /var/www/ow_plugins ] && [ -x /var/www/ow_themes ]; then cd /var/www git pull origin master cd /var/www/ow_plugins git pull origin master cd /var/www/ow_themes git pull origin master service apache2 restart wget -q -O /dev/null http://localhost/ow_cron/run.php rm -f /var/www/ow_includes/config.php echo $CONFIG0$HOSTNAMESPOD$CONFIG1$CONFIG2 >> /var/www/ow_includes/config.php service apache2 restart wget -q -O /dev/null http://localhost/ rm -f /var/www/ow_includes/config.php echo $CONFIG0$HOSTNAMESPOD$CONFIG1$CONFIG3 >> /var/www/ow_includes/config.php chown www-data:www-data -R /var/www service apache2 restart else echo "Your SPOD installation is corrupt, please uninstall and istall it again. Your database will be erased." exit -2 fi ;; *) echo "No valid action found."; exit -1; ;; esac ############################################################################################## ############################################################################################## ############################################################################################## ############################################################################################## ############################################################################################## ############################################################################################## ##############################################################################################