-
Notifications
You must be signed in to change notification settings - Fork 10
/
create-archive.sh
executable file
·102 lines (85 loc) · 2.03 KB
/
create-archive.sh
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
#
# Create an archive of project directory for OBS
#
# Author: Tom Schraitle, 2022-2023
set -o errexit
set -o pipefail
set -o nounset
# set -o xtrace
ME="${0##*/}"
NAME="suse-xsl"
OUTDIR="/tmp"
SUFFIX=".tar.gz"
FROM="HEAD"
function exit_on_error {
echo "ERROR: ${1}" >&2
exit 1;
}
function usage {
cat << EOF
Create archive of current repo
SYNOPSIS
$ME [OPTIONS] [VERSION]
$ME -h|--help
OPTIONS
-h, --help Output this help text.
--outdir=OUTDIR Store archive in OUTDIR (default ${OUTDIR@Q})
-f FROM, --from=FROM
The tree or commit to produce an archive for
(default ${FROM@Q})
ARGUMENTS
VERSION Use this version to create the archive
If omitted, the version is retrieved through "git describe"
Any "v" prefix is removed.
EXAMPLES:
1. $ME
creates an archive and stores it under $OUTDIR
2. $ME --outdir=/local/repo
creates an archive and stores it under /local/repo
3. $ME v3.0.0
creates an archive /tmp/$NAME-3.0.0.tar.bz2
EOF
}
# -- CLI parsing
ARGS=$(getopt -o h,f: -l help,from:,outdir: -n "$ME" -- "$@")
eval set -- "$ARGS"
while true; do
case "$1" in
--help|-h)
usage
exit 0
shift
;;
-f|--from)
FROM="$2"
shift 2
;;
--outdir)
OUTDIR="$2"
if [ ! -d "$OUTDIR" ]; then
mkdir -p "$OUTDIR"
fi
shift 2
;;
--) shift ; break ;;
*) exit_on_error "Wrong parameter: $1" ;;
esac
done
# Remove last slash and expand ~ with $HOME
OUTDIR=${OUTDIR%*/}
OUTDIR=${OUTDIR/#\~/$HOME}
# Get version from git:
VERSION=$(git describe)
# Overwrite VERSION with first argument
if [ "$#" -ne 0 ]; then
VERSION="$1"
fi
# Remove "v" prefix:
VERSION=${VERSION#v*}
FILE="${OUTDIR}/${NAME}-${VERSION}${SUFFIX}"
echo "Generating version ${FILE@Q}..."
git archive --worktree-attributes --format=${SUFFIX#.*} \
--prefix="suse-xsl-${VERSION}/" \
--output="${FILE}" \
"$FROM"