|
|
#!/bin/sh # --- SDE-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: bin/sde-download2 # Copyright (C) 2007 The OpenSDE Project # # More information can be found in the files COPYING and README. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. A copy of the # GNU General Public License can be found in the file COPYING. # --- SDE-COPYRIGHT-NOTE-END ---
#Description: Download sources
[ -n "$SDEROOT" ] || export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
. $SDEROOT/lib/libsde.in
download_usage() { local progname=${0##*/} cat <<EOT >&2 Usage: $progname [DISCRIMINATOR] [OPTIONS] [ITEMS...]
Accepted discriminators: * config (cfg) * package (pkg) - default * repository (repo)
For more information read \`sde help download\`. EOT }
# detect discriminator discriminator=package if [ $# -gt 0 ]; then case "$1" in -*) ;; config|cfg) discriminator=config; shift ;; package|pkg) discriminator=package; shift ;; repository|repo) discriminator=repository; shift ;; *) echo_error "$1: invalid discriminator" download_usage exit -1 ;; esac fi
shortopts='nqvc:m:e' longopts='dry-run,quiet,verbose,cfg,timeout:,cfg,check:,mirror:,mode:,extenders' options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
if [ $? -ne 0 ]; then download_usage exit -1 fi
# load new arguments list eval set -- "$options"
dryrun= verbose=1 timeout=normal check=always mirror= altdir= mode=hardlink extenders= config=
# load global settings eval $( $SDEROOT/bin/sde-config-ini --file=$SDESETTINGS download ) eval $( $SDEROOT/bin/sde-config-ini --file=$SDESETTINGS download-$sdever )
while [ $# -gt 0 ]; do case "$1" in --) shift; break ;;
-n|--dry-run) dryrun=yes ;; -e|--extenders) extenders=yes ;; -v|--verbose) let verbose++ ;; -q|--quiet) let verbose-- ;;
--timeout) shift case "$1" in normal|long|no) timeout="$1" ;; *) echo_abort 1 "$1: invalid timeout value: [normal*|long|no]" ;; esac ;; --check) shift case "$1" in always|download|never) check="$1" ;; *) echo_abort 1 "$1: invalid ckeck value: [always*|download|never]" ;; esac ;; --mirror) shift case "$1" in none|auto|http://*|https://*|ftp://*|file://*) mirror="$1" ;; *) echo_abort 1 "$1: invalid mirror value" ;; esac ;; -m|--mode) shift case "$1" in hardlink|copy|move) mode="$1" ;; *) echo_abort 1 "$1: invalid altdir mode [hardlink*|copy|move]" ;; esac ;; -c|--cfg) shift config=${1:-default} ;; esac shift done
# constants to pass to sde-download-get downloadgetopt= if [ $verbose -gt 2 ]; then downloadgetopt='-v' elif [ $verbose -lt 0 ]; then downloadgetopt='-q' fi if [ -n "$dryrun" ]; then downloadgetopt="$downloadgetopt --dry-run" fi
case "$discriminator" in package) $SDEROOT/bin/sde-list-download ${config:+--cfg $config} ${extenders:+--extenders} -pkl -- "$@" ;; repository) $SDEROOT/bin/sde-list-download ${config:+--cfg $config} ${extenders:+--extenders} -rpkl -- "$@" ;; config) [ -z "$config" ] || set -- "$config" "$@"
[ $# -gt 0 ] || set -- default
for config; do $SDEROOT/bin/sde-list-download --cfg "$config" -pkl done ;; esac | while read pkg cksum file location; do # temporal download location tmpfile="$SDEROOT/tmp/down.$( echo $file | tr '/' '-' )" mkdir -p "$SDEROOT/tmp" [ $? -eq 0 ] || exit -1
if [ -s "$SDEROOT/$file" ]; then : elif [ -e "$tmpfile.lock" ]; then echo_warning "$file: skipping." else if [ $verbose -le 0 ]; then : elif [ $verbose -le 1 ]; then echo_info "Downloading $pkg:$file" else echo_info "Downloading $pkg:$file ($cksum) $location" fi
"$SDEROOT"/bin/sde-download-get $downloadgetopt -- "$tmpfile" $location if [ $? -ne 0 ]; then echo_warning "$file: failed to download" rm -f "$tmpfile" else mkdir -p "${file%/*}" mv "${tmpfile}" "$file" fi fi done
|