This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathrelease.sh
executable file
·59 lines (50 loc) · 1.91 KB
/
release.sh
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
#!/usr/bin/env bash
CURL='/usr/bin/env curl'
JQ='/usr/bin/env jq'
PACKER='/usr/bin/env packer'
RE='^[0-9]+([.][0-9]+)?$'
FIND='/usr/bin/env find'
IMAGES="centos-7.6-x86_64
ubuntu-18.04-amd64"
BUILDERS="virtualbox-iso"
echo "Removing old files in output dirs"
FILES=$($FIND ./output-* -type f -print)
for FILE in $FILES; do
echo "Removing $FILE"
rm -f $FILE
done
echo "Please enter your GitHub personal access token (we don't save it):"
read -s TOKEN
LATEST_TAG=$($CURL -s https://api.github.com/repos/librenms/librenms/releases/latest | $JQ -r ".tag_name")
if ! [[ "$LATEST_TAG" =~ $RE ]] ; then
echo "Tag not found"; exit 1;
fi
echo "Tag $LATEST_TAG, found, building images"
for IMAGE in $IMAGES; do
for BUILDER in $BUILDERS; do
echo "Building $IMAGE with $BUILDER"
BUILD=$($PACKER build -force -only=$BUILDER -var "librenms_version=$LATEST_TAG" -var 'headless=true' $IMAGE.json)
if [ $? != 0 ] ; then
echo "Build failed:"
echo $BUILD
else
echo "Build completed"
fi
done
done
echo "Creating new release $LATEST_TAG"
UPLOAD_URL=$($CURL -s https://api.github.com/repos/librenms/packer-builds/releases -H "Authorization: token $TOKEN" -X POST --header "Content-Type: application/json" -d "{\"tag_name\":\"$LATEST_TAG\",\"name\":\"v$LATEST_TAG\"}" | $JQ -r ".upload_url")
UPLOAD_URL="${UPLOAD_URL//\{\?name,label\}/}"
FILES=$($FIND ./output-* -type f -print)
for FILE in $FILES; do
IFS='/' read -a OVA <<< "$FILE"
NAME=${OVA[2]}
echo "$CURL -s \"$UPLOAD_URL?name=$NAME\" -H \"Authorization: token <TOKEN>\" --data-binary @\"$FILE\" -H \"Content-Type: application/tar\""
UPLOAD=$($CURL -s "$UPLOAD_URL?name=$NAME" -H "Authorization: token $TOKEN" --data-binary @"$FILE" -H "Content-Type: application/tar")
if [ $? != 0 ] ; then
echo "Upload failed:"
echo $UPLOAD
else
echo "Upload completed"
fi
done