Renamed some functions inside bin/sde-update-package to be update_*() instead of...
[opensde-nopast.git] / bin / sde-download-git
blob1049e155a2c73ac02eaa214c6fa38974346979dc
1 #!/bin/sh
2 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 #
5 # Filename: bin/sde-download-git
6 # Copyright (C) 2007 The OpenSDE Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
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 [-vq] <target> <source> <tag>
25 EOT
28 shortopts='qv'
29 longopts='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 verbose=1
41 target=
42 source=
44 while [ $# -gt 0 ]; do
45 case "$1" in
46 --) shift; break ;;
48 -v|--verbose)
49 let verbose++ ;;
50 -q|--quiet)
51 let verbose-- ;;
52 esac
53 shift
54 done
56 # now take the real arguments
57 if [ $# -ne 3 ]; then
58 echo_error "Not enough arguments given."
59 download_usage
60 exit -1
63 target="$1"
64 source="$2"
65 tag="$3"
66 errno=0
68 if [ -e "$target.lock" ]; then
69 echo_warning "$target: File locked"
70 exit 111
71 else
72 trap '' INT
73 echo "$$" > "$target.lock"
74 prefix=${source##*/}; prefix=${prefix%.git}-${tag}
76 [ $verbose -le 1 ] || echo_info "git-archive --format=tar --prefix=$prefix/ --remote='$source' '$tag'"
78 # download in background
80 git-archive --format=tar --prefix=$prefix/ --remote="$source" "$tag" | bzip2 > $target
81 echo $? > $target.errno
82 ) &
84 # and wait until it ends
85 while fuser $target &> /dev/null ; do
86 echo -ne "$( nice du -sh "$target" 2> /dev/null | cut -f1 ) downloaded from archive so far...\r"
87 sleep 3
88 done
90 errno=$( cat $target.errno 2> /dev/null )
91 if [ "$errno" != "0" -o ! -s "$target" ]; then
92 rm -f "$target"
93 echo_error "Download failed (errno:${errno:-undefined})"
94 elif [ $verbose -gt 0 ]; then
95 echo_info "$( du -sh "$target" 2> /dev/null | cut -f1 ) downloaded from archive."
98 rm -f "$target.errno" "$target.lock"
99 trap - INT
100 exit ${errno:-1}