4
4
trap ' last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
5
5
trap ' if [ $? -ne 0 ]; then echo "\"${last_command}\" command filed with exit code $?."; fi' EXIT
6
6
7
+ BLUE=" \033[01;34m"
8
+ YELLOW=" \033[01;33m"
9
+ GREEN=" \033[01;32m"
10
+ RED=" \033[01;31m"
11
+ NORM=" \033[00m"
12
+
13
+
14
+ error () {
15
+ echo -en " \n${RED} [!]${NORM} ${1} \n"
16
+ exit 1
17
+ }
18
+
19
+ warn () {
20
+ echo -en " \n${YELLOW} [w]${NORM} ${1} "
21
+ }
22
+
23
+ info () {
24
+ echo -en " \n${BLUE} [i]${NORM} ${1} "
25
+ }
26
+
7
27
8
28
if [ ! -z $TOOL ]; then
9
29
TOOL=$TOOL
10
30
else
11
- echo -e " [w] Tool name not set Use Envvar 'TOOL' Defaulting to: terraform"
31
+ warn " Variable ' \$ TOOL' not set, Defaulting to: terraform\n "
12
32
TOOL=" terraform"
13
33
fi
14
34
15
35
16
36
if [ ! -z $VERSION ]; then
17
37
VERSION=$VERSION
18
38
else
19
- echo -e " [w] No version set, use Envvar 'VERSION' Defaulting to latest version for ${TOOL} "
39
+ warn " Variable ' \$ VERSION' not set, Defaulting to latest version for ${TOOL} \n "
20
40
VERSION=$( curl --fail --silent --location " https://api.github.com/repos/hashicorp/${TOOL} /tags" | grep ' "name":' | sed -E ' s/.*"([^"]+)".*/\1/' | head -n 1| tr -d ' v' )
21
41
fi
22
42
23
43
24
44
PLATF=${1:- linux}
25
45
ARCH=${2:- amd64}
26
46
47
+ info " Preparing package for ${GREEN}${TOOL} ${VERSION}${NORM} for ${GREEN}${PLATF}${NORM} on ${GREEN}${ARCH}${NORM} ...\n"
48
+
49
+
27
50
URL=" https://releases.hashicorp.com/${TOOL} /${VERSION} /${TOOL} _${VERSION} _${PLATF} _${ARCH} .zip"
28
51
SHASUM=" https://releases.hashicorp.com/${TOOL} /${VERSION} /${TOOL} _${VERSION} _SHA256SUMS"
29
52
SHASUMSIG=" ${SHASUM} .sig"
@@ -35,35 +58,35 @@ OUTPATH="/output/${TOOL}"
35
58
36
59
mkdir -p ${EXPATH} ${OUTPATH} /{deb,rpm}
37
60
38
- echo -ne " Importing Hashicorp GPG key from keybase: "
39
- curl -s ${HASHIGPG} | gpg --import - > /dev/null 2>&1 && echo " [OK]" || echo " ERROR"
61
+ info " Importing Hashicorp GPG key from keybase: "
62
+ curl -s ${HASHIGPG} | gpg --import - > /dev/null 2>&1 && echo -n " [OK]" || error " ERROR"
40
63
41
- echo -ne " Getting ${TOOL} ${VERSION} : "
42
- wget $URL > /dev/null 2>&1 && echo " [OK]" || echo " ERROR"
64
+ info " Getting ${TOOL} ${VERSION} : "
65
+ wget $URL > /dev/null 2>&1 && echo -n " [OK]" || error " ERROR"
43
66
44
- echo -ne " Getting changelog for ${VERSION} : "
45
- wget -O " /tf/${VERSION} /changelog.md" ${CHANGELOGURL} > /dev/null 2>&1 && echo " [OK]" || echo " ERROR"
67
+ info " Getting changelog for ${VERSION} : "
68
+ wget -O " /tf/${VERSION} /changelog.md" ${CHANGELOGURL} > /dev/null 2>&1 && echo -n " [OK]" || error " ERROR"
46
69
47
- echo -ne " Getting SHASUM file for ${TOOL} : "
48
- wget ${SHASUM} > /dev/null 2>&1 && echo " [OK]" || echo " ERROR"
70
+ info " Getting SHASUM file for ${TOOL} : "
71
+ wget ${SHASUM} > /dev/null 2>&1 && echo -n " [OK]" || error " ERROR"
49
72
50
- echo -ne " Getting SHASUM sig file for ${TOOL} : "
51
- wget ${SHASUMSIG} > /dev/null 2>&1 && echo " [OK]" || echo " ERROR"
73
+ info " Getting SHASUM sig file for ${TOOL} : "
74
+ wget ${SHASUMSIG} > /dev/null 2>&1 && echo -n " [OK]" || error " ERROR"
52
75
53
- echo -ne " Verify GPG signature for SHA256SUM file: "
54
- gpg --verify ${TOOL} _${VERSION} _SHA256SUMS.sig ${TOOL} _${VERSION} _SHA256SUMS > /dev/null 2>&1 && echo " [OK]"
76
+ info " Verify GPG signature for SHA256SUM file: "
77
+ gpg --verify ${TOOL} _${VERSION} _SHA256SUMS.sig ${TOOL} _${VERSION} _SHA256SUMS > /dev/null 2>&1 && echo -n " [OK]"
55
78
56
- echo -ne " Verifying SHA256SUM for ${TOOL} : "
79
+ info " Verifying SHA256SUM for ${TOOL} : "
57
80
sha256sum --ignore-missing -c ${TOOL} _${VERSION} _SHA256SUMS
58
81
59
- echo -ne " Unzipping ${TOOL} ${VERSION} : "
60
- unzip -o -qq ${TOOL} _${VERSION} _${PLATF} _${ARCH} .zip -d ${EXPATH} && rm -Rf ${VERSION} .zip > /dev/null 2>&1 && echo " [OK]" || echo " ERROR"
82
+ info " Unzipping ${TOOL} ${VERSION} : "
83
+ unzip -o -qq ${TOOL} _${VERSION} _${PLATF} _${ARCH} .zip -d ${EXPATH} && rm -Rf ${VERSION} .zip > /dev/null 2>&1 && echo -n " [OK]" || error " ERROR"
61
84
62
- echo -ne " Creating deb Package: "
63
- fpm -s dir -t deb -n ${TOOL} -v ${VERSION} -a ${ARCH} --deb-changelog /tf/${VERSION} /changelog.md -p ${OUTPATH} /deb ${EXPATH} /=/usr/bin > /dev/null 2>&1 && echo " [OK]" || echo " ERROR"
85
+ info " Creating deb Package: "
86
+ fpm -s dir -t deb -n ${TOOL} -v ${VERSION} -a ${ARCH} --deb-changelog /tf/${VERSION} /changelog.md -p ${OUTPATH} /deb ${EXPATH} /=/usr/bin > /dev/null 2>&1 && echo " [OK]" || error " ERROR"
64
87
65
88
# Changelog omitted from RPM because not correct format
66
- echo -ne " Creating RPM Package: "
67
- fpm -s dir -t rpm -n ${TOOL} -v ${VERSION} -a ${ARCH} -p ${OUTPATH} /rpm ${EXPATH} /=/usr/bin > /dev/null 2>&1 && echo " [OK]" || echo " ERROR"
89
+ info " Creating RPM Package: "
90
+ fpm -s dir -t rpm -n ${TOOL} -v ${VERSION} -a ${ARCH} -p ${OUTPATH} /rpm ${EXPATH} /=/usr/bin > /dev/null 2>&1 && echo -en " [OK]\n " || error " ERROR"
68
91
69
92
0 commit comments