-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.bash
112 lines (103 loc) · 2.9 KB
/
deploy.bash
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
# Build and deploy a new version to the remote device
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
re_ip='^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'
re_ip_user='^.+@[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'
IP_LIST=""
MVN_SETTINGS_FILE=""
RESTART=0
while test $# -gt 0
do
case "$1" in
-h)
shift
echo "Usage: ./deploy.bash [-H IP | -H USER@IP]... [-R] :q[-s SETTINGS_FILE] [-v VERSION]"
echo " -h Show this help message"
echo " -H IP Specify a host with username pi"
echo " -H USER@IP Specify a host with a different username"
echo " -R Restart the remote host instead of just restarting the service"
echo " -s Specify a maven settings file"
echo " -v Specify a specific version of animatedledstrip to build"
exit
;;
-H)
shift
if test $# -gt 0
then
if [[ $1 =~ $re_ip_user ]]
then
IP_LIST="${IP_LIST} $1"
elif [[ $1 =~ $re_ip ]]
then
IP_LIST="${IP_LIST} pi@$1"
else
echo "Invalid IP: $1"
fi
shift
fi
;;
-R)
shift
RESTART=1
;;
-s)
shift
if test $# -gt 0
then
MVN_SETTINGS_FILE=$1
shift
fi
;;
-v)
shift
if test $# -gt 0
then
ALS_VERSION=$1
shift
fi
;;
esac
done
if [[ ${MVN_SETTINGS_FILE} != "" ]]
then
MVN_SETTINGS_FILE="-gs ${MVN_SETTINGS_FILE}"
fi
if [[ ${ALS_VERSION} != "" ]]
then
ALS_VERSION="-PanimatedledstripServerVersion=${ALS_VERSION}"
# else
# echo "ERROR"
# exit 1
fi
# shellcheck disable=SC2086
./gradlew shadowJar ${ALS_VERSION} --console plain
mv build/libs/animatedledstrip-server-pi-1.0-all.jar build/libs/animatedledstrip-server-pi-1.0.jar
# shellcheck disable=SC2181
if [[ $? != 0 ]]
then
echo "Gradle build failed"
exit
else
echo "Gradle build successful, continuing to deployment..."
fi
if [[ ${IP_LIST} == "" ]]
then
echo "No hosts specified"
else
echo "Hosts: ${IP_LIST}"
for host in ${IP_LIST}
do
echo "${host}"
if [[ ${host} != "" ]]
then
scp "${DIR}"/build/libs/animatedledstrip-server-pi-1.0.jar "${host}":ledserver.jar
ssh "${host}" -t "sudo cp ledserver.jar /usr/local/leds/ledserver.jar"
if [[ ${RESTART} == 1 ]]
then
ssh "${host}" -t "sudo reboot"
else
ssh "${host}" -t "sudo systemctl restart ledserver"
fi
fi
done
fi