-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlinux-sugarchain-webwallet-en.sh
307 lines (268 loc) · 8.13 KB
/
linux-sugarchain-webwallet-en.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
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!/bin/bash
#disable bash history
set +o history
#color codes
RED='\033[1;31m'
YELLOW='\033[1;33m'
BLUE="\\033[38;5;27m"
SEA="\\033[38;5;49m"
GREEN='\033[1;32m'
CYAN='\033[1;36m'
NC='\033[0m'
dversion="v1.0"
CRTDIR=$(pwd)
ip=`curl --connect-timeout 10 -m 20 -s http://whatismyip.akamai.com/`
function string_limit_check_mark(){
if [[ -z "$2" ]]; then
string="$1"
string=${string::100}
else
string=$1
string_color=$2
string_leght=${#string}
string_leght_color=${#string_color}
string_diff=$((string_leght_color-string_leght))
string=${string_color::100+string_diff}
fi
echo -e "${ARROW}${CYAN}$string[${CHECK_MARK}√${CYAN}]${NC}"
}
function string_limit_x_mark(){
if [[ -z "$2" ]]; then
string="$1"
string=${string::50}
else
string=$1
string_color=$2
string_leght=${#string}
string_leght_color=${#string_color}
string_diff=$((string_leght_color-string_leght))
string=${string_color::50+string_diff}
fi
echo -e "${ARROW}${CYAN}$string[${CHECK_MARK}${RED}×${CYAN}]${NC}"
}
function Start_sugar_webwallet(){
CRON_LINE="cd sugarchain-web-wallet && pm2 start ./bin/www --name sugarchain-web-wallet"
CRON_EXISTS=$(crontab -l | grep "$CRON_LINE" | wc -l)
if [ $CRON_EXISTS -eq 0 ]
then
crontab -l | { cat; echo "@reboot $CRON_LINE"; } | crontab -
string_limit_check_mark "Startup task completed........." "Startup task completed.........${GREEN}${CYAN} ........."
else
string_limit_check_mark "Startup task already exists........." "Startup task already exists${GREEN}${CYAN} ........."
fi
#install nvm
if ! nvm --version > /dev/null 2>&1; then
echo -e "${ARROW} ${YELLOW}Installing nvm ....${NC}"
unset NVM_DIR
cd
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.9/install.sh | bash
source /etc/profile
profile_LINE="NVM_DIR/nvm.sh"
profile_EXISTS=$(cat /etc/profile | grep "$profile_LINE" | wc -l)
if [ $profile_EXISTS -eq 0 ]
then
echo 'export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> /etc/profile
source /etc/profile
string_limit_check_mark "Write successful........." "Write successful${GREEN}${CYAN} ........."
fi
source /etc/profile
fi
#install node
if ! node -v > /dev/null 2>&1; then
echo -e "${ARROW} ${YELLOW}Installing node ....${NC}"
nvm install v12.14.0
fi
if [[ ! -d ${CRTDIR}/sugarchain-web-wallet ]]; then
git clone https://github.com/bailaoshijiadao/sugarchain-web-wallet
fi
pm2 save --force
pm2_flag=`pm2 list`
if [[ $pm2_flag =~ "sugarchain-web-wallet" ]]; then
echo -e "${ARROW} ${YELLOW}sugarchain-web-wallet already exists....${NC}"
string_limit_check_mark "http://$ip:3088" "http://$ip:3088${GREEN}${CYAN} ......"
else
cd sugarchain-web-wallet
npm install
npm install pm2 -g
pm2 start ./bin/www --name sugarchain-web-wallet
pm2 startup
string_limit_check_mark "http://$ip:3088" "http://$ip:3088${GREEN}${CYAN} ......"
fi
}
function install_step(){
if ! figlet -v > /dev/null 2>&1; then
echo -e "${ARROW} ${YELLOW}Installing figlet ....${NC}"
sudo $* install -y figlet
fi
#install JQ
if ! jq --version > /dev/null 2>&1; then
echo -e "${ARROW} ${YELLOW}Installing JQ ....${NC}"
sudo $* install -y jq > /dev/null 2>&1
fi
if ! screen -v > /dev/null 2>&1; then
echo -e "${ARROW} ${YELLOW}Installing screen ....${NC}"
sudo $* install -y screen > /dev/null 2>&1
fi
if ! wget --version > /dev/null 2>&1; then
echo -e "${ARROW} ${YELLOW}Installing wget ....${NC}"
sudo $* install -y wget > /dev/null 2>&1
fi
if ! git --version > /dev/null 2>&1; then
echo -e "${ARROW} ${YELLOW}Installing git ....${NC}"
sudo $* install -y git > /dev/null 2>&1
fi
}
function webwallet_domain(){
read -p "input your domain,For example wallet.example.com: " domain
#Ubuntu
if [[ -f /etc/issue ]]; then
system_v=$(cat /etc/issue)
if [[ $system_v =~ "Ubuntu" ]]; then
echo -e "${YELLOW}apt${NC}"
sudo apt-get update
sudo apt install nginx snapd -y
fi
fi
#Centos
if [[ -f /etc/centos-release ]]; then
echo -e "${YELLOW}yum${NC}"
sudo yum install nginx -y
else
if [[ -f /etc/redhat-release ]]; then
echo -e "${YELLOW}yum${NC}"
sudo yum install nginx snapd -y
fi
fi
sudo unlink /etc/nginx/sites-enabled/$domain.conf
rm -rf /etc/nginx/sites-available/$domain.conf
if [[ ! -f /etc/nginx/sites-available/$domain.conf ]]; then
cat << EOF > /etc/nginx/sites-available/$domain.conf
server {
server_name $domain;
location / {
proxy_pass http://localhost:3088;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
}
location /socket.io {
include proxy_params;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://127.0.0.1:3088/socket.io;
}
listen 80;
}
EOF
fi
sudo ln -s /etc/nginx/sites-available/$domain.conf /etc/nginx/sites-enabled
sudo snap install --classic certbot
sudo certbot --nginx -d $domain
string_limit_check_mark "https://$domain" "https://$domain${GREEN}${CYAN} ......"
}
if ! node -version > /dev/null 2>&1 ; then
#Ubuntu
if [[ -f /etc/issue ]]; then
system_v=$(cat /etc/issue)
if [[ $system_v =~ "Ubuntu" ]]; then
echo -e "${YELLOW}apt${NC}"
sudo apt-get update
install_step apt
fi
fi
#Centos
if [[ -f /etc/centos-release ]]; then
echo -e "${YELLOW}yum${NC}"
install_step yum
else
if [[ -f /etc/redhat-release ]]; then
echo -e "${YELLOW}yum${NC}"
install_step yum
fi
fi
#Centos换源
if [[ -f /etc/centos-release ]]; then
if ! jq --version > /dev/null 2>&1; then
mv /etc/yum.repos.d /etc/yum.repos.d.bak
mkdir -p /etc/yum.repos.d
curl https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo > /etc/yum.repos.d/Centos-vault-8.5.2111.repo
curl https://mirrors.aliyun.com/repo/epel-archive-8.repo > /etc/yum.repos.d/epel-archive-8.repo
yum clean all && yum makecache
fi
install_step yum
else
if [[ -f /etc/redhat-release ]]; then
if ! jq --version > /dev/null 2>&1; then
mv /etc/yum.repos.d /etc/yum.repos.d.bak
mkdir -p /etc/yum.repos.d
curl https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo > /etc/yum.repos.d/Centos-vault-8.5.2111.repo
curl https://mirrors.aliyun.com/repo/epel-archive-8.repo > /etc/yum.repos.d/epel-archive-8.repo
yum clean all && yum makecache
fi
install_step yum
fi
fi
fi
while :
do
sleep 1
echo -e "${BLUE}"
figlet -f big "SugarChain"
echo -e "${YELLOW}===========================================================${NC}"
echo -e "${GREEN}Version: $dversion${NC}"
echo -e "${GREEN}System: Linux Ubuntu Centos${NC}"
echo -e "${GREEN}Author: bailaoshi${NC}"
echo -e "${YELLOW}===========================================================${NC}"
echo -e "${CYAN}1 - Start SugarChain Web wallet[Including installation process]${NC}"
echo -e "${CYAN}2 - View the usage of Web wallet resources${NC}"
echo -e "${CYAN}3 - Delete Web wallet PM2 application${NC}"
echo -e "${CYAN}4 - Web wallet startOrReload${NC}"
echo -e "${CYAN}5 - View Web wallet logs${NC}"
echo -e "${CYAN}6 - View Web wallet details${NC}"
echo -e "${CYAN}7 - Stop SugarChain Web wallet${NC}"
echo -e "${CYAN}8 - Set your domain${NC}"
echo -e "${YELLOW}===========================================================${NC}"
echo -e "${YELLOW}******SugarChain Web wallet script******${NC}"
echo -e "${YELLOW}Sponsorship address: sugar1q8d79pk0jyhl92jrmfsrpvuwwg9ycsr20xz93rz(bailaoshi)${NC}"
read -rp "Please enter a numerical option and press Enter: "
case "$REPLY" in
1)
sleep 2
Start_sugar_webwallet
;;
2)
sleep 2
pm2 monit
;;
3)
sleep 2
pm2 delete sugarchain-web-wallet
;;
4)
sleep 2
pm2 startOrReload sugarchain-web-wallet
;;
5)
sleep 2
pm2 logs sugarchain-web-wallet
;;
6)
sleep 2
pm2 show sugarchain-web-wallet
;;
7)
sleep 2
pm2 stop sugarchain-web-wallet
;;
8)
sleep 2
webwallet_domain
;;
esac
done