-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathxvei.sh
More file actions
executable file
·161 lines (146 loc) · 5.78 KB
/
Copy pathxvei.sh
File metadata and controls
executable file
·161 lines (146 loc) · 5.78 KB
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
#!/usr/bin/env bash
# xvei - modular Xray (+ Hysteria2) installer / live editor.
# Repo: https://github.com/Shark-vil/xray_vless_easy_install_script
# No `set -e`: this is an interactive tool and many helpers legitimately return
# non-zero (e.g. the python engine returns 2 for "no change").
set -o pipefail
REPO_SLUG="Shark-vil/xray_vless_easy_install_script"
REPO_BRANCH="master"
INSTALL_DIR="/usr/local/lib/xvei"
# --- resolve our own location -------------------------------------------
_resolve_root() {
local src="${BASH_SOURCE[0]}"
while [ -h "$src" ]; do
local dir; dir="$(cd -P "$(dirname "$src")" && pwd)"
src="$(readlink "$src")"; [[ $src != /* ]] && src="$dir/$src"
done
cd -P "$(dirname "$src")" && pwd
}
XVEI_ROOT="$(_resolve_root)"
export XVEI_ROOT
# --- bootstrap: fetch the modular tree when run via curl|bash ----------
bootstrap() {
[ "$(id -u)" -eq 0 ] || { echo "run as root" >&2; exit 1; }
echo "[xvei] fetching $REPO_SLUG@$REPO_BRANCH -> $INSTALL_DIR"
command -v curl >/dev/null 2>&1 || { echo "curl required" >&2; exit 1; }
command -v tar >/dev/null 2>&1 || { echo "tar required" >&2; exit 1; }
mkdir -p "$INSTALL_DIR"
curl -fsSL "https://github.com/$REPO_SLUG/archive/refs/heads/$REPO_BRANCH.tar.gz" \
| tar -xz -C "$INSTALL_DIR" --strip-components=1
ln -sf "$INSTALL_DIR/xvei.sh" /usr/local/bin/xvei
chmod +x "$INSTALL_DIR/xvei.sh"
exec bash "$INSTALL_DIR/xvei.sh" "$@"
}
if [ ! -f "$XVEI_ROOT/lib/common.sh" ]; then
bootstrap "$@"
fi
# --- load modules ------------------------------------------------------
# shellcheck source=lib/common.sh
for m in common deps xray nginx certs hysteria2 warp tor apply menu; do
# shellcheck disable=SC1090
source "$XVEI_ROOT/lib/$m.sh"
done
# --- high level flows ------------------------------------------------
wizard_install() {
require_root
ensure_core_deps
xray_install
py init >/dev/null 2>&1 || true
py wizard
py set-meta --server-ip "$(server_ip)" >/dev/null || true
apply_all
echo
menu_status
echo
py show-links
echo
ok "Client files: $CLIENT_DIR"
}
xvei_remove() {
require_root
log "stopping services"
systemctl disable --now xray.service 2>/dev/null || true
hy2_remove_pkg
warp_down
tor_down
xray_remove_pkg
nginx_teardown
cert_hook_teardown
rm -rf "$XRAY_DIR" "$HY2_DIR" "$CLIENT_DIR"
ok "xvei removed"
}
self_update() {
require_root
[ -d "$INSTALL_DIR" ] || die "not a bootstrapped install ($INSTALL_DIR missing)"
curl -fsSL "https://github.com/$REPO_SLUG/archive/refs/heads/$REPO_BRANCH.tar.gz" \
| tar -xz -C "$INSTALL_DIR" --strip-components=1
ln -sf "$INSTALL_DIR/xvei.sh" /usr/local/bin/xvei
ok "updated $INSTALL_DIR"
}
_apply_after() {
# run a py mutation, then apply_all iff it changed state.
# The engine opens /dev/tty itself for any prompts it needs.
py "$@"
local rc=$?
case $rc in
0) apply_all ;;
2) log "no change" ;;
*) exit "$rc" ;;
esac
}
print_help() {
cat <<'EOF'
xvei - Xray + Hysteria2 installer / live editor
xvei open the interactive menu (or offer to install)
xvei install guided first-time setup
xvei edit interactive menu
xvei apply regenerate + validate + restart from the current state
xvei add-inbound <type> [--port N] [--dest SNI] [--method M]
types: vless-tls vless-ws vless-xhttp-reality vless-xhttp-tls
shadowsocks hysteria2
xvei remove-inbound <tag>
xvei add-outbound <warp|tor>
xvei remove-outbound <warp|tor>
xvei rule <add|remove|list> <block|warp|tor|direct> [matcher ...]
xvei template <russia|iran|china> --exit <warp|tor|block> [--tunnel <warp|tor> | --direct]
xvei template popular --tunnel <warp|tor>
xvei template none [--tunnel <warp|tor> | --direct]
xvei site [list | auth | blank | 404 | <preset> | proxy <url|preset>]
presets: nebula critters game2048 snake notes
xvei links [tag] print client share links
xvei qr <tag> print a QR code for one inbound
xvei status services + active template
xvei set-meta [--domain D --email E ...]
xvei update-geo refresh geoip/geosite
xvei self-update re-fetch the script tree
xvei remove uninstall everything
EOF
}
# --- dispatch --------------------------------------------------------
cmd="${1:-}"; shift || true
case "$cmd" in
""|edit|menu) main_menu ;;
install) wizard_install ;;
apply) apply_all ;;
add-inbound) _apply_after add-inbound "$@" ;;
remove-inbound) _apply_after remove-inbound "$@" ;;
add-outbound) _apply_after add-outbound "$@" ;;
remove-outbound) _apply_after remove-outbound "$@" ;;
rule) _apply_after rule "$@" ;;
template) _apply_after template "$@" ;;
site) if [ "${1:-list}" = "list" ]; then py site list
else _apply_after site "$@"; fi ;;
set-meta) _apply_after set-meta "$@" ;;
links) py show-links ${1:+--tag "$1"} ;;
qr) [ -n "${1:-}" ] || die "usage: xvei qr <tag>"
f="$CLIENT_DIR/$1.link"
[ -f "$f" ] || die "no link file: $f"
qrencode -t ANSIUTF8 "$(cat "$f")" ;;
status) menu_status ;;
update-geo) require_root; xray_update_geo; xray_restart; ok "geo updated" ;;
self-update) self_update ;;
remove|uninstall) xvei_remove ;;
_renew-hook) require_root; cert_renew_hook_run ;;
help|-h|--help) print_help ;;
*) err "unknown command: $cmd"; print_help; exit 1 ;;
esac