-
Notifications
You must be signed in to change notification settings - Fork 30
/
autMan.sh
180 lines (147 loc) · 6.46 KB
/
autMan.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
#/bin/bash
LOG_FILE="/var/log/autMan.log"
function log::info() {
# 基础日志
printf "[%s] \033[32mINFO: \033[0m%s\n" "$(date +'%Y-%m-%d %H:%M:%S')" "$*" | tee -a "$LOG_FILE"
}
function log::error() {
# 错误日志
local item
printf "[$(date +'%Y-%m-%d %H:%M:%S')] \033[31mERROR: \033[0m$*\n" | tee -a "$LOG_FILE"
}
function utils::quote() {
# 转义引号
# shellcheck disable=SC2046
if [ $(echo "$*" | tr -d "\n" | wc -c) -eq 0 ]; then
echo "''"
elif [ $(echo "$*" | tr -d "[a-z][A-Z][0-9]:,.=~_/\n-" | wc -c) -gt 0 ]; then
printf "%s" "$*" | sed -e "1h;2,\$H;\$!d;g" -e "s/'/\'\"\'\"\'/g" | sed -e "1h;2,\$H;\$!d;g" -e "s/^/'/g" -e "s/$/'/g"
else
echo "$*"
fi
}
function check::exit_code() {
# 检查返回码
local code=${1:-}
local app=${2:-}
local desc=${3:-}
local exit_script=${4:-}
if [[ "${code}" == "0" ]]; then
log::info "[${app}]" "${desc} succeeded."
else
log::error "[${app}]" "${desc} failed."
[[ "$exit_script" == "exit" ]] && exit "$code"
fi
}
function command::exec() {
local command="$*"
command="$(utils::quote "$command")"
# 本地执行
# log::info "[command]" "bash -c $(printf "%s" "${command//${SUDO_PASSWORD:-}/******}")"
# shellcheck disable=SC2094
COMMAND_OUTPUT=$(eval bash -c "${command}" 2>>"$LOG_FILE" | tee -a "$LOG_FILE")
local status=$?
return $status
}
function install::Debian_Ubuntu(){
# Debian 安装命令
log::info "[apt]" "apt update and download python"
command::exec "apt update -y && apt install -y wget python3 python3-pip"
check::exit_code "$?" "apt" "apt install python" "exit"
# if [ ! -f "~/.pip/pip.conf" ]; then
# mkdir -p ~/.pip
# echo "[global]" >> ~/.pip/pip.conf
# echo "index-url = https://pypi.tuna.tsinghua.edu.cn/simple" >> ~/.pip/pip.conf
# fi
log::info "[pip3]" "pip3 dependency installation"
command::exec "pip3 install requests user_agent PyExecJS aiohttp -i https://pypi.tuna.tsinghua.edu.cn/simple"
check::exit_code "$?" "pip3" "pip3 install" "exit"
log::info "[node]" "node install"
command::exec "curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - && apt install -y nodejs"
check::exit_code "$?" "node" "node install" "exit"
log::info "[node]" "node dependency installation"
command::exec "npm install axios request require crypto-js"
check::exit_code "$?" "node" "node dependency install" "exit"
# log::info "[php]" "php install "
# command::exec "apt-get install -y php"
# check::exit_code "$?" "php" "php install" "exit"
}
function install::CentOS_Oracle(){
log::info "[yum]" "yum update and download python"
command::exec "yum update -y && yum install -y wget python3 python3-pip"
check::exit_code "$?" "yum" "yum install python" "exit"
# if [ ! -f "~/.pip/pip.conf" ]; then
# mkdir -p ~/.pip
# echo "[global]" >> ~/.pip/pip.conf
# echo "index-url = https://pypi.tuna.tsinghua.edu.cn/simple" >> ~/.pip/pip.conf
# fi
log::info "[pip3]" "pip3 dependency installation"
command::exec "pip3 install requests user_agent PyExecJS aiohttp -i https://pypi.tuna.tsinghua.edu.cn/simple"
check::exit_code "$?" "pip3" "pip3 install" "exit"
log::info "[node]" "node install"
command::exec "curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo -E bash - && yum install -y nodejs"
check::exit_code "$?" "node" "node install" "exit"
log::info "[node]" "node dependency installation"
command::exec "npm install axios request require crypto-js"
check::exit_code "$?" "node" "node dependency install" "exit"
# log::info "[php]" "php install "
# command::exec "yum install -y php"
# check::exit_code "$?" "php" "php install" "exit"
}
function install::anuMan(){
arch=$(uname -m)
if [ "$arch" == "x86_64" ]; then
a=amd64
elif [ "$arch" == "aarch64" ]; then
a=arm64
fi
latest_version=$(curl -s "https://ghproxy.homeboyc.cn/https://api.github.com/repos/hdbjlizhe/fanli/releases/latest" | grep -oP '"tag_name": "\K.*?(?=")')
command::exec "mkdir -p /root/autMan
cd /root/antMan
wget http://gh.301.ee/https://github.com/hdbjlizhe/fanli/releases/download/$latest_version/autMan_$a.tar.gz;
tar -zxvf autMan_$a.tar.gz -C /root/autMan;
rm -rf autMan_$a.tar.gz
chmod 777 /root/autMan/autMan
pkill -9 /root/antMan/antMan
/root/autMan/autMan -d"
check::exit_code "$?" "anuMan install"
}
function main(){
echo -e "\033[1;3$((RANDOM%10%8))m
█████╗ ██╗ ██╗████████╗███╗ ███╗ █████╗ ███╗ ██╗
██╔══██╗██║ ██║╚══██╔══╝████╗ ████║██╔══██╗████╗ ██║
███████║██║ ██║ ██║ ██╔████╔██║███████║██╔██╗ ██║
██╔══██║██║ ██║ ██║ ██║╚██╔╝██║██╔══██║██║╚██╗██║
██║ ██║╚██████╔╝ ██║ ██║ ╚═╝ ██║██║ ██║██║ ╚████║
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝ \033[0m"
echo
echo "有问题请带上日志文件联系作者,路径为:$LOG_FILE"
echo
os=$(grep -oP 'NAME=["]?([^"]+)' /etc/os-release | awk -F= '{print $2}' | tr -d '"' | head -1)
if [[ ! "$os" ]]; then
log::error "获取系统信息错误"
exit
else
log::info "获取系统信息" "$os"
fi
log::info "开始安装基础环境"
if [[ $os == *"Debian"* ]] || [[ $os == *"Ubuntu"* ]]; then
install::Debian_Ubuntu
elif [[ $os == *"CentOS"* ]] || [[ $os==*"Oracle"* ]]; then
install::CentOS_Oracle
fi
log::info "开始安装AutMan"
install::anuMan
ps aux | grep autMan | grep -v grep 2>&1 > /dev/null
if [ $? == 0 ];then
log::info "autMan运行成功"
else
log::error "autMan运行失败,请手动运行"
fi
echo
cat << EOF
安装路径:/root/autMan
运行命令:/root/autMan/autMan 前台运行 -t 交互运行 -d 后台默认运行
EOF
}
main