diff options
Diffstat (limited to 'run.sh')
-rwxr-xr-x | run.sh | 67 |
1 files changed, 67 insertions, 0 deletions
@@ -0,0 +1,67 @@ +#!/bin/bash + +set_proxy() { + case "$XDG_SESSION_DESKTOP" in + + "gnome" | "ubuntu") + gsettings set org.gnome.system.proxy mode "manual" + gsettings set org.gnome.system.proxy.socks host "127.0.0.1" + gsettings set org.gnome.system.proxy.socks port "10808" + gsettings set org.gnome.system.proxy.http host "127.0.0.1" + gsettings set org.gnome.system.proxy.http port "10809" + gsettings set org.gnome.system.proxy.https host "127.0.0.1" + gsettings set org.gnome.system.proxy.https port "10809" + ;; + + *) + echo "Only support GNOME currently, please set proxy manually." + ;; + + esac +} + +unset_proxy() { + case "$XDG_SESSION_DESKTOP" in + + "gnome" | "ubuntu") + gsettings set org.gnome.system.proxy mode "none" + ;; + + *) + echo "Only support GNOME currently, please unset proxy manually." + ;; + + esac +} + +cd "$(dirname "$0")" + +V2RAY_HOME=${V2RAY_HOME:-$(pwd)} +V2RAY_CONFIG_DIR=${V2RAY_CONFIG_DIR:-$(pwd)} +V2RAY="$V2RAY_HOME/v2ray" +V2RAY_SUB="$V2RAY_CONFIG_DIR/subscription" + +[[ -f "$V2RAY" ]] \ +|| { echo "V2ray not found, try to download it..."; "$V2RAY_HOME/upgrade.sh" || exit 1; } + +if [[ "$#" -ne 0 && -f "$1" ]] +then + set_proxy \ + && "$V2RAY" -config "$1" +else + if [[ "$#" -eq 0 ]] + then + [[ -f "$V2RAY_SUB" ]] || "$V2RAY_HOME/update.sh" || exit 1 + "$V2RAY_HOME/vmess2json/vmess2json.py" \ + < "$V2RAY_SUB" \ + --inbounds "http:10809,socks:10808" \ + --output "$V2RAY_CONFIG_DIR/config.json" \ + && set_proxy \ + && "$V2RAY" -config "$V2RAY_CONFIG_DIR/config.json" + else + echo "$1 does not exist." >&2 + exit 1 + fi +fi + +unset_proxy && printf "\nV2ray stopped.\n" |