v2ray-update.sh
1 #!/usr/bin/env bash 2 3 # Update /etc/v2ray/config.json based on subscription url. 4 5 # Usage: 6 # sudo ./v2ray-update.sh <subscription-url> 7 8 [ -x "$(command -v v2ray-tools)" ] || (echo "==> 'v2ray-tools' not installed." && echo "==> Install it by 'npm install -g v2ray-tools'" && exit 1) 9 [ -x "$(command -v v2ray)" ] || (echo "==> 'v2ray' not installed." && exit 2) 10 11 # Exit if the proxy is up 12 if [[ "$(HTTPS_PROXY=http://127.0.0.1:1080 curl -m 5 -Is https://www.google.com | head -1)" == *"200"* ]]; then 13 exit 0 14 fi 15 16 curl -sL "${1}" | base64 --decode | while read line ; do 17 if [[ "$(v2ray-tools vmesstest --url $line)" == "ok"*"美国"* ]]; then 18 v2ray-tools vmess2config --port 1080 --url "$line" > /etc/v2ray/config.json 19 sed -i 's/socks/http/' /etc/v2ray/config.json 20 systemctl restart v2ray.service 21 exit 0 22 fi 23 done