-
Notifications
You must be signed in to change notification settings - Fork 7
/
make-archive
executable file
·102 lines (98 loc) · 2.48 KB
/
make-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
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/sh
set -e
usage() {
status="${1}"
if [ "${status}" -eq 0 ] ; then
out=/dev/stdout
else
out=/dev/stderr
fi
{
echo "usage: make-archive [--origin ORIGIN] \\"
echo " [--test VERSION [GNUEFI_GIT_TAG]"
echo " |--release VERSION CERTWRAPPER_GIT_TAG GNUEFI_GIT_TAG]"
} >>"${out}"
exit "${status}"
}
main() {
VERSION=""
CERTWRAPPER_GIT_TAG=""
GNUEFI_GIT_TAG=""
ORIGIN="origin"
while [ $# -ne 0 ] ; do
case "$1" in
--help|--usage|-h|"-?")
usage 0
;;
--origin)
if [ $# -lt 2 ] ; then
echo "error: missing origin" >>/dev/stderr
usage 1
fi
ORIGIN="${2}"
shift
;;
--test)
if [ $# -lt 2 ] ; then
echo "error: missing version" >>/dev/stderr
usage 1
fi
VERSION="${2}"
if [ $# -gt 2 ] ; then
GNUEFI_GIT_TAG="${3}"
shift
fi
shift
;;
--release)
if [ $# -lt 2 ] ; then
echo "error: missing version" >>/dev/stderr
usage 1
fi
if [ $# -lt 3 ] ; then
echo "error: missing certwrapper git tag" >>/dev/stderr
usage 1
fi
if [ $# -lt 4 ] ; then
echo "error: missing gnuefi git tag" >>/dev/stderr
usage 1
fi
VERSION="${2}"
CERTWRAPPER_GIT_TAG="${3}"
GNUEFI_GIT_TAG="${4}"
shift
shift
shift
;;
*)
echo unknown argument "\"$1\"" >>/dev/stderr
usage 1
;;
esac
shift
done
ARCHIVE_DIR="$(mktemp -d)"
rm -rf "${ARCHIVE_DIR}/certwrapper-${VERSION}" "${ARCHIVE_DIR}/certwrapper-${VERSION}"
mkdir -p "${ARCHIVE_DIR}/certwrapper-${VERSION}/gnu-efi"
cd gnu-efi || exit 1
if [ "x" = "x${GNUEFI_GIT_TAG}" ] ; then
git archive --format=tar "$(git log -1 --pretty=format:%h)" | ( cd "${ARCHIVE_DIR}/certwrapper-${VERSION}/gnu-efi" ; tar x )
else
git archive --format=tar "${ORIGIN}/${GNUEFI_GIT_TAG}" | ( cd "${ARCHIVE_DIR}/certwrapper-${VERSION}/gnu-efi" ; tar x )
fi
cd ..
if [ "x" = "x${CERTWRAPPER_GIT_TAG}" ] ; then
git archive --format=tar "$(git log -1 --pretty=format:%h)" | ( cd "${ARCHIVE_DIR}/certwrapper-${VERSION}" ; tar x )
else
# ORIGIN doesn't yet have this tag
git archive --format=tar "${CERTWRAPPER_GIT_TAG}" | ( cd "${ARCHIVE_DIR}/certwrapper-${VERSION}" ; tar x )
fi
git log -1 --pretty=format:%H > "${ARCHIVE_DIR}/certwrapper-${VERSION}/commit"
DIR="$PWD"
cd "${ARCHIVE_DIR}"
tar -c --bzip2 -f "${DIR}/certwrapper-${VERSION}.tar.bz2" "certwrapper-${VERSION}"
rm -rf "${ARCHIVE_DIR}"
echo "The archive is in certwrapper-${VERSION}.tar.bz2"
exit 0
}
main "${@}"