-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·182 lines (138 loc) · 3.52 KB
/
setup
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
#!/bin/bash
Check for administrator user
if [ `id -u` != 0 ]; then
echo "Run with administrator user (sudo)"
exit 1;
fi
APPNAME="Forever GUI"
APPFOLDER="forever-gui"
APPMODULESFOLDER="app_modules"
NODEINSTALLPATH="/usr/local/lib/node_modules"
CONFIGFILE="config.json"
ACCOUNTSFILE="accounts.json"
S=" "
L="$S =============================================================="
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function md5it {
if builtin command -v md5 > /dev/null; then
echo "$1" | md5
elif builtin command -v md5sum > /dev/null ; then
echo "$1" | md5sum | awk '{print $1}'
else
rvm_error "Neither md5 nor md5sum were found in the PATH"
return 1
fi
return 0
}
function PromptDomain {
while true; do
read -p "$S Specify domain (without http://) or IP: " DOMAIN
# Removed because some servers may use only IP
#
# validDomain=`echo $DOMAIN | egrep "([a-z0-9_-]+)\.([a-zA-Z\.]){2,7}"`
# if [ ! -z "$validDomain" ]; then
# break;
if [ ! -z "$DOMAIN" ]; then
break;
else
echo ""
echo "$S Please write a valid domain"
echo ""
fi
done
}
function PromptPort {
while true; do
read -p "$S Specify port for $DOMAIN [443]: " PORT
portRegex='^[0-9]{2,5}$'
if [[ $PORT =~ $portRegex ]]; then
break;
else
PORT=443
echo "$S Port is set to $PORT because specified port is not matching the pattern [0-9]{2,5}"
break;
fi
done
}
function PromptUsername {
while true; do
read -p "$S Specify Administrator username: " ADMIN_USER
loginRegex='^[a-zA-Z0-9_-]{5,16}$'
if [[ $ADMIN_USER =~ $loginRegex ]]; then
break;
else
echo ""
echo "$S Please use a proper username"
echo "$S Accepted characters: [a-zA-Z0-9_-] and length between 5 and 16 symbols"
echo ""
fi
done
}
function PromptPassword {
while true; do
read -s -p "$S Specify Administrator password: " ADMIN_PASS
validPass=`echo "$ADMIN_PASS" | egrep "[a-z]" | egrep "[A-Z]" | egrep "([a-zA-Z0-9@#-_$]){6,100}"`
if [ ! -z "$validPass" ]; then
echo ""
break;
else
echo ""
echo "$S Please use stronger password."
echo "$S Required at least one lower case letter [a-z], at least one upper case [A-Z] letter."
echo "$S Accepted characters: a-zA-Z0-9@#-_$"
echo ""
fi
done
# Prompt for Repeat Password
while true; do
read -s -p "$S Repeat password: " ADMIN_PASS2
if [ $ADMIN_PASS = $ADMIN_PASS2 ]; then
echo ""
break;
else
echo ""
echo "$S Passwords do not match"
echo ""
PromptPassword
break;
fi
done
}
function SetupFiles {
echo "$S Preparing for installation of app files"
mkdir -p "$NODEINSTALLPATH" || { exit 1; }
echo "$S Moving files to app directory"
cp -R "$SCRIPT/$APPFOLDER" "$NODEINSTALLPATH/" || { exit 1; }
}
function SaveSettings {
ENCRYPTED_PASS=$(md5it "$ADMIN_PASS")
printf '{"domain":"%s","port":"%s"}' "$DOMAIN" "$PORT" > "$NODEINSTALLPATH/$APPFOLDER/$APPMODULESFOLDER/$CONFIGFILE"
printf '{"%s":"%s"}' "$ADMIN_USER" "$ENCRYPTED_PASS" > "$NODEINSTALLPATH/$APPFOLDER/$APPMODULESFOLDER/$ACCOUNTSFILE"
}
case "$1" in
install)
echo ""
echo "$S Installaton of $APPNAME has started"
echo ""
echo "$L"
echo ""
PromptDomain
PromptPort
PromptUsername
PromptPassword
SetupFiles
SaveSettings
echo ""
echo "$L"
echo ""
echo "$S The $APPNAME will be available at url https://$DOMAIN:$PORT"
echo "$S You can login with username $ADMIN_USER and the specified password"
echo ""
;;
help)
echo "Help information [TODO]"
;;
*)
echo "Usage: {install|help}"
;;
esac