41 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/bash
 | |
| # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
 | |
| source "$(dirname "$0")/lib/ulib/ulib" || exit 1
 | |
| urequire DEFAULTS
 | |
| 
 | |
| function display_help() {
 | |
|     uecho "$scriptname: Télécharger un fichier avec wget ou curl
 | |
| 
 | |
| USAGE
 | |
|     $scriptname <file.url|file.desktop|URL> [wget options]"
 | |
| }
 | |
| 
 | |
| parse_opts + "${PRETTYOPTS[@]}" \
 | |
|     --help '$exit_with display_help' \
 | |
|     @ args -- "$@" && set -- "${args[@]}" || die "$args"
 | |
| 
 | |
| "$scriptdir/caturl" --check "$1"
 | |
| case $? in
 | |
| 2) die "Vous devez spécifier l'url à ouvrir";;
 | |
| 3) die "Le fichier spécifié ne contient pas d'url";;
 | |
| esac
 | |
| setx url="$scriptdir/caturl" "$1" || die
 | |
| shift
 | |
| 
 | |
| filename="$(basename "$url")"
 | |
| if progexists wget; then
 | |
|     if [ -f "$filename" ]; then
 | |
|         wget -c "$@" "$url"
 | |
|     else
 | |
|         wget "$@" "$url"
 | |
|     fi
 | |
| elif progexists curl; then
 | |
|     if [ -f "$filename" ]; then
 | |
|         curl -C - -o "$filename" "$@" "$url"
 | |
|     else
 | |
|         curl -o "$filename" "$@" "$url"
 | |
|     fi
 | |
| else
 | |
|     die "Aucune méthode de téléchargement n'a été détectée"
 | |
| fi
 |