-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup_JiuWei
executable file
·306 lines (288 loc) · 10.8 KB
/
Setup_JiuWei
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
#
# @name: Setup_JiuWei
# @repo: https://gitee.com/TangYuanMaster/JiuWei
# @author: TangYuanMaster
# @license: See the file 'LICENSE.txt'
#
COLOR_DEFAULT="\e[0m"
COLOR_RED="\e[31m"
COLOR_GREEN="\e[32m"
COLOR_YELLOW="\e[33m"
COLOR_CYAN="\e[36m"
interrupt_handler() {
echo -e "${COLOR_YELLOW}[WARN] Received Ctrl+C, Do you want to continue running the script? (Y/n)${COLOR_DEFAULT}"
read -r answer
case $answer in
[Nn]) exit 1;;
*) continue;;
esac
}
trap interrupt_handler SIGINT
check_root() {
if [[ $EUID -ne 0 ]]; then
echo -e "${COLOR_RED}[-] This command must be run as root!${COLOR_DEFAULT}"
exit 1
fi
}
if [ ! -n "$TERMUX_VERSION" ]; then
check_root
fi
if [ ! -n "$HOME" ]; then
echo -e "${COLOR_RED}[-]\$HOME variables do not exist, please set the variable \$HOME and try again.${COLOR_DEFAULT}"
exit 1
fi
MAIN_DIR="$HOME/JiuWei"
INED_FILE=".installed" #记录所有已安装的包名(文本文件)
CONFIG_FILE="config.list" #放置源URL(文本文件)
FOXINDEX_FILE=".foxindex" #放置FOXINDEX解压后产生的文件(文件夹)
CACHE_FILE=".cache" #放置从源中下载的安装包(文件夹)
BIN_FILE=".bin" #快捷命令存放(文件夹)
ST_FILE=".expand" #拓展状态文件
INED="$MAIN_DIR/$INED_FILE"
CONFIG="$MAIN_DIR/$CONFIG_FILE"
CACHE="$MAIN_DIR/$CACHE_FILE"
FOXINDEX="$MAIN_DIR/$FOXINDEX_FILE"
BIN="$MAIN_DIR/$BIN_FILE"
ST="$MAIN_DIR/$ST_FILE"
if [ -f "/etc/os-release" ]; then
if grep -qi 'ID=alpine' /etc/os-release; then
sys_name="alpine"
elif grep -qi 'ID=debian' /etc/os-release; then
sys_name="debian"
elif grep -qi 'ID=ubuntu' /etc/os-release; then
sys_name="ubuntu"
elif grep -qi 'ID=kali' /etc/os-release; then
sys_name="kali"
elif grep -qi 'ID=arch' /etc/os-release; then
sys_name="arch"
elif grep -qi 'ID=centos' /etc/os-release; then
sys_name="centos"
elif grep -qi 'ID=*rhel*' /etc/os-release; then
sys_name="redhat"
fi
else
if [ -n "$TERMUX_VERSION" ]; then
sys_name="termux"
elif command -v "sw_vers"; then
sys_name="darwin"
else
echo -e "${COLOR_YELLOW}[*] Current system is not supported.${COLOR_DEFAULT}"
exit 1
fi
fi
update_run() {
echo -e "${COLOR_YELLOW}[*] Update...${COLOR_DEFAULT}"
if [ "$sys_name" = "alpine" ]; then
local run="apk update"
elif [ "$sys_name" = "debian" ] || [ "$sys_name" = "ubuntu" ] || [ "$sys_name" = "kali" ]; then
local run="apt update"
elif [ "$sys_name" = "arch" ]; then
local run="pacman -Sy"
elif [ "$sys_name" = "centos" ] || [ "$sys_name" = "redhat" ]; then
local run="yum -y update"
elif [ "$sys_name" = "termux" ]; then
local run="apt update"
elif [ "$sys_name" = "darwin" ]; then
local run="brew update"
fi
eval "$run"
}
check_curl() {
if ! command -v curl; then
echo -e "${COLOR_YELLOW}[*] Curl is not installed, start downloading and installing...${COLOR_DEFAULT}"
if [ "$sys_name" = "alpine" ]; then
apk add curl
elif [ "$sys_name" = "debian" ] || [ "$sys_name" = "ubuntu" ] || [ "$sys_name" = "kali" ]; then
apt install -y curl
elif [ "$sys_name" = "arch" ]; then
pacman -Sy curl
elif [ "$sys_name" = "centos" ] || [ "$sys_name" = "redhat" ]; then
yum install -y curl
elif [ "$sys_name" = "termux" ]; then
apt install -y curl
elif [ "$sys_name" = "darwin" ]; then
brew install -y curl
fi
fi
}
check_wget() {
if ! command -v wget; then
echo -e "${COLOR_YELLOW}[*] Wget is not installed, start downloading and installing...${COLOR_DEFAULT}"
if [ "$sys_name" = "alpine" ]; then
apk add wget
elif [ "$sys_name" = "debian" ] || [ "$sys_name" = "ubuntu" ] || [ "$sys_name" = "kali" ]; then
apt install -y wget
elif [ "$sys_name" = "arch" ]; then
pacman -Sy wget
elif [ "$sys_name" = "centos" ] || [ "$sys_name" = "redhat" ]; then
yum install -y wget
elif [ "$sys_name" = "termux" ]; then
apt install -y wget
elif [ "$sys_name" = "darwin" ]; then
brew install -y wget
fi
fi
}
check_git() {
if ! command -v git; then
echo -e "${COLOR_YELLOW}[*] Git is not installed, start downloading and installing...${COLOR_DEFAULT}"
if [ "$sys_name" = "alpine" ]; then
apk add git
elif [ "$sys_name" = "debian" ] || [ "$sys_name" = "ubuntu" ] || [ "$sys_name" = "kali" ]; then
apt install -y git
elif [ "$sys_name" = "arch" ]; then
pacman -Sy git
elif [ "$sys_name" = "centos" ] || [ "$sys_name" = "redhat" ]; then
yum install -y git
elif [ "$sys_name" = "termux" ]; then
apt install -y git
elif [ "$sys_name" = "darwin" ]; then
brew install -y git
fi
fi
git config --global pull.rebase false
}
check_python3_pip3() {
if ! command -v python3 || ! command -v pip3; then
echo -e "${COLOR_YELLOW}[*] Python3 or pip3 is not installed, start downloading and installing...${COLOR_DEFAULT}"
if [ "$sys_name" = "alpine" ]; then
apk add python3 py3-pip
elif [ "$sys_name" = "debian" ] || [ "$sys_name" = "ubuntu" ] || [ "$sys_name" = "kali" ]; then
apt install -y python3 python3-pip
elif [ "$sys_name" = "arch" ]; then
pacman -Sy python3 python-pip
elif [ "$sys_name" = "centos" ] || [ "$sys_name" = "redhat" ]; then
yum install -y python3
elif [ "$sys_name" = "termux" ]; then
apt install -y python python-pip
elif [ "$sys_name" = "darwin" ]; then
brew install -y python
fi
fi
}
check_go() {
if ! command -v go; then
echo -e "${COLOR_YELLOW}[*] Go is not installed, start downloading and installing...${COLOR_DEFAULT}"
if [ "$sys_name" = "alpine" ]; then
apk add go
elif [ "$sys_name" = "debian" ] || [ "$sys_name" = "ubuntu" ] || [ "$sys_name" = "kali" ]; then
apt install -y golang
elif [ "$sys_name" = "arch" ]; then
pacman -Sy go
elif [ "$sys_name" = "centos" ] || [ "$sys_name" = "redhat" ]; then
yum install -y golang
elif [ "$sys_name" = "termux" ]; then
apt install -y golang
elif [ "$sys_name" = "darwin" ]; then
brew install -y go
fi
fi
}
check_ruby_gem() {
if ! command -v ruby || ! command -v gem; then
echo -e "${COLOR_YELLOW}[*] Ruby or Gem is not installed, start downloading and installing...${COLOR_DEFAULT}"
if [ "$sys_name" = "alpine" ]; then
apk add ruby
elif [ "$sys_name" = "debian" ] || [ "$sys_name" = "ubuntu" ] || [ "$sys_name" = "kali" ]; then
apt install -y ruby-full
elif [ "$sys_name" = "arch" ]; then
pacman -Sy ruby
elif [ "$sys_name" = "centos" ] || [ "$sys_name" = "redhat" ]; then
yum install -y ruby ruby-devel
elif [ "$sys_name" = "termux" ]; then
pkg install -y ruby
elif [ "$sys_name" = "darwin" ]; then
brew install ruby
fi
fi
}
check_bc() {
if ! command -v bc >/dev/null 2>&1; then
echo -e "${COLOR_YELLOW}[*] bc is not installed, start downloading and installing...${COLOR_DEFAULT}"
if [ "$sys_name" = "alpine" ]; then
apk add bc
elif [ "$sys_name" = "debian" ] || [ "$sys_name" = "ubuntu" ] || [ "$sys_name" = "kali" ]; then
apt install -y bc
elif [ "$sys_name" = "arch" ]; then
pacman -Sy bc
elif [ "$sys_name" = "centos" ] || [ "$sys_name" = "redhat" ]; then
yum install -y bc
elif [ "$sys_name" = "termux" ]; then
apt install -y bc
elif [ "$sys_name" = "darwin" ]; then
brew install -y bc
fi
fi
}
check_make() {
if ! command -v make; then
echo -e "${COLOR_YELLOW}[*] Make is not installed, start downloading and installing...${COLOR_DEFAULT}"
if [ "$sys_name" = "alpine" ]; then
apk add make
elif [ "$sys_name" = "debian" ] || [ "$sys_name" = "ubuntu" ] || [ "$sys_name" = "kali" ]; then
apt install -y make
elif [ "$sys_name" = "arch" ]; then
pacman -Sy make
elif [ "$sys_name" = "centos" ] || [ "$sys_name" = "redhat" ]; then
yum install -y make
elif [ "$sys_name" = "termux" ]; then
apt install -y make
elif [ "$sys_name" = "darwin" ]; then
brew install -y make
fi
fi
}
check_code() {
echo -e "${COLOR_GREEN}[+] Check the software package dependence...Wait.${COLOR_DEFAULT}"
check_curl
check_wget
check_git
check_python3_pip3
check_make
check_go
check_ruby_gem
check_bc
}
update_run
check_code
mkdir -p "$MAIN_DIR" "$BIN" "$CACHE" "$FOXINDEX"
if ! wget -O "$CONFIG" "https://gitee.com/TangYuanMaster/JiuWei/raw/master/config.list"; then
echo -e "${COLOR_RED}[-] An error occurred while downloading...Exit.${COLOR_DEFAULT}"
exit 1
fi
touch "$INED"
if ! wget -O "$MAIN_DIR/CHANGE.log" "https://gitee.com/TangYuanMaster/JiuWei/raw/master/CHANGE.MD"; then
echo -e "${COLOR_RED}[-] An error occurred while downloading...Exit.${COLOR_DEFAULT}"
exit 1
fi
cd "$BIN"
# 使用wget命令从指定URL下载文件
if ! wget -O "fox" "https://gitee.com/TangYuanMaster/JiuWei/raw/master/fox"; then
echo -e "${COLOR_RED}[-] An error occurred while downloading...Exit.${COLOR_DEFAULT}"
exit 1
fi
chmod +x fox
if ! wget -O "get_latest_releases" "https://gitee.com/TangYuanMaster/JiuWei/raw/master/get_latest_releases"; then
echo -e "${COLOR_RED}[-] An error occurred while downloading...Exit.${COLOR_DEFAULT}"
exit 1
fi
chmod +x get_latest_releases
if ! wget -O "jiuwei" "https://gitee.com/TangYuanMaster/JiuWei/raw/master/jiuwei"; then
echo -e "${COLOR_RED}[-] An error occurred while downloading...Exit.${COLOR_DEFAULT}"
exit 1
fi
chmod +x jiuwei
if [ ! -n "$TERMUX_VERSION" ]; then
echo "export \"PATH=\$PATH:$MAIN_DIR/.bin\"" > /data/data/com.termux/files/usr/etc/profile.d/JiuWei.sh
chmod +x /data/data/com.termux/files/usr/etc/profile.d/JiuWei.sh
else
echo "export \"PATH=\$PATH:$MAIN_DIR/.bin\"" > /etc/profile.d/JiuWei.sh
chmod +x /etc/profile.d/JiuWei.sh
fi
export PATH="$PATH:$MAIN_DIR/.bin"
wget -O "Remove_JiuWei" https://gitee.com/TangYuanMaster/JiuWei/raw/master/Remove_JiuWei
chmod +x Remove_JiuWei
wget -O "Expand_JiuWei" https://gitee.com/TangYuanMaster/JiuWei/raw/master/Expand_JiuWei
chmod +x Expand_JiuWei
echo -e "${COLOR_GREEN}[INFO] Welcome to use JiuWei ~ Fox want to hug you.\(つ≧▽≦\)つ${COLOR_DEFAULT}"