-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharchive
executable file
·78 lines (62 loc) · 1.4 KB
/
archive
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
#!/usr/bin/env bash
# Sane defaults.
set -euo pipefail
# Find scripts directory.
script="$0"
if test -L "$script"; then
script="$(readlink -f "$0")"
fi
prefix="$(dirname "$script")"
script="$(basename "$script")"
# Print the manual.
help() {
cat <<-EOF >&2
About
Generate add-on archive for given release tag.
Usage
$script -h
$script [-x] <tag>
Flags
-h Print this manual.
-x Enable debug mode.
EOF
}
# Parse and apply flags.
while getopts ":xh" option; do
case "$option" in
x)
set -x
;;
h)
help
exit
;;
?)
echo "$script: unknown flag '$OPTARG', try -h" >&2
exit
;;
esac
done
# Drop flags by shifting arguments.
shift $((OPTIND - 1))
# Test required arguments.
if test -z "$*"; then
echo "$script: missing required argument, see -h" >&2
exit
fi
# Release tag, e.g. Add-on/42.
tag="$1"
# Add-on absolute path, e.g. /Add-on.
target="$("$prefix/parse-tag" -a "$tag")"
# Add-on name, e.g. Add-on.
name="$("$prefix/inspect" -n "$target")"
# Add-on archive, e.g. Add-on-v42.zip.
archive="$("$prefix/inspect" -a "$target")"
# Distributable directory, e.g. ./dist.
dist="$target/dist"
# Make sure distributable directory exists.
mkdir -p "$dist"
# Git root directory.
root="$(git rev-parse --show-toplevel)"
# Generate add-on archive.
git archive --format=zip -o "$dist/$archive" --prefix="$name/" "$tag:${target#"$root/"}"