-
Notifications
You must be signed in to change notification settings - Fork 1
/
webhook.sh
39 lines (31 loc) · 1.44 KB
/
webhook.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
#!/bin/bash
## Install a version of this script to deploy to a ubuntu server via a webhook
# exit on errors
set -e
# Set this to the branch you want to build
# Note: A future version of this script could get the code from a param from webhook
export GIT_BRANCH="main"
export DEB_BUILD_VERSION=0.99 # Use a static version for the deb package, so we know what version to install in the webhook
export LOGFILE="/var/log/webhook/notify.log"
echo "Building Notify" >> $LOGFILE
id >> $LOGFILE
cd /home/notify/notify/
LOCKFILE=/tmp/notify-webhook-lock
if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
# NOTE: Because we are exiting here, we can potentially skip builds if there are multiple commits in quick succession
echo "Script Already running" >> $LOGFILE 2>&1
echo "Script Already running"
exit
fi
# make sure the lockfile is removed when we exit and then claim it
trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT
echo $$ > ${LOCKFILE}
if [ "$(id -u)" = "0" ]; then
echo "Running as root. Switching to notify user..."
sudo -S -u notify GIT_BRANCH=$GIT_BRANCH DEB_BUILD_VERSION=$DEB_BUILD_VERSION bash -i -c "cd /home/notify/notify/; ./build_deb_package.sh" >> $LOGFILE 2>&1
else
echo "Not running as root."
time ./build_deb_test_package.sh >> $LOGFILE 2>&1
fi
sudo apt -qq --allow-downgrades --reinstall install -y /home/notify/notify/backend/target/debian/notify-server_${DEB_BUILD_VERSION}_amd64.deb >> $LOGFILE 2>&1
rm -f ${LOCKFILE}