Skip to content

Commit 916055d

Browse files
authored
Linux proxy control script improvement (2dust#7558)
* Proper Unix files new-line termination * Fallback for proxy configuration on Linux This introduces a special fallback for platform detection that helps with configuring the proxy settings on minimal (DE-less) setups. Also unifies the check for proper $MODE value.
1 parent 683ca8a commit 916055d

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

v2rayN/ServiceLib/Sample/linux_autostart_config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ X-GNOME-Autostart-enabled=true
77
Name[en_US]=v2rayN
88
Name=v2rayN
99
Comment[en_US]=v2rayN
10-
Comment=v2rayN
10+
Comment=v2rayN

v2rayN/ServiceLib/Sample/proxy_set_linux_sh

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ set_gnome_proxy() {
2929
echo "Ignored Hosts: $IGNORE_HOSTS"
3030
elif [ "$MODE" == "none" ]; then
3131
echo "GNOME: Proxy disabled."
32-
else
33-
echo "GNOME: Invalid mode. Use 'none' or 'manual'."
34-
exit 1
3532
fi
3633
}
3734

@@ -69,9 +66,6 @@ set_kde_proxy() {
6966
# Disable proxy
7067
$KWRITECONFIG --file kioslaverc --group "Proxy Settings" --key ProxyType 0
7168
echo "KDE: Proxy disabled."
72-
else
73-
echo "KDE: Invalid mode. Use 'none' or 'manual'."
74-
exit 1
7569
fi
7670

7771
# Apply changes by restarting KDE's network settings
@@ -84,7 +78,7 @@ detect_desktop_environment() {
8478
echo "gnome"
8579
return
8680
fi
87-
81+
8882
if [[ "$XDG_CURRENT_DESKTOP" == *"XFCE"* ]] || [[ "$XDG_SESSION_DESKTOP" == *"XFCE"* ]]; then
8983
echo "gnome"
9084
return
@@ -94,7 +88,7 @@ detect_desktop_environment() {
9488
echo "gnome"
9589
return
9690
fi
97-
91+
9892
if [[ "$XDG_CURRENT_DESKTOP" == *"UKUI"* ]] || [[ "$XDG_SESSION_DESKTOP" == *"ukui"* ]]; then
9993
echo "gnome"
10094
return
@@ -117,6 +111,15 @@ detect_desktop_environment() {
117111
return
118112
fi
119113
done
114+
115+
# Fallback to GNOME method if CLI utility is available. This solves the
116+
# proxy configuration issues on minimal installation systems, like setups
117+
# with only window managers, that borrow some parts from big DEs.
118+
if command -v gsettings >/dev/null 2>&1; then
119+
echo "gnome"
120+
return
121+
fi
122+
120123
echo "unsupported"
121124
}
122125

@@ -134,6 +137,11 @@ PROXY_IP=$2
134137
PROXY_PORT=$3
135138
IGNORE_HOSTS=$4
136139

140+
if ! [[ "$MODE" =~ ^(manual|none)$ ]]; then
141+
echo "Invalid mode. Use 'none' or 'manual'." >&2
142+
exit 1
143+
fi
144+
137145
# Detect desktop environment
138146
DE=$(detect_desktop_environment)
139147

@@ -144,6 +152,6 @@ elif [ "$DE" == "kde" ]; then
144152
set_gnome_proxy "$MODE" "$PROXY_IP" "$PROXY_PORT" "$IGNORE_HOSTS"
145153
set_kde_proxy "$MODE" "$PROXY_IP" "$PROXY_PORT" "$IGNORE_HOSTS"
146154
else
147-
echo "Unsupported desktop environment: $DE"
155+
echo "Unsupported desktop environment: $DE" >&2
148156
exit 1
149-
fi
157+
fi

0 commit comments

Comments
 (0)