From 12b69e6522cae75a09680ed716c339e17150712d Mon Sep 17 00:00:00 2001 From: root Date: Thu, 10 Feb 2011 12:02:47 +0100 Subject: [PATCH] Used getopts and added download feature --- check_rc_upgrade.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/check_rc_upgrade.sh b/check_rc_upgrade.sh index fb3bebf..90c460d 100755 --- a/check_rc_upgrade.sh +++ b/check_rc_upgrade.sh @@ -10,9 +10,45 @@ MAX_CHECK=10 MAX_FAILED=3 SLEEP_ON_FAILED=10 CHECK_URL=http://www.roundcube.net/download +DOWNLOAD_DIR=$RC_HOME/../upstream DEBUG=0 -[ "$1" == "-v" ] && DEBUG=1 +DOWNLOAD=0 + +function usage() { + echo "Usage : $0 [-v] [-d]" + echo " -v Verbose mode" + echo " -d Download new release" + echo " -h Display this help" +} + +while getopts ":dvh" opt; do + case $opt in + v) + DEBUG=1 + ;; + d) + DOWNLOAD=1 + ;; + h) + usage + exit 0 + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + echo + usage + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + echo + usage + exit 1 + ;; + + esac +done [ -f "$0.local" ] && source "$0.local" && [ $DEBUG -eq 1 ] && echo "Import local config file : $0.local" @@ -73,6 +109,19 @@ then echo "Newest : $newest" >> $tmp echo >> $tmp echo "Download URL : $DOWNLOAD_URL" >> $tmp + + if [ $DOWNLOAD -eq 1 ] + then + if [ -d "$DOWNLOAD_DIR" ] + then + cd "$DOWNLOAD_DIR" + [ $DEBUG -eq 1 ] && echo "Download new release in $( pwd )/roundcubemail-$newest.tar.gz" + wget -q -O "roundcubemail-$newest.tar.gz" "$DOWNLOAD_URL" + echo "Download file : $( pwd )/roundcubemail-$newest.tar.gz" >> $tmp + else + echo "[WARNING] Le dossier de telechargement n'existe pas ($DOWNLOAD_DIR)." + fi + fi M=0 if [ -f $CACHE ]