Debian Codegraph @

tools/make-tarball

raw symbols SCIP
1 #!/bin/sh
2 set -e
3
4 TEMP_D=""
5 cleanup() {
6 [ -z "$TEMP_D" ] || rm -Rf "${TEMP_D}"
7 }
8 trap cleanup EXIT
9
10 Usage() {
11 cat << EOF
12 Usage: ${0##*/} [revision]
13 create a tarball of revision (default HEAD)
14
15 options:
16 -h | --help print usage
17 -o | --output FILE write to file
18 --version VERSION Set the version used in the tarball. Default value is determined with 'git describe'.
19 --orig-tarball Write file cloud-init_<version>.orig.tar.gz
20 --long Use git describe --long for versioning
21 EOF
22 }
23
24 short_opts="ho:v"
25 long_opts="help,output:,version:,orig-tarball,long"
26 getopt_out=$(getopt --name "${0##*/}" \
27 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
28 eval set -- "${getopt_out}" || {
29 Usage 1>&2
30 exit 1
31 }
32
33 long_opt=""
34 orig_opt=""
35 version=""
36 while [ $# -ne 0 ]; do
37 cur=$1
38 next=$2
39 case "$cur" in
40 -h | --help)
41 Usage
42 exit 0
43 ;;
44 -o | --output)
45 output=$next
46 shift
47 ;;
48 --version)
49 version=$next
50 shift
51 ;;
52 --long) long_opt="--long" ;;
53 --orig-tarball) orig_opt=".orig" ;;
54 --)
55 shift
56 break
57 ;;
58 esac
59 shift
60 done
61
62 rev=${1:-HEAD}
63 if [ -z "$version" ]; then
64 version=$(git describe --abbrev=8 "--match=[0-9]*" ${long_opt} $rev)
65 elif [ ! -z "$long_opt" ]; then
66 echo "WARNING: --long has no effect when --version is passed" >&2
67 exit 1
68 fi
69
70 archive_base="cloud-init-$version"
71 if [ -z "$output" ]; then
72 if [ ! -z "$orig_opt" ]; then
73 archive_base="cloud-init_$version"
74 fi
75 output="$archive_base$orig_opt.tar.gz"
76 fi
77
78 # when building an archiving from HEAD, ensure that there aren't any
79 # uncommitted changes in the working directory (because these would not
80 # end up in the archive).
81 if [ "$rev" = HEAD ] && ! git diff-index --quiet HEAD --; then
82 if [ -z "$SKIP_UNCOMITTED_CHANGES_CHECK" ]; then
83 echo "ERROR: There are uncommitted changes in your working directory." >&2
84 exit 1
85 else
86 echo "WARNING: There are uncommitted changes in your working directory." >&2
87 echo " This changes will not be included in the archive." >&2
88 fi
89 fi
90
91 TEMP_D=$(mktemp -d)
92 tar=${output##*/}
93 tar="$TEMP_D/${tar%.gz}"
94 git archive --format=tar --prefix="$archive_base/" "$rev" > "$tar"
95 gzip -9 -c "$tar" > "$output"
96 echo "$output"