summaryrefslogtreecommitdiff
path: root/run.sh
diff options
context:
space:
mode:
authorJordan Gong <jordan.gong@protonmail.com>2020-10-03 10:58:11 +0800
committerJordan Gong <jordan.gong@protonmail.com>2020-10-03 10:58:11 +0800
commit39bb0d50ecbdd6d9669a01c7d2c170ed07291f76 (patch)
treec377f3c8adcd01c4192f00f2dd7051f65aba1423 /run.sh
Add basic features
- Subscription support - V2ray-core upgrade support
Diffstat (limited to 'run.sh')
-rwxr-xr-xrun.sh67
1 files changed, 67 insertions, 0 deletions
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"