forked from fledge-iot/fledge-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-rh
executable file
·244 lines (197 loc) · 6.33 KB
/
deploy-rh
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/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 Red Hat Linux 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 == *"Red Hat"* ]] || [[ $n == *"CentOS"* ]]; 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="/usr/share/nginx/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
rm -f /tmp/diskusage
df -T -h > /tmp/diskusage
echo -e "${CINFO}Disk Usages : ${CRESET}"
cat /tmp/diskusage
echo # new line
}
nginx_health(){
if ! which nginx > /dev/null 2>&1; then
echo -e "${CERR} Fledge GUI can not run, As Nginx is not installed.${CRESET}"
echo -e "${CINFO} Run ./deploy-rh without any argument to install the fledge gui with nginx.${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
}
install_epel () {
echo -e INFO: "${CINFO} Installing epel-release ... ${CRESET}"
sudo rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum -y update
sudo yum -y install epel-release
}
check_install_nginx () {
if ! which nginx > /dev/null 2>&1; then
echo -e WARNING: "${CWARN} Nginx not installed! ${CRESET}"
if rpm -q epel-release > /dev/null 2>&1;
then
sudo yum remove epel-release*.noarch
sudo rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
else
install_epel
fi
EPEL=$(rpm -qa | grep epel)
echo $EPEL
echo -e INFO: "${CINFO} Installing nginx ... ${CRESET}"
sudo yum -y install nginx
else
nginx_version=$(nginx -v 2>&1)
echo -e INFO: "${CINFO} Found ${nginx_version} ${CRESET}"
fi
}
install () {
check_install_nginx
sudo systemctl stop nginx
# 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/user
tar -zxvf fledge-gui-${FLEDGE_GUI_VER}.tar.gz
# put them into /usr/share/nginx/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/\/usr\/share\/nginx\/html/g' ${DOC_ROOT}/nginx.conf
sudo cp ${DOC_ROOT}/fledge.html ${DOC_ROOT}/index.html
restorecon -v ${DOC_ROOT}/* | grep fledge.html
sudo systemctl start nginx
sudo systemctl status nginx | 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
-H, --health, --dry-run Run health check for nginx
-L, --local Deploy on local with an internal call to ./build
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