-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenkins.sh
executable file
·73 lines (56 loc) · 1.73 KB
/
genkins.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
ACTION='\033[1;90m'
FINISHED='\033[1;96m'
READY='\033[1;92m'
NOCOLOR='\033[0m' # No Color
ERROR='\033[0;31m'
TIMESTAMP=$(date)
echo
echo -e ${ACTION}Running build script at ${TIMESTAMP}${NOCOLOR}
# Check for git updates
echo
echo -e ${ACTION}Checking Git repo
echo -e =======================${NOCOLOR}
BRANCH=$(sudo -u guy git rev-parse --abbrev-ref HEAD)
if [ "$BRANCH" != "master" ] ; then
echo -e ${ERROR}Not on master. Aborting. ${NOCOLOR}
echo
exit 0
fi
sudo -u guy git fetch
HEADHASH=$(sudo -u guy git rev-parse HEAD)
UPSTREAMHASH=$(sudo -u guy git rev-parse master@{upstream})
if [ "$HEADHASH" != "$UPSTREAMHASH" ] ; then
echo -e ${ACTION}Not up to date with origin. Pull from remote${NOCOLOR}
else
echo -e ${FINISHED}Current branch is up to date with origin/master.${NOCOLOR}
exit 0
fi
PULLRESULT=$(sudo -u guy git pull)
if [ "$PULLRESULT" = "Already up to date." ] ; then
echo -e ${FINISHED}Current branch is up to date with origin/master.${NOCOLOR}
exit 0
fi
echo -e ${ACTION}Building code...${NOCOLOR}
MAKERESULT=$(sudo -u guy make)
if [ "$MAKERESULT" = "make: Nothing to be done for \`all\'." ] ; then
echo -e ${FINISHED}make - Nothing to build.${NOCOLOR}
exit 0
fi
if [ $? -ne 0 ] ; then
echo -e ${ERROR}Build failed. Aborting. ${NOCOLOR}
exit 0
fi
echo -e ${ACTION}Build succeeded${NOCOLOR}
# Stop the process...
echo -e ${ACTION}Stopping wctl service...${NOCOLOR}
systemctl stop weatherctl
echo -e ${ACTION}Installing new version...${NOCOLOR}
make install
if [ $? -ne 0 ] ; then
echo -e ${ERROR}Failed to install new version. Aborting. ${NOCOLOR}
exit 0
fi
# Restart the process...
echo -e ${ACTION}Restarting wctl service...${NOCOLOR}
systemctl start weatherctl