-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathg.sh
152 lines (143 loc) · 5.39 KB
/
g.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
#!/bin/bash
# FROM
# https://github.com/spiritLHLS/gaganode-one-click-command-installation
# 2023.12.26
utf8_locale=$(locale -a 2>/dev/null | grep -i -m 1 -E "UTF-8|utf8")
if [[ -z "$utf8_locale" ]]; then
echo "No UTF-8 locale found"
else
export LC_ALL="$utf8_locale"
export LANG="$utf8_locale"
export LANGUAGE="$utf8_locale"
echo "Locale set to $utf8_locale"
fi
myvar=$(pwd)
red(){ echo -e "\033[31m\033[01m$1$2\033[0m"; }
green(){ echo -e "\033[32m\033[01m$1$2\033[0m"; }
yellow(){ echo -e "\033[33m\033[01m$1$2\033[0m"; }
reading(){ read -rp "$(green "$1")" "$2"; }
check_root(){
[[ $(id -u) != 0 ]] && red " The script must be run as root, you can enter sudo -i and then download and run again." && exit 1
}
check_operating_system(){
CMD=("$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)"
"$(hostnamectl 2>/dev/null | grep -i system | cut -d : -f2)"
"$(lsb_release -sd 2>/dev/null)" "$(grep -i description /etc/lsb-release 2>/dev/null | cut -d \" -f2)"
"$(grep . /etc/redhat-release 2>/dev/null)"
"$(grep . /etc/issue 2>/dev/null | cut -d \\ -f1 | sed '/^[ ]*$/d')"
)
for i in "${CMD[@]}"; do SYS="$i" && [[ -n $SYS ]] && break; done
REGEX=("debian" "ubuntu" "centos|red hat|kernel|oracle linux|amazon linux|alma|rocky")
RELEASE=("Debian" "Ubuntu" "CentOS")
PACKAGE_UPDATE=("apt -y update" "apt -y update" "yum -y update")
PACKAGE_INSTALL=("apt -y install" "apt -y install" "yum -y install")
PACKAGE_UNINSTALL=("apt -y autoremove" "apt -y autoremove" "yum -y autoremove")
for ((int = 0; int < ${#REGEX[@]}; int++)); do
[[ $(echo "$SYS" | tr '[:upper:]' '[:lower:]') =~ ${REGEX[int]} ]] && SYSTEM="${RELEASE[int]}" && break
done
[[ -z $SYSTEM ]] && red " ERROR: The script supports Debian, Ubuntu, CentOS or Alpine systems only.\n" && exit 1
}
check_virt(){
architecture=$(uname -m)
case "$architecture" in
"armv7l" | "armv6l" | "armv5l" | "armv7" | "armv6" | "armv5")
ARCH="arm32"
;;
"aarch64")
ARCH="arm64"
;;
"x86_64" | "x64")
ARCH="amd64"
;;
"i686")
ARCH="386"
;;
*)
ARCH="amd64"
;;
esac
}
input_token(){
[ -z $token ] && reading " Enter your Token, if you do not find it, open https://dashboard.gaganode.com/register?referral_code=smowgcziqyrfhpo to find it: " token
}
uninstall(){
check_virt
if [[ $ARCH == "amd64" ]]; then
apphub_name="apphub-linux-amd64"
elif [[ $ARCH == "arm64" ]]; then
apphub_name="apphub-linux-arm64"
elif [[ $ARCH == "386" ]]; then
apphub_name="apphub-linux-386"
elif [[ $ARCH == "arm32" ]]; then
apphub_name="apphub-linux-arm32"
fi
cd ${myvar}/${apphub_name}
sudo ./apphub service remove
cd ..
rm -rf ${myvar}/${apphub_name}
exit 1
}
result(){
green " Finish \n"
}
while getopts "UuT:t:" OPTNAME; do
case "$OPTNAME" in
'U'|'u' ) uninstall;;
'T'|'t' ) token=$OPTARG;;
esac
done
# 主程序
check_root
check_operating_system
check_virt
input_token
if [ $SYSTEM = "CentOS" ]; then
yum update
yum install -y curl tar ca-certificates sudo
if ! command -v crontab >/dev/null 2>&1; then
yum install -y cronie
fi
else
apt-get update
apt-get install -y curl tar ca-certificates sudo
if ! command -v crontab >/dev/null 2>&1; then
apt-get install -y cron
fi
fi
timeout=60
interval=3
elapsed_time=0
if [[ $ARCH == "amd64" ]]; then
curl -o ${myvar}/apphub-linux-amd64.tar.gz https://assets.coreservice.io/public/package/60/app-market-gaga-pro/1.0.4/app-market-gaga-pro-1_0_4.tar.gz && tar -zxf apphub-linux-amd64.tar.gz && rm -f apphub-linux-amd64.tar.gz
cd ${myvar}/apphub-linux-amd64
echo "0 3 * * * cd ${myvar}/apphub-linux-amd64 && ./apphub restart" | crontab -
elif [[ $ARCH == "arm64" ]]; then
curl -o ${myvar}/apphub-linux-arm64.tar.gz https://assets.coreservice.io/public/package/61/app-market-gaga-pro/1.0.4/app-market-gaga-pro-1_0_4.tar.gz && tar -zxf apphub-linux-arm64.tar.gz && rm -f apphub-linux-arm64.tar.gz
cd ${myvar}/apphub-linux-arm64
echo "0 3 * * * cd ${myvar}/apphub-linux-arm64 && ./apphub restart" | crontab -
elif [[ $ARCH == "386" ]]; then
curl -o ${myvar}/apphub-linux-386.tar.gz https://assets.coreservice.io/public/package/70/app-market-gaga-pro/1.0.4/app-market-gaga-pro-1_0_4.tar.gz && tar -zxf apphub-linux-386.tar.gz && rm -f apphub-linux-386.tar.gz
cd ${myvar}/apphub-linux-386
echo "0 3 * * * cd ${myvar}/apphub-linux-386 && ./apphub restart" | crontab -
elif [[ $ARCH == "arm32" ]]; then
curl -o ${myvar}/apphub-linux-arm32.tar.gz https://assets.coreservice.io/public/package/72/app-market-gaga-pro/1.0.4/app-market-gaga-pro-1_0_4.tar.gz && tar -zxf apphub-linux-arm32.tar.gz && rm -f apphub-linux-arm32.tar.gz
cd ${myvar}/apphub-linux-arm32
echo "0 3 * * * cd ${myvar}/apphub-linux-arm32 && ./apphub restart" | crontab -
fi
sudo ./apphub service remove && sudo ./apphub service install
sudo ./apphub service start
sleep 5
while [ $elapsed_time -lt $timeout ]; do
status=$(sudo ./apphub status)
if [[ "$status" == *RUNNING* ]]; then
break
fi
echo "Waiting for the program to start up..."
echo "${status}"
sleep $interval
elapsed_time=$((elapsed_time + interval))
done
sudo ./apps/gaganode/gaganode config set --token=${token}
sleep 3
sudo ./apphub restart
result