-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·74 lines (56 loc) · 2.03 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·74 lines (56 loc) · 2.03 KB
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
#!/bin/bash
set -euo pipefail
REPO="fthomys/check_cloudflared"
DIST_DIR="/var/www/packages.fthomys.me/debian"
ARCH="amd64"
: "${GPG_KEY_ID:?Please export GPG_KEY_ID first (e.g. export GPG_KEY_ID=ABCD1234)}"
WORKDIR=$(mktemp -d)
cleanup() {
echo "[*] Cleaning up $WORKDIR"
rm -rf "$WORKDIR"
}
trap cleanup EXIT
VERSION=$(curl -s https://api.github.com/repos/$REPO/releases/latest | jq -r .tag_name | sed 's/^v//')
if [[ -z "$VERSION" ]]; then
echo "Error: Could not determine version."
exit 1
fi
git clone --depth 1 --branch "v$VERSION" https://github.com/$REPO.git "$WORKDIR/src"
cd "$WORKDIR/src"
go build -o check_cloudflared
PKG_NAME="monitoring-check-cloudflared"
PKG_ROOT="${WORKDIR}/${PKG_NAME}_${VERSION}_$ARCH"
mkdir -p "$PKG_ROOT/DEBIAN"
mkdir -p "$PKG_ROOT/usr/lib/nagios/plugins"
cat > "$PKG_ROOT/DEBIAN/control" <<EOF
Package: $PKG_NAME
Version: $VERSION
Section: monitoring
Priority: optional
Architecture: $ARCH
Maintainer: Fabian Thomys <git@fthomys.me>
Description: Icinga plugin to check cloudflared installation and updates
Depends: curl
EOF
cp check_cloudflared "$PKG_ROOT/usr/lib/nagios/plugins/"
chmod 755 "$PKG_ROOT/usr/lib/nagios/plugins/check_cloudflared"
DEB_NAME="${PKG_NAME}_${VERSION}_${ARCH}.deb"
fakeroot dpkg-deb --build "$PKG_ROOT" "$WORKDIR/$DEB_NAME"
mkdir -p "$DIST_DIR/pool/"
mv "$WORKDIR/$DEB_NAME" "$DIST_DIR/pool/"
cd "$DIST_DIR"
mkdir -p dists/stable/main/binary-amd64
dpkg-scanpackages pool /dev/null > dists/stable/main/binary-amd64/Packages
gzip -c9 dists/stable/main/binary-amd64/Packages > dists/stable/main/binary-amd64/Packages.gz
cat > dists/stable/Release <<EOF
Origin: fthomys
Label: fthomys
Suite: stable
Codename: stable
Architectures: amd64
Components: main
EOF
gpg --batch --yes -abs -o dists/stable/Release.gpg --local-user "$GPG_KEY_ID" dists/stable/Release
gpg --batch --yes --clearsign -o dists/stable/InRelease --local-user "$GPG_KEY_ID" dists/stable/Release
gpg --armor --export "$GPG_KEY_ID" > "$DIST_DIR/fthomys.gpg.key"
echo "[✓] Version $VERSION built and published successfully!"