From 39bb0d50ecbdd6d9669a01c7d2c170ed07291f76 Mon Sep 17 00:00:00 2001 From: Jordan Gong Date: Sat, 3 Oct 2020 10:58:11 +0800 Subject: Add basic features - Subscription support - V2ray-core upgrade support --- run.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 run.sh (limited to 'run.sh') diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..c0889d3 --- /dev/null +++ b/run.sh @@ -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" -- cgit v1.2.3