summaryrefslogtreecommitdiff
path: root/tools/make-tarball
blob: 91c45624c0b12af5e934eeea1727f3cf477edb60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
set -e

TEMP_D=""
cleanup() {
    [ -z "$TEMP_D" ] || rm -Rf "${TEMP_D}"
}
trap cleanup EXIT

Usage() {
    cat <<EOF
Usage: ${0##*/} [revision]
    create a tarball of revision (default HEAD)

    options:
      -o | --output FILE   write to file
EOF
}

short_opts="ho:v"
long_opts="help,output:,long,verbose"
getopt_out=$(getopt --name "${0##*/}" \
    --options "${short_opts}" --long "${long_opts}" -- "$@") &&
    eval set -- "${getopt_out}" || { Usage 1>&2; exit 1; }

long_opt=""
while [ $# -ne 0 ]; do
    cur=$1; next=$2
    case "$cur" in
        -o|--output) output=$next; shift;;
           --long) long_opt="--long";;
        --) shift; break;;
    esac
    shift;
done

rev=${1:-HEAD}
version=$(git describe "--match=[0-9]*" ${long_opt} $rev)

archive_base="cloud-init-$version"
if [ -z "$output" ]; then
    output="$archive_base.tar.gz"
fi

# when building an archiving from HEAD, ensure that there aren't any
# uncomitted changes in the working directory (because these would not
# end up in the archive).
if [ "$rev" = HEAD ] && ! git diff-index --quiet HEAD --; then
    if [ -z "$SKIP_UNCOMITTED_CHANGES_CHECK" ]; then
        echo "ERROR: There are uncommitted changes in your working directory." >&2
        exit 1
    else
        echo "WARNING: There are uncommitted changes in your working directory." >&2
        echo "         This changes will not be included in the archive." >&2
    fi
fi

TEMP_D=$(mktemp -d)
tar=${output##*/}
tar="$TEMP_D/${tar%.gz}"
git archive --format=tar --prefix="$archive_base/" "$rev" > "$tar"
gzip -9 -c "$tar" > "$output"
echo "$output"