Created
May 22, 2018 11:09
-
-
Save InsanusMokrassar/a300c4629e7baa045d9ed6e1712c61c0 to your computer and use it in GitHub Desktop.
Shadowsocks launch functions which can be included by `source terminal_launch.sh` or by put this script in auto-start scripts such as `.bashrc`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Return (echo) last ss-local task | |
proxy_task() { | |
echo `ps -u $USER | grep "ss-local"` | |
} | |
proxy_status() { | |
if [ -z "`proxy_task`" ]; then | |
echo "Disabled" | |
else | |
echo "Enabled" | |
fi | |
} | |
enable_proxy() { | |
# Set proxy log file | |
proxy_log_file="$HOME/.proxy_work.log" | |
# Set socks configs list | |
ss_configs[0]="shadowsocks.config0" | |
ss_configs[1]="shadowsocks.config0" | |
# Disable proxy if ss-local was started before | |
if [ ! -z "`proxy_task`" ]; then | |
echo Disable previous proxy | |
disable_proxy | |
fi | |
# Choose one config | |
config=${ss_configs[$(($RANDOM % ${#ss_configs[@]}))]} | |
echo Chosen config: $config | |
# Launch ss-local | |
ss-local -c $config > $proxy_log_file & | |
# Add `socks_proxy` env variable into /etc/environment to give access to proxy via `socks_proxy` | |
echo Add proxy in /etc/environment | |
printf "`cat /etc/environment`\nsocks_proxy=\"socks://localhost:1080/\"\n" | sudo tee /etc/environment >> /dev/null | |
# Enable proxy settings in Gnome proxy | |
echo Enable Gnome Proxy | |
gsettings set org.gnome.system.proxy mode 'manual' | |
gsettings set org.gnome.system.proxy.socks host localhost | |
gsettings set org.gnome.system.proxy.socks port 1080 | |
} | |
disable_proxy() { | |
# Get task info for ss-local | |
task=`proxy_task` | |
task_number=`echo $task | grep -o "^[0-9]*"` | |
# If task is empty - task was not added and we must not do anything | |
if [ ! -z "$task_number" ]; then | |
echo Task: $task | |
echo Task number: $task_number | |
# Kill oldest task | |
kill $task_number | |
echo Killed | |
else | |
echo Proxy task was not found | |
fi | |
# Remove `socks_proxy` from `/etc/environment` | |
echo Clear /etc/environment | |
environment=`cat /etc/environment | grep -v socks_proxy` | |
echo "$environment" | sudo tee /etc/environment >> /dev/null | |
# Disable proxy settings in Gnome proxy | |
echo Disable Gnome Proxy | |
gsettings reset org.gnome.system.proxy.socks host | |
gsettings reset org.gnome.system.proxy.socks port | |
gsettings reset org.gnome.system.proxy mode | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment