Skip to content

Instantly share code, notes, and snippets.

@knutov
Forked from pothi/pma-auto-update.sh
Created August 23, 2013 13:50
Show Gist options
  • Save knutov/6319537 to your computer and use it in GitHub Desktop.
Save knutov/6319537 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script to automate PhpMyAdmin updates
# To manually switch to another version, use...
# bash pma-auto-update.sh version_number
### Variables
[email protected]
SITESDIR=${HOME}/sites
PMADIR=${SITESDIR}/phpmyadmin
LOGDIR=$HOME/log
LOGFILE=$LOGDIR/phpmyadmin-updates.log
###### PLEASE DO NOT EDIT BELOW THIS LINE ######
function send_email() {
echo "PhpMyAdmin Update didn't go through on server $(hostname -f | awk -F. '{print $2"."$3}'), $(date)" | \
mail -s "ALERT: PhpMyAdmin Script Failed - Check the log file for more info" $ADMIN_EMAIL
}
TEMP_FILE='/tmp/pma-version.html'
PMAOLD=${PMADIR}-old
## check for all directories
if [ ! -d "$LOGDIR" ]; then
echo
echo "Log directory doesn't exist. Please modify the script and re-run."
echo
send_email
exit 1
fi
# check for the latest version
wget -q -O $TEMP_FILE http://www.phpmyadmin.net/home_page/downloads.php
if [ "$?" != '0' ]; then
echo 'Something wrent wrong while downloading the downloads.php file from phpmyadmin.net!' >> $LOGFILE
send_email
exit 1
fi
NEW_VERSION=$(grep -i '.h2.phpmyadmin' $TEMP_FILE | head -1 | sed 's_</\?h2>__g' | awk '{print $2}')
if [ "$NEW_VERSION" == '' ]; then
echo 'Something wrong in identifying the new version' >> $LOGFILE
send_email
fi
rm $TEMP_FILE
CURRENT_VERSION=$(ls ${PMADIR}/RELEASE-DATE-* | sed 's:'${PMADIR}'/RELEASE-DATE-::')
echo >> $LOGFILE
# insert date and time of update
echo 'Date: '$(date +%F) >> $LOGFILE
echo 'Time: '$(date +%H-%M-%S) >> $LOGFILE
echo 'Current Version: '$CURRENT_VERSION >> $LOGFILE
echo 'New Version: '$NEW_VERSION >> $LOGFILE
if [ "$1" == '' ]; then
if [ "$NEW_VERSION" == "$CURRENT_VERSION" ]; then
echo 'No updates available' >> $LOGFILE
echo >> $LOGFILE
exit 0
else
version=$NEW_VERSION
echo 'Updating PhpMyAdmin from '$CURRENT_VERSION' to '$NEW_VERSION'...' >> $LOGFILE
fi
else
version=$1
echo 'Manually updating the version to '$1'...' >> $LOGFILE
fi
if [ ! -d "$PMADIR" ]; then
echo "PhpMyAdmin directory doesn't exist. Please modify the script and re-run." >> $LOGFILE
send_email
exit 1
fi
echo 'Upgrading PhpMyAdmin to '$version
echo 'Hold on! Downloading the latest version...'
wget -q sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/${version}/phpMyAdmin-${version}-english.tar.gz -O /tmp/phpmyadmin-current-version.tar.gz
if [ "$?" != '0' ]; then
echo 'Something wrent wrong while downloading the version - '${version} >> $LOGFILE
send_email
exit 1
fi
echo 'Done downloading'
cd /tmp/
tar xzf /tmp/phpmyadmin-current-version.tar.gz && rm /tmp/phpmyadmin-current-version.tar.gz
cd - &> /dev/null
if [ "$?" != '0' ]; then
echo 'Something wrent wrong, while extracting the archive!' >> $LOGFILE
send_email
exit 1
fi
# backup the installed version and switch to new version
mv $PMADIR $PMAOLD && mv /tmp/phpMyAdmin-${version}-english $PMADIR
if [ "$?" != '0' ]; then
echo 'Something wrent wrong, while moving directories!' >> $LOGFILE
send_email
exit 1
fi
cp ${PMAOLD}/config.inc.php ${PMADIR}/
if [ "$?" != '0' ]; then
echo 'Something wrent wrong, while copying the config file!' >> $LOGFILE
send_email
exit 1
fi
# remove old files
rm -rf $PMAOLD
echo 'Done upgrading PhpMyadmin...' >> $LOGFILE
echo >> $LOGFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment