Created
December 20, 2019 11:29
-
-
Save nielsnuebel/396eaea9de7e66a958ed0d8cdd91e2bf to your computer and use it in GitHub Desktop.
reinstall.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BACKUP="/var/www/vhosts/PATH/scripts/kicktemp/kicktemp.sql" | |
BACKUPCONFIG="/var/www/vhosts/PATH/scripts/kicktemp/configuration.php" | |
BACKUPZIP="/var/www/vhosts/PATH/scripts/kicktemp/backup.zip" | |
DELETDIR="/var/www/vhosts/PATH/demo.kicktemp.com/" | |
CONFIG="/var/www/vhosts/PATH/demo.kicktemp.com/configuration.php" | |
REMOVEADMINDIR=("com_installer/" "com_media/"); | |
REMOVESITEDIR=("com_users/"); | |
OWNER="USER" | |
GROUP="GROUP" | |
MUSER="DBUSER" | |
MPASS="DBPASS" | |
MDB="DATABASE" | |
MHOST="localhost" | |
# Detect paths | |
ll | |
AWK=$(which awk) | |
GREP=$(which grep) | |
if [ -f $BACKUPZIP ]; | |
then | |
echo "Backup $BACKUPZIP exists" | |
else | |
echo "Backup $BACKUPZIP does not exists" | |
exit 1 | |
fi | |
# make sure we can connect to server | |
$MYSQL -u $MUSER -p$MPASS -h $MHOST -e "use $MDB" &>/dev/null | |
if [ $? -ne 0 ] | |
then | |
echo "Error - Cannot connect to mysql server using given username, password or database does not exits!" | |
exit 2 | |
fi | |
if [ -f $BACKUP ]; | |
then | |
echo "MySQL Backup $BACKUP exists" | |
else | |
echo "MySQL Backup $BACKUP does not exists" | |
exit 3 | |
fi | |
if [ -d $DELETDIR ]; | |
then | |
echo "Webdir $DELETDIR exists" | |
else | |
echo "Webdir $DELETDIR does not exists" | |
exit 5 | |
fi | |
echo "Webdir delet" | |
rm -Rf $DELETDIR* | |
echo "Copy Backup to Webdir" | |
unzip -d $DELETDIR -o $BACKUPZIP | |
echo "Remove Democonfig" | |
rm -f $CONFIG | |
echo "Establish Democonfig" | |
cp -f $BACKUPCONFIG $DELETDIR | |
echo "Alter owner and group" | |
chgrp $GROUP -R $DELETDIR* | |
chown $OWNER -R $DELETDIR* | |
echo "Alter File and Directory permissions" | |
find $DELETDIR -type f -print | xargs chmod 644 | |
find $DELETDIR -type d -print | xargs chmod 755 | |
echo "Alter configuration.php permsissons" | |
chmod 444 $CONFIG | |
TABLES=$($MYSQL -u $MUSER -p$MPASS -h $MHOST $MDB -e 'show tables' | $AWK '{ print $1}' | $GREP -v '^Tables' ) | |
# make sure tables exits | |
if [ "$TABLES" == "" ] | |
then | |
echo "Error - No table found in $MDB database!" | |
exit 3 | |
fi | |
# let us do it | |
for t in $TABLES | |
do | |
echo "Deleting $t table from $MDB database..." | |
$MYSQL -u $MUSER -p$MPASS -h $MHOST $MDB -e "drop table $t" | |
done | |
$MYSQL -u $MUSER -p$MPASS -h $MHOST $MDB < $BACKUP | |
echo "Reinstall finsh" | |
echo "Clean Joomla" | |
ADMINDIR="administrator/components/" | |
ADMINDIR=$DELETDIR$ADMINDIR | |
for i in ${REMOVEADMINDIR[*]} | |
do | |
rm -Rf $ADMINDIR$i | |
echo "removed $ADMINDIR$i" | |
done | |
SITEDIR="components/" | |
SITEDIR=$DELETDIR$SITEDIR | |
for i in ${REMOVESITEDIR[*]} | |
do | |
rm -Rf $SITEDIR$i | |
echo "removed $SITEDIR$i" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment