functions: changed pkginstalled() to use $* instead of "$@" when generating the pattern
[opensde-nopast.git] / bin / sde-download-get
blob2c41f93f4a5cc8fb73bb4fd3a87fb2f2daa70f51
1 #!/bin/sh
2 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # Filename: bin/sde-download-get
6 # Copyright (C) 2007 The OpenSDE Project
8 # More information can be found in the files COPYING and README.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- SDE-COPYRIGHT-NOTE-END ---
16 [ -n "$SDEROOT" ] ||
17 export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
19 . $SDEROOT/lib/libsde.in
21 download_usage() {
22 local progname=${0##*/}
23 cat <<EOT >&2
24 Usage: $progname [-vqd] <target> <source>
25 EOT
28 shortopts='nqv'
29 longopts='dry-run,quiet,verbose'
30 options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
32 if [ $? -ne 0 ]; then
33 download_usage
34 exit -1
37 # load new arguments list
38 eval set -- "$options"
40 dryrun=
41 verbose=1
42 target=
43 source=
45 while [ $# -gt 0 ]; do
46 case "$1" in
47 --) shift; break ;;
49 -n|--dry-run)
50 dryrun="yes" ;;
51 -v|--verbose)
52 let verbose++ ;;
53 -q|--quiet)
54 let verbose-- ;;
55 esac
56 shift
57 done
59 # now take the real arguments
60 if [ $# -lt 2 ]; then
61 echo_error "Not enough arguments given."
62 download_usage
63 exit -1
66 target="$1"; shift
67 protocol=${1%%:*}
69 # debug output
70 [ $verbose -le 1 ] || echo_info "($protocol) $@"
72 # find the right handler
73 if [ -x "$SDEROOT/bin/sde-download-$protocol" ]; then
74 handler="$SDEROOT/bin/sde-download-$protocol"
75 else
76 handler=$( grep -l "^#Protocol: $protocol\$" "$SDEROOT/bin"/sde-download-* 2> /dev/null )
78 handleropt=
80 [ -x "$handler" ] || echo_abort 2 "$protocol: protocol unhandled"
82 if [ -n "$dryrun" ]; then
83 echo "(${handler##*/}) $source"
84 elif [ ! -e "$target.lock" ]; then
86 # arguments for the handler, reduce the verbosity on one level
87 if [ $verbose -gt 2 ]; then
88 handleropt="-v"
89 elif [ $verbose -lt 0 ]; then
90 handleropt="-q"
93 exec "$handler" $handleropt -- "$target" "$@"