Used getopts and added download feature

This commit is contained in:
root 2011-02-10 12:02:47 +01:00
parent bfc9ce7f7f
commit 12b69e6522

View file

@ -10,9 +10,45 @@ MAX_CHECK=10
MAX_FAILED=3 MAX_FAILED=3
SLEEP_ON_FAILED=10 SLEEP_ON_FAILED=10
CHECK_URL=http://www.roundcube.net/download CHECK_URL=http://www.roundcube.net/download
DOWNLOAD_DIR=$RC_HOME/../upstream
DEBUG=0 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" [ -f "$0.local" ] && source "$0.local" && [ $DEBUG -eq 1 ] && echo "Import local config file : $0.local"
@ -74,6 +110,19 @@ then
echo >> $tmp echo >> $tmp
echo "Download URL : $DOWNLOAD_URL" >> $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 M=0
if [ -f $CACHE ] if [ -f $CACHE ]
then then