-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdeploy
executable file
·228 lines (184 loc) · 5.89 KB
/
deploy
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env bash
##--------------------------------------------------------------------
## Copyright (c) 2019 Dianomic Systems Inc.
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##--------------------------------------------------------------------
##
## Author: Mohd. Shariq
##
set -e
__version__="2.6.0"
if [ -f "package.json" ];
then
__version__=`cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[" ,]//g'`
fi
FLEDGE_GUI_VER=${__version__}
# Colors
CPFX="\033["
CRESET="${CPFX}0m" # Text Reset
CERR="${CPFX}1;31m"
CINFO="${CPFX}1;32m"
CWARN="${CPFX}0;33m"
echo -e "${CWARN}This script is partially done, please track https://github.com/fledge/fledge-gui/issues/73 ${CRESET}"
compat_msg="This script is compatible with Linux (Debian, Ubuntu and Raspberry Pi OS) Only!"
os=$(uname)
if [[ $os != "Linux" ]]; then
echo -e "${CERR}${compat_msg}${CRESET}"
exit 1;
fi
if [ -f /etc/os-release ]; then
n=$(cat /etc/os-release | grep -w PRETTY_NAME | cut -d= -f2- | tr -d '"')
if [[ $n == *"Raspbian"* ]] || [[ $n == *"Debian"* ]] || [[ $n == *"Ubuntu"* ]] ; then
echo -e "${CINFO}${n} ${CRESET}"
else
echo -e "${CWARN}${n} ${CRESET}"
echo -e "${CERR}${compat_msg} ${CRESET}"
exit 1;
fi
else
echo -e "${CERR}${compat_msg}${CRESET}"
exit 1;
fi
DOC_ROOT="/var/www/html"
echo -e WARNING: "${CWARN}This script will remove all the contents of ${DOC_ROOT} ${CRESET}"
read -p "Continue? Press n or N to exit." -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Nn]$ ]]
then
exit 0;
fi
machine_details() {
echo -e "${CINFO}Hostname : ${CRESET} ${HOSTNAME} "
internal_ip=$(hostname -I)
echo -e "${CINFO}IP : ${CRESET} ${internal_ip}"
}
memory_footprints(){
# Check RAM and SWAP Usages
rm -f /tmp/ramcache
free -h | grep -v + > /tmp/ramcache
echo -e "${CINFO}Memory Usages : ${CRESET}"
cat /tmp/ramcache
echo # new line
# Check Disk Usages on RPi
if [ -f /etc/os-release ]; then
n=$(cat /etc/os-release | grep -w PRETTY_NAME | cut -d= -f2-)
if [[ $n == *"Raspbian"* ]]; then
rm -f /tmp/diskusage
sudo fdisk -l| grep 'Device\|/dev/mmcblk0*' > /tmp/diskusage
echo -e "${CINFO}Disk Usages : ${CRESET}"
cat /tmp/diskusage
echo # new line
fi
fi
}
nginx_health(){
if ! which nginx > /dev/null 2>&1; then
echo -e "${CERR} Fledge GUI can not run, As Nginx(-light) is not installed.${CRESET}"
echo -e "${CINFO} Run ./deploy without any argument to install the fledge gui with nginx-light.${CRESET}"
else
machine_details
memory_footprints
nginx_version=$(nginx -v 2>&1)
echo -e INFO: "${CINFO}Found ${nginx_version}${CRESET}"
nginx_status=$(sudo service nginx status | grep active 2>&1)
echo -e "${CINFO}Status: ${nginx_status}${CRESET}"
echo "USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND"
ps aux -P | grep [n]ginx
fi
}
check_install_nginx () {
if ! which nginx > /dev/null 2>&1; then
echo -e WARNING: "${CWARN} Nginx not installed ${CRESET}"
yes Y | sudo apt-get install nginx-light
else
nginx_version=$(nginx -v 2>&1)
echo -e INFO: "${CINFO} Found ${nginx_version} ${CRESET}"
fi
}
install () {
check_install_nginx
sudo service nginx stop
# Download fledge-gui build artifacts i.e. dist directory compressed file
# url e.g. http://192.168.1.120/fledge-gui-${FLEDGE_GUI_VER}.tar.gz
# github release https://github.com/fledge/fledge-gui/releases/download/v1.2.0/fledge-gui-1.2.0.tar.gz
# wget ${BUILD_URL}
# FIXME: scp fledge-gui-${FLEDGE_GUI_VER}.tar.gz pi@<IP>:/home/pi
tar -zxvf fledge-gui-${FLEDGE_GUI_VER}.tar.gz
# put them into /var/www/html and start nginx
sudo rm -rf ${DOC_ROOT}/*
sudo mv dist/* ${DOC_ROOT}/.
sudo rm -rf dist
# FIXME: if --keep, then don't remove
sudo rm -rf fledge-gui-${FLEDGE_GUI_VER}.tar.gz
# sudo sed -i 's/dist/\/var\/www\/html/g' ${DOC_ROOT}/nginx.conf
sudo cp ${DOC_ROOT}/fledge.html ${DOC_ROOT}/index.html
sudo service nginx start
sudo service nginx status | grep "Active:"
echo -e "${CINFO} Done. ${CRESET}"
}
############################################################
# Usage text for this script
############################################################
USAGE="${__version__}
DESCRIPTION
This script installs fledge-gui with nginx-light
OPTIONS
Multiple commands can be specified but they all must be
specified separately (-hv is not supported).
-h, --help Display this help text
-v, --version Display this script's version information
EXAMPLE
$0 --version"
############################################################
# Execute the command specified in $OPTION
############################################################
execute_command() {
if [[ "$OPTION" == "HELP" ]]
then
echo "${USAGE}"
elif [[ "$OPTION" == "VERSION" ]]
then
echo $__version__
fi
}
start () {
machine_details
memory_footprints
./requirements
./build
install
memory_footprints
}
############################################################
# Process arguments
############################################################
if [ $# -gt 0 ]
then
for i in "$@"
do
case $i in
-h|--help)
OPTION="HELP"
;;
-v|--version)
OPTION="VERSION"
;;
*)
echo "Unrecognized option: $i"
esac
execute_command
done
else
start
fi