diff --git a/cli/upgrade.sh b/cli/upgrade.sh index a2cf347cc..215d8a083 100755 --- a/cli/upgrade.sh +++ b/cli/upgrade.sh @@ -10,36 +10,42 @@ # By Uwe Bieling # and Jordan S (https://github.com/jas8522) -if [[ $(id -u) -ne 0 ]] ; then echo -e "\033[1;31mPlease run as root\033[0m" ; exit 1 ; fi - SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -cd "${SCRIPT_DIR}/.." - -if [ ! -d snappymail/v ] ; then echo -e "\033[1;31mThis script can only be run from the SnappyMail install directory\033[0m" ; exit 1 ; fi - LATEST_URL="https://snappymail.eu/repository/latest.tar.gz" - OWNERGROUP=`stat -c "%U:%G" snappymail` OLD_VERSION=`grep "define('APP_VERSION" index.php | awk -F\' '{print $4}'` -# Safety First ... make a backup -DSTAMP=`date +%Y-%m-%d` -echo -e "\033[1;33mBacking up snappymail $OLD_VERSION to ../backup_snappymail_${DSTAMP}.tar.gz\033[0m" -tar -czf ../backup_snappymail_${DSTAMP}.tar.gz . +# check if we are root +if [[ $(id -u) -ne 0 ]] ; then echo -e "\033[1;31mPlease run as root\033[0m" ; exit 1 ; fi + +# check if we are in the correct dir +cd "${SCRIPT_DIR}" +if [ ! -d snappymail/v ] ; then echo -e "\033[1;31mThis script can only be run from the SnappyMail install directory\033[0m" ; exit 1 ; fi # Download last release to /tmp echo -e "\033[1;33mDownloading last release\033[0m" -wget $LATEST_URL -O /tmp/snappymail_latest.tar.gz +wget $LATEST_URL -O /tmp/snappymail_latest.tar.gz >/dev/null 2>&1 NEW_VERSION=`tar -tf /tmp/snappymail_latest.tar.gz | grep "snappymail/v/.*/index.php" | awk -F/ '{print $3}'` -echo -e "\033[1;33mInstalling $NEW_VERSION\033[0m" -tar -xzf /tmp/snappymail_latest.tar.gz +if [ $OLD_VERSION != $NEW_VERSION ] ; +then + # Safety First ... make a backup + DSTAMP=`date +%Y-%m-%d` + echo -e "\033[1;33mBacking up snappymail $OLD_VERSION to ../backup_snappymail_${DSTAMP}.tar.gz\033[0m" + tar -czf ../backup_snappymail_${DSTAMP}.tar.gz . -# set permissions -echo -e "\033[1;33mSet permissions\033[0m" -find . -type d -exec chmod 755 {} \; -find . -type f -exec chmod 644 {} \; -chmod u+x "${SCRIPT_DIR}/upgrade.sh" -chown -R $OWNERGROUP * + # installing + echo -e "\033[1;33mInstalling $NEW_VERSION\033[0m"; + tar -xzf /tmp/snappymail_latest.tar.gz; -echo -e "\033[1;32mFinished with snappymail upgrade from $OLD_VERSION to $NEW_VERSION... \033[0m" + # set permissions + echo -e "\033[1;33mSet permissions\033[0m" + find . -type d -exec chmod 755 {} \; + find . -type f -exec chmod 644 {} \; + chmod u+x "${SCRIPT_DIR}/upgrade.sh" + chown -R $OWNERGROUP * + echo -e "\033[1;32mFinished with snappymail upgrade from $OLD_VERSION to $NEW_VERSION... \033[0m" + +else + echo -e "\033[1;31msame Version skipping.. \033[0m"; +fi