Skip to content

Commit fd19e62

Browse files
committed
Bump Debian version and polish script
1 parent e23931a commit fd19e62

File tree

5 files changed

+58
-33
lines changed

5 files changed

+58
-33
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
output

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM debian:stretch
1+
FROM debian:bullseye
22
LABEL maintainer "ant <git@manchestermonkey.co.uk>"
33

44
RUN apt-get update -qq && \

Makefile

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
SHELL = /bin/bash
22

3-
.PHONY: help build go
3+
.PHONY: help container package
44

55
.DEFAULT_GOAL = help
66

77
TOOL := "terraform"
88

99
help:
10-
@echo "You'll need to specify a thing to do:"
11-
@egrep '^(.+)\:\ ##\ (.+)' ${MAKEFILE_LIST} | column -t -c 2 -s ':#'
10+
@echo -e "\nYou'll need to specify a thing to do:\n"
11+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-\/]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
12+
@echo -e "\nSpecify "TOOL=" and/or "VERSION=" to override defaults\n"
1213

13-
build: ## - Build Docker image
14+
container: ## - Build Docker image to fetch and create packages
1415
@echo "[i] Building docker image"
1516
@docker build -t mcrmonkey/hashi-pkg .
1617

1718
output:
1819
@echo "[i] Creating output directory"
1920
@mkdir output
2021

21-
go: ## - Go get the tool. Specify "TOOL=" and/or "VERSION=" to override defaults
22+
package: ## - Download the tool and create a package
2223
@echo "[i] Getting ${TOOL}"
2324
@${MAKE} output
2425
@docker run -it --rm -e TOOL="${TOOL}" -e VERSION="${VERSION}" -v ${PWD}/output:/output mcrmonkey/hashi-pkg

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ To avoid adding extra junk to your system this makes use of a docker container w
2727
To build the image run the following on your system:
2828

2929
```shell
30-
make build
30+
make container
3131
```
3232

3333
To get the latest terraform and turn it in to a package run the following:
3434

3535
```shell
36-
make go
36+
make package
3737
```
3838

3939
To get an older version of terraform specify the version, like so:
4040

4141
```shell
42-
make VERSION="0.7.4" go
42+
make VERSION="0.7.4" package
4343
```
4444

4545
To specify an alternate tool specify the tool name, like so:
4646

4747
```shell
48-
make TOOL="packer" go
48+
make TOOL="packer" package
4949
```
5050

5151
The `TOOL` and `VERSION` can be specified together to get specific versions of tools.
@@ -58,7 +58,7 @@ If these variables are not specified it will default to getting and packaging th
5858
There are some things to be aware of:
5959

6060
* Due to the format of the changelog being different to what the RPM builder
61-
tool expects so is not included in the RPM package.
61+
tool expects the change log is not included in the RPM package.
6262
* The Docker image is probably a little larger than it should be due to the
63-
repo building tools that aren't currently used
63+
repo building tools that are included but aren't currently used
6464

prep-pkg.sh

+44-21
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,49 @@ set -e
44
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
55
trap 'if [ $? -ne 0 ]; then echo "\"${last_command}\" command filed with exit code $?."; fi' EXIT
66

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+
727

828
if [ ! -z $TOOL ]; then
929
TOOL=$TOOL
1030
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"
1232
TOOL="terraform"
1333
fi
1434

1535

1636
if [ ! -z $VERSION ]; then
1737
VERSION=$VERSION
1838
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"
2040
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')
2141
fi
2242

2343

2444
PLATF=${1:-linux}
2545
ARCH=${2:-amd64}
2646

47+
info "Preparing package for ${GREEN}${TOOL} ${VERSION}${NORM} for ${GREEN}${PLATF}${NORM} on ${GREEN}${ARCH}${NORM}...\n"
48+
49+
2750
URL="https://releases.hashicorp.com/${TOOL}/${VERSION}/${TOOL}_${VERSION}_${PLATF}_${ARCH}.zip"
2851
SHASUM="https://releases.hashicorp.com/${TOOL}/${VERSION}/${TOOL}_${VERSION}_SHA256SUMS"
2952
SHASUMSIG="${SHASUM}.sig"
@@ -35,35 +58,35 @@ OUTPATH="/output/${TOOL}"
3558

3659
mkdir -p ${EXPATH} ${OUTPATH}/{deb,rpm}
3760

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"
4063

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"
4366

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"
4669

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"
4972

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"
5275

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]"
5578

56-
echo -ne "Verifying SHA256SUM for ${TOOL}: "
79+
info "Verifying SHA256SUM for ${TOOL}: "
5780
sha256sum --ignore-missing -c ${TOOL}_${VERSION}_SHA256SUMS
5881

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"
6184

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"
6487

6588
# 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"
6891

6992

0 commit comments

Comments
 (0)