Last active
July 29, 2024 17:58
-
-
Save vcheckzen/6554233f79b223af383521d9dce1b963 to your computer and use it in GitHub Desktop.
Run xray in tmp for mipsel_mips32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
BASEDIR="$(dirname "$0")" | |
( | |
cd "$BASEDIR" || exit 1 | |
./kill-xray | |
sleep 3 | |
./start-xray | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
nohup \ | |
/usr/local/etc/xray/daemon \ | |
cb98958f-65b6-4345-af9d-770f0536c7fd \ | |
8443 \ | |
/path/to/you \ | |
d015c3e4-b338-4bec-8c62-e575b5449393 \ | |
www.apple.com \ | |
/path/to/me \ | |
www.example.com \ | |
443 \ | |
1>/dev/null 2>&1 & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
search_pid() { | |
# shellcheck disable=SC2009 | |
ps | grep "$1" | grep -v grep | awk '{print $1}' | |
} | |
find_children() { | |
parent_pid="$1" | |
children="$(awk -v ppid="$parent_pid" '$4==ppid {print $1}' /proc/[0-9]*/stat 2>/dev/null)" | |
for child in $children; do | |
echo "$child" | |
find_children "$child" | |
done | |
} | |
pk() { | |
echo "$1" | |
kill "$1" | |
} | |
stop() { | |
for id in $(search_pid "$1"); do | |
for cid in $(find_children "$id"); do | |
pk "$cid" | |
done | |
pk "$id" | |
done | |
} | |
stop /usr/local/etc/xray/daemon | |
stop /tmp/xray/v2ray | |
rm -rf /tmp/xray/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ "$#" -ne 8 ]; then | |
echo "Usage: $0 [uuid_in] [port_in] [path_in] [uuid_out] [host_out] [path_out] [proxy_host] [proxy_port]" | |
exit 1 | |
fi | |
UUID_IN="$1" | |
PORT_IN="$2" | |
PATH_IN="$3" | |
UUID_OUT="$4" | |
HOST_OUT="$5" | |
PATH_OUT="$6" | |
PROXY_HOST="$7" | |
PROXY_PORT="$8" | |
RUN_DIR="/tmp/xray" | |
# BIN_FILE="https://opt.cn2qq.com/opt-file/v2ray" | |
# GEOIP_FILE="https://opt.cn2qq.com/opt-file/geoip.dat" | |
# GEOSITE_FILE="https://mirror.ghproxy.com/https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat" | |
#BIN_FILE="https://files.catbox.moe/7dq5gc" | |
#BIN_FILE="https://files.catbox.moe/xcijwm" | |
BIN_FILE="https://files.catbox.moe/acg48k" | |
GEOIP_FILE="https://files.catbox.moe/0ukrr8.dat" | |
GEOSITE_FILE="https://files.catbox.moe/gxjwpf.dat" | |
BIN_FILE_SAVE_NAME="v2ray" | |
GEOIP_FILE_SAVE_NAME="geoip.dat" | |
GEOSITE_FILE_SAVE_NAME="geosite.dat" | |
slog() { | |
logger -t v2rayd[$$] "$1" | |
} | |
init_bin() { | |
curl -s qq.com 1>/dev/null 2>&1 || return 1 | |
down() { | |
uri="$1" | |
save_name="$2" | |
is_bin="$3" | |
[ -f "$RUN_DIR/$save_name" ] || { | |
if curl -kL "$uri" -o "$RUN_DIR/$save_name"; then | |
[ "$is_bin" ] && chmod +x "$RUN_DIR/$save_name" | |
else | |
rm -f "$RUN_DIR/$save_name" | |
slog "Failed to download $save_name." | |
return 1 | |
fi | |
} | |
return 0 | |
} | |
down "$BIN_FILE" "$BIN_FILE_SAVE_NAME" "true" || return 1 | |
down "$GEOIP_FILE" "$GEOIP_FILE_SAVE_NAME" || return 1 | |
down "$GEOSITE_FILE" "$GEOSITE_FILE_SAVE_NAME" || return 1 | |
return 0 | |
} | |
init_config() { | |
[ -f "$RUN_DIR/conf.json" ] && return 0 | |
cat >"$RUN_DIR/conf.json" <<EOF | |
{ | |
"inbounds": [ | |
{ | |
"tag": "ml_in", | |
"listen": "0.0.0.0", | |
"port": $PORT_IN, | |
"protocol": "vless", | |
"settings": { | |
"decryption": "none", | |
"clients": [ | |
{"id": "$UUID_IN"} | |
] | |
}, | |
"streamSettings": { | |
"network": "ws", | |
"wsSettings": {"path": "$PATH_IN"} | |
}, | |
"sockopt": { | |
"mark": 0, | |
"tcpFastOpen": true, | |
"tcpcongestion": "bbr", | |
"tproxy": "off" | |
}, | |
"sniffing": { | |
"enabled": false, | |
"destOverride": ["http", "tls"] | |
} | |
} | |
], | |
"outbounds": [ | |
{"tag": "block", "protocol": "blackhole"}, | |
{"tag": "direct_out", "protocol": "freedom"}, | |
{ | |
"tag": "proxy_out", | |
"protocol": "vless", | |
"settings": { | |
"vnext": [ | |
{ | |
"address": "$PROXY_HOST", | |
"port": $PROXY_PORT, | |
"users": [ | |
{ | |
"id" : "$UUID_OUT", | |
"encryption": "none" | |
} | |
] | |
} | |
] | |
}, | |
"streamSettings": { | |
"network": "ws", | |
"security": "tls", | |
"tlsSettings": { | |
"allowInsecure": false, | |
"serverName": "$HOST_OUT", | |
"fingerprint": "safari" | |
}, | |
"wsSettings": { | |
"headers": {"Host": "$HOST_OUT"}, | |
"path": "$PATH_OUT?ed=2560" | |
} | |
}, | |
"sockopt": { | |
"mark": 0, | |
"tcpFastOpen": true, | |
"tcpcongestion": "bbr", | |
"tproxy": "off" | |
} | |
} | |
], | |
"routing": { | |
"domainStrategy": "AsIs", | |
"domainMatcher": "hybrid", | |
"rules": [ | |
{ | |
"type": "field", | |
"domain": ["geosite:category-ads-all"], | |
"outboundTag": "block" | |
}, | |
{ | |
"type": "field", | |
"inboundTag": ["ml_in"], | |
"domain": ["geosite:cn", "geosite:geolocation-cn"], | |
"outboundTag": "direct_out" | |
}, | |
{ | |
"type": "field", | |
"inboundTag": ["ml_in"], | |
"ip": ["geoip:private", "geoip:cn"], | |
"outboundTag": "direct_out" | |
}, | |
{ | |
"type": "field", | |
"inboundTag": ["ml_in"], | |
"protocol": ["bittorrent"], | |
"outboundTag": "direct_out" | |
}, | |
{ | |
"type": "field", | |
"inboundTag": ["ml_in"], | |
"outboundTag": "proxy_out" | |
} | |
] | |
} | |
} | |
EOF | |
} | |
get_pid() { | |
pgrep "$RUN_DIR/v2ray" | |
} | |
init() { | |
[ "$(get_pid)" ] && return 0 | |
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR" | |
init_bin && init_config | |
} | |
run() { | |
[ "$(get_pid)" ] && return 0 | |
if ! ( | |
cd "$RUN_DIR" || exit 1 | |
nohup "$RUN_DIR/v2ray" run -c "$RUN_DIR/conf.json" >>"$RUN_DIR/log" 2>&1 & | |
sleep 5 | |
); then | |
return 1 | |
fi | |
rid="$(get_pid)" | |
if [ "$rid" ]; then | |
slog "Started, pid: $rid" | |
clean_bin | |
return 0 | |
else | |
slog "Failed to start, msg: $(cat "$RUN_DIR/log")" | |
return 1 | |
fi | |
} | |
clean_bin() { | |
( | |
cd "$RUN_DIR" || exit 1 | |
rm -f "$GEOIP_FILE_SAVE_NAME" "$GEOSITE_FILE_SAVE_NAME" "$BIN_FILE_SAVE_NAME" | |
) | |
} | |
clean_log() { | |
minute="$(date +%M)" | |
if [ "$minute" -ne 32 ] && [ "$minute" -ne 33 ]; then | |
return 0 | |
fi | |
[ ! -f "$RUN_DIR/log" ] && return 0 | |
[ "$(du -k "$RUN_DIR/log" | cut -f1)" -gt 128 ] && { | |
tmp_log="$(mktemp)" | |
tail -n1000 "$RUN_DIR/log" >"$tmp_log" && mv "$tmp_log" "$RUN_DIR/log" | |
} | |
} | |
daemon() { | |
while true; do | |
init && { | |
run && clean_log | |
sleep 1m | |
continue | |
} | |
sleep 5m | |
done | |
} | |
daemon | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment