-
Notifications
You must be signed in to change notification settings - Fork 0
/
Expand_JiuWei
executable file
·211 lines (202 loc) · 7.63 KB
/
Expand_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
#!/bin/bash
#
# @name: Expand_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" #配置文件(文本文件)
FOXINDEX_FILE=".foxindex" #放置FOXINDEX解压后产生的文件(文件夹)
CACHE_FILE=".cache" #放置从源中下载的安装包(文件夹)
BIN_FILE=".bin" #快捷命令存放(文件夹)
ST_FILE=".expand" #拓展状态文件
INED="$MAIN_DIR/$INED_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() {
if [ "$parameters_1" = "--no-update" ] || [ "$parameters_2" = "--no-update" ]; then
echo -e "${COLOR_YELLOW}[*] Skip update~=_=${COLOR_DEFAULT}"
else:
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
fi
if [ "$parameters_1" = "--no-update" ] || [ "$parameters_2" = "--no-update" ]; then
echo "$run"
fi
}
check_rust_cargo() {
if ! command -v rustc || ! command -v cargo; then
echo -e "${COLOR_YELLOW}[*] Rust or Cargo is not installed, start downloading and installing...${COLOR_DEFAULT}"
if [ "$sys_name" = "alpine" ]; then
apk add rust cargo
elif [ "$sys_name" = "debian" ] || [ "$sys_name" = "ubuntu" ] || [ "$sys_name" = "kali" ]; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
elif [ "$sys_name" = "arch" ]; then
pacman -Sy rust
elif [ "$sys_name" = "centos" ] || [ "$sys_name" = "redhat" ]; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
elif [ "$sys_name" = "termux" ]; then
pkg install -y rust
elif [ "$sys_name" = "darwin" ]; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
fi
fi
}
check_node_npm() {
if ! command -v node || ! command -v npm; then
echo -e "${COLOR_YELLOW}[*] Node.js or npm is not installed, start downloading and installing...${COLOR_DEFAULT}"
if [ "$sys_name" = "alpine" ]; then
apk add nodejs npm
elif [ "$sys_name" = "debian" ] || [ "$sys_name" = "ubuntu" ] || [ "$sys_name" = "kali" ]; then
apt install -y nodejs npm
elif [ "$sys_name" = "arch" ]; then
pacman -Sy nodejs npm
elif [ "$sys_name" = "centos" ] || [ "$sys_name" = "redhat" ]; then
curl -sL https://rpm.nodesource.com/setup_lts.x | bash -
yum install -y nodejs
elif [ "$sys_name" = "termux" ]; then
pkg install -y nodejs
elif [ "$sys_name" = "darwin" ]; then
brew install -y node
fi
fi
}
check_java() {
if ! command -v java || ! command -v javac; then
echo -e "${COLOR_YELLOW}[*] Java is not installed, start downloading and installing...${COLOR_DEFAULT}"
if [ "$sys_name" = "alpine" ]; then
apk add openjdk8
elif [ "$sys_name" = "debian" ] || [ "$sys_name" = "ubuntu" ] || [ "$sys_name" = "kali" ]; then
apt install -y openjdk-11-jdk
elif [ "$sys_name" = "arch" ]; then
pacman -Sy jdk-openjdk
elif [ "$sys_name" = "centos" ] || [ "$sys_name" = "redhat" ]; then
yum install -y java-11-openjdk-devel
elif [ "$sys_name" = "termux" ]; then
pkg install -y openjdk-17
elif [ "$sys_name" = "darwin" ]; then
brew install -y openjdk@11
fi
fi
}
check_python2_pip2() {
if ! command -v python2 || ! command -v pip2; then
echo -e "${COLOR_YELLOW}[*] Python2 or pip2 is not installed, start downloading and installing...${COLOR_DEFAULT}"
if [ "$sys_name" = "alpine" ]; then
#需要旧的AlpineLinux源
apk add python2 py2-pip
elif [ "$sys_name" = "debian" ] || [ "$sys_name" = "ubuntu" ] || [ "$sys_name" = "kali" ]; then
apt install -y python2 python-pip
elif [ "$sys_name" = "arch" ]; then
pacman -Sy python2 python2-pip
elif [ "$sys_name" = "centos" ] || [ "$sys_name" = "redhat" ]; then
yum install -y python2
elif [ "$sys_name" = "termux" ]; then
apt install -y python2 python2-pip
elif [ "$sys_name" = "darwin" ]; then
brew install -y python@2
fi
fi
}
check_perl() {
if ! command -v perl; then
echo -e "${COLOR_YELLOW}[*] Perl is not installed, start downloading and installing...${COLOR_DEFAULT}"
if [ "$sys_name" = "alpine" ]; then
apk add perl
elif [ "$sys_name" = "debian" ] || [ "$sys_name" = "ubuntu" ] || [ "$sys_name" = "kali" ]; then
apt install -y perl
elif [ "$sys_name" = "arch" ]; then
pacman -Sy perl
elif [ "$sys_name" = "centos" ] || [ "$sys_name" = "redhat" ]; then
yum install -y perl
elif [ "$sys_name" = "termux" ]; then
pkg install -y perl
elif [ "$sys_name" = "darwin" ]; then
brew install -y perl
fi
fi
}
check_code() {
echo -e "${COLOR_GREEN}[+] Check the software package dependence...Wait.${COLOR_DEFAULT}"
check_rust_cargo
check_node_npm
check_java
check_python2_pip2
check_perl
}
update_run
check_code
touch "$ST"
echo -e "${COLOR_GREEN}[INFO] Thank you for your support of Fox ~ Have a good luck! o\( ̄▽ ̄\)d${COLOR_DEFAULT}"