| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | set -e |
| 3 | |
| 4 | TEMP_D="" |
| 5 | cleanupscip-shell shell shell-project 0.0.0 cleanup().() { |
| 6 | [scip-shell system . . `[`. -z "$TEMP_D" ] || rmscip-shell system . . rm. -Rf "${TEMP_D}" |
| 7 | } |
| 8 | trap cleanup EXIT |
| 9 | |
| 10 | Usagescip-shell shell shell-project 0.0.0 Usage().() { |
| 11 | catscip-shell system . . 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=$(getoptscip-shell system . . getopt. --name "${0##*/}" \ |
| 27 | --options "${short_opts}" --long "${long_opts}" -- "$@") && |
| 28 | eval set -- "${getopt_out}" || { |
| 29 | Usagescip-shell shell shell-project 0.0.0 Usage(). 1>&2 |
| 30 | exit 1 |
| 31 | } |
| 32 | |
| 33 | long_opt="" |
| 34 | orig_opt="" |
| 35 | version="" |
| 36 | while [scip-shell system . . `[`. $# -ne 0 ]; do |
| 37 | cur=$1 |
| 38 | next=$2 |
| 39 | case "$cur" in |
| 40 | -h | --help) |
| 41 | Usagescip-shell shell shell-project 0.0.0 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 [scip-shell system . . `[`. -z "$version" ]; then |
| 64 | version=$(gitscip-shell system . . git. describe --abbrev=8 "--match=[0-9]*" ${long_opt} $rev) |
| 65 | elif [scip-shell system . . `[`. ! -z "$long_opt" ]; then |
| 66 | echoscip-shell system . . 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 [scip-shell system . . `[`. -z "$output" ]; then |
| 72 | if [scip-shell system . . `[`. ! -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 [scip-shell system . . `[`. "$rev" = HEAD ] && ! gitscip-shell system . . git. diff-index --quiet HEAD --; then |
| 82 | if [scip-shell system . . `[`. -z "$SKIP_UNCOMITTED_CHANGES_CHECK" ]; then |
| 83 | echoscip-shell system . . echo. "ERROR: There are uncommitted changes in your working directory." >&2 |
| 84 | exit 1 |
| 85 | else |
| 86 | echoscip-shell system . . echo. "WARNING: There are uncommitted changes in your working directory." >&2 |
| 87 | echoscip-shell system . . echo. " This changes will not be included in the archive." >&2 |
| 88 | fi |
| 89 | fi |
| 90 | |
| 91 | TEMP_D=$(mktempscip-shell system . . mktemp. -d) |
| 92 | tar=${output##*/} |
| 93 | tar="$TEMP_D/${tar%.gz}" |
| 94 | gitscip-shell system . . git. archive --format=tar --prefix="$archive_base/" "$rev" > "$tar" |
| 95 | gzipscip-shell system . . gzip. -9 -c "$tar" > "$output" |
| 96 | echoscip-shell system . . echo. "$output" |