-
Notifications
You must be signed in to change notification settings - Fork 16.4k
/
Copy pathinit.sh
153 lines (137 loc) · 3.6 KB
/
init.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
#!/bin/bash
author=233boy
# github=https://github.com/233boy/v2ray
# bash fonts colors
red='\e[31m'
yellow='\e[33m'
gray='\e[90m'
green='\e[92m'
blue='\e[94m'
magenta='\e[95m'
cyan='\e[96m'
none='\e[0m'
_red() { echo -e ${red}$@${none}; }
_blue() { echo -e ${blue}$@${none}; }
_cyan() { echo -e ${cyan}$@${none}; }
_green() { echo -e ${green}$@${none}; }
_yellow() { echo -e ${yellow}$@${none}; }
_magenta() { echo -e ${magenta}$@${none}; }
_red_bg() { echo -e "\e[41m$@${none}"; }
_rm() {
rm -rf "$@"
}
_cp() {
cp -rf "$@"
}
_sed() {
sed -i "$@"
}
_mkdir() {
mkdir -p "$@"
}
is_err=$(_red_bg 错误!)
is_warn=$(_red_bg 警告!)
err() {
echo -e "\n$is_err $@\n"
[[ $is_dont_auto_exit ]] && return
exit 1
}
warn() {
echo -e "\n$is_warn $@\n"
}
# load bash script.
load() {
. $is_sh_dir/src/$1
}
# wget add --no-check-certificate
_wget() {
# [[ $proxy ]] && export https_proxy=$proxy
wget --no-check-certificate "$@"
}
# yum or apt-get
cmd=$(type -P apt-get || type -P yum)
# x64
case $(arch) in
amd64 | x86_64)
is_core_arch="64"
caddy_arch="amd64"
;;
*aarch64* | *armv8*)
is_core_arch="arm64-v8a"
caddy_arch="arm64"
;;
*)
err "此脚本仅支持 64 位系统..."
;;
esac
is_core=v2ray
is_core_name=V2Ray
is_core_dir=/etc/$is_core
is_core_bin=$is_core_dir/bin/$is_core
is_core_repo=v2fly/$is_core-core
is_conf_dir=$is_core_dir/conf
is_log_dir=/var/log/$is_core
is_sh_bin=/usr/local/bin/$is_core
is_sh_dir=$is_core_dir/sh
is_sh_repo=$author/$is_core
is_pkg="wget unzip jq qrencode"
is_config_json=$is_core_dir/config.json
is_caddy_bin=/usr/local/bin/caddy
is_caddy_dir=/etc/caddy
is_caddy_repo=caddyserver/caddy
is_caddyfile=$is_caddy_dir/Caddyfile
is_caddy_conf=$is_caddy_dir/$author
is_caddy_service=$(systemctl list-units --full -all | grep caddy.service)
is_http_port=80
is_https_port=443
# core ver
is_core_ver=$($is_core_bin version | head -n1 | cut -d " " -f1-2)
if [[ $(grep -o ^[0-9] <<<${is_core_ver#* }) -lt 5 ]]; then
# core version less than 5, e.g, v4.45.2
is_core_ver_lt_5=1
if [[ $(grep 'run -config' /lib/systemd/system/v2ray.service) ]]; then
sed -i 's/run //' /lib/systemd/system/v2ray.service
systemctl daemon-reload
fi
else
is_with_run_arg=run
if [[ ! $(grep 'run -config' /lib/systemd/system/v2ray.service) ]]; then
sed -i 's/-config/run -config/' /lib/systemd/system/v2ray.service
systemctl daemon-reload
fi
fi
if [[ $(pgrep -f $is_core_bin) ]]; then
is_core_status=$(_green running)
else
is_core_status=$(_red_bg stopped)
is_core_stop=1
fi
if [[ -f $is_caddy_bin && -d $is_caddy_dir && $is_caddy_service ]]; then
is_caddy=1
# fix caddy run; ver >= 2.8.2
[[ ! $(grep '\-\-adapter caddyfile' /lib/systemd/system/caddy.service) ]] && {
load systemd.sh
install_service caddy
systemctl restart caddy &
}
is_caddy_ver=$($is_caddy_bin version | head -n1 | cut -d " " -f1)
is_tmp_http_port=$(egrep '^ {2,}http_port|^http_port' $is_caddyfile | egrep -o [0-9]+)
is_tmp_https_port=$(egrep '^ {2,}https_port|^https_port' $is_caddyfile | egrep -o [0-9]+)
[[ $is_tmp_http_port ]] && is_http_port=$is_tmp_http_port
[[ $is_tmp_https_port ]] && is_https_port=$is_tmp_https_port
if [[ $(pgrep -f $is_caddy_bin) ]]; then
is_caddy_status=$(_green running)
else
is_caddy_status=$(_red_bg stopped)
is_caddy_stop=1
fi
fi
load core.sh
# old sh ver
is_old_dir=/etc/v2ray/233boy
is_old_conf=/etc/v2ray/233blog_v2ray_backup.conf
if [[ -f $is_old_conf && -d $is_old_dir ]]; then
load old.sh
fi
[[ ! $args ]] && args=main
main $args