+

Add possibility to use curl instead of wget

Benjamin Renard [2017-04-24 12:51:36]
Add possibility to use curl instead of wget
Filename
check_rc_upgrade.sh
diff --git a/check_rc_upgrade.sh b/check_rc_upgrade.sh
index d8e7d97..00f3bfc 100755
--- a/check_rc_upgrade.sh
+++ b/check_rc_upgrade.sh
@@ -15,29 +15,33 @@ CHECK_URL=https://roundcube.net/download/
 DOWNLOAD=0
 DOWNLOAD_DIR=$RC_HOME/../upstream
 DONT_CHECK_SSL_CERT=0
+WGET_OPTS=""
+CURL_OPTS=""

 ### DO NOT MODIFY AFTER THIS LINE ###

 DEBUG=0
 NAGIOS=0
 UPGRADE=0
+CURL=0
 EXTRACT=0
 JUST_DISP=0
 JUST_AFTER_UPGRADE=0

 function usage() {
-	echo "Usage : $0 [-v] [-n] [-d] [-u]"
+	echo "Usage : $0 [-v] [-n] [-d] [-u] [-c]"
 	echo "  -v   Verbose mode"
 	echo "  -n   Nagios mode"
-	echo "  -S   Don't check SSL certificate"
+	echo "  -S   Don't check SSL certificate (Wget only)"
 	echo "  -d   Download new release"
 	echo "  -u   Upgrade installation"
+	echo "  -c   Use curl instead of wget"
 	echo "  -a   Just run after_upgrade function"
 	echo "  -j   Just display current stable version"
 	echo "  -h   Display this help"
 }

-while getopts ":dvnShuaj" opt; do
+while getopts ":dvnShucaj" opt; do
 	case $opt in
 		v)
 			DEBUG=1
@@ -57,6 +61,9 @@ while getopts ":dvnShuaj" opt; do
 			DEBUG=1
 			EXTRACT=1
 		;;
+		c)
+			CURL=1
+		;;
 		a)
 			JUST_AFTER_UPGRADE=1
 		;;
@@ -117,7 +124,12 @@ fi
 for i in `seq 1 $MAX_CHECK`
 do
 	tmpfile=`mktemp`
-	wget $WGET_SSL_OPT -q $CHECK_URL -O $tmpfile
+	if [ $CURL -eq 1 ]
+	then
+		curl $CURL_OPTS --silent --output $tmpfile $CHECK_URL
+	else
+		wget $WGET_OPTS $WGET_SSL_OPT -q $CHECK_URL -O $tmpfile
+	fi
 	newest=`cat $tmpfile|grep 'github.com'|grep 'complete.tar.gz'|head -n 1|sed 's|^.*github.com/roundcube/roundcubemail/releases/download/\([^/]*\)/roundcubemail-.*$|\1|'`
 	if [ -n "$newest" ]
 	then
@@ -188,7 +200,12 @@ then
 			cd "$DOWNLOAD_DIR"
 			DOWNLOAD_FILE="$( pwd )/roundcubemail-$newest.tar.gz"
 			[ $DEBUG -eq 1 ] && echo "Download new release in $DOWNLOAD_FILE"
-			wget $WGET_SSL_OPT -q -O "$DOWNLOAD_FILE" "$DOWNLOAD_URL"
+			if [ $CURL -eq 1 ]
+			then
+				curl $CURL_OPTS --silent --output $DOWNLOAD_FILE $DOWNLOAD_URL
+			else
+				wget $WGET_OPTS $WGET_SSL_OPT -q -O "$DOWNLOAD_FILE" "$DOWNLOAD_URL"
+			fi
 			if [ $EXTRACT -eq 1 ]
 			then
 				[ $DEBUG -eq 1 ] && echo "Extract new release"
ViewGit