Blob


1 #!/bin/sh
3 die() {
4 ec=$1
5 shift
6 echo "$@" >&2
7 exit "$ec"
8 }
10 usage() {
11 die 1 "Usage: got-archive [-sV] [-b branch/tag] [-o outdir] [-t tmpdir] repo"
12 }
14 args=$(getopt b:o:st:V $*)
15 [ $? -ne 0 ] && usage
17 set -- $args
19 strip=0
20 branch=
21 outdir=.
22 tmpdir="/tmp/got-archive"
24 while [ $# -ne 0 ]; do
25 case "$1" in
26 -s)
27 strip=1
28 shift
29 ;;
30 -b)
31 branch=$2
32 shift
33 shift
34 ;;
35 -o)
36 outdir=$2
37 shift
38 shift
39 ;;
40 -t)
41 tmpdir=$2
42 shift
43 shift
44 ;;
45 -V)
46 echo "got-archive-@VERSION@"
47 exit 1
48 ;;
49 --)
50 shift
51 break
52 ;;
53 esac
54 done
56 [ $# -ne 1 ] && usage
58 repo=$1
59 name=$(basename "$repo" | sed 's/\.git$//')
60 if [ "$strip" = 1 ]; then
61 ver=$(echo "$branch" | sed 's/^v//g')
62 else
63 ver=$branch
64 fi
66 [ -d "$repo" ] || die 2 "Error: invalid repo: $repo"
68 mkdir -p "$tmpdir"
70 if [ "$branch" ]; then
71 cname="$name-$ver"
72 got checkout -q -b "$branch" "$repo" "$tmpdir/$cname" || die 3 "Error: failed to checkout"
73 else
74 cname="$name"
75 got checkout -q "$repo" "$tmpdir/$cname" || die 3 "Error: failed to checkout"
76 fi
78 rm -rf "$tmpdir/$cname/.got"
79 tar -czf "$outdir/$cname.tgz" -C "$tmpdir" "$cname" || die 4 "Error: failed to create tarball"
80 rm -rf "$tmpdir/$cname"