You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
IUT/vdn/bin/vdn-download-network

87 lines
1.2 KiB

#!/usr/bin/env bash
set -eu
#set -x
DRY=0
SYSTEMS=""
FORCE=0
synopsis() {
cat << EOF
Usage : `basename $0` [-hdf] url
EOF
}
help() {
cat << EOF
`basename $0` télécharge le réseau.
`synopsis`
-h : affiche cette aide
-d : dry run
-f : pas de demande de confirmation
EOF
}
usage() {
synopsis
exit 1
}
args() {
local opt
while getopts "hf" opt; do
case $opt in
h) help; exit 0;;
f) FORCE=1;;
?) usage;;
esac
done
shift $(($OPTIND-1))
[ $# -gt 1 ] && usage
[ $# -eq 1 ] && URL=$1 || URL=""
}
download() {
file=$(basename $URL .zip)
if [ $file.zip = $URL ]; then
URL="$DEFAULT_REPOSITORY/$file"
fi
echo "file:$file"
rm -f $TMPDIR/$file.zip
wget -c -O $TMPDIR/$file.zip $URL
if [ -e $VDN_NETWORKS_BASE_DIR/$file -a $FORCE = 0 ]; then
requestNo "Network exist ! Overwrite ?"
fi
if [ $FORCE = 0 ]; then
request "Extract $file.zip ?"
fi
( cd $VDN_NETWORKS_BASE_DIR; rm -Rf $file; unzip -x $TMPDIR/$file.zip )
}
# Programme principal
GUEST_OWNER=$USER
VDN_PATH=$(readlink -f $(dirname $0)/..); . $VDN_PATH/bin/functions.sh
args "$@"
if [ -z "$URL" ]; then
echo -n "URL (ex: http:truc.bidule/net.zip) : "
read URL
fi
download $URL