Skip to content

Instantly share code, notes, and snippets.

@VincentSit
Last active March 24, 2024 14:39
Show Gist options
  • Save VincentSit/b5b112d273513f153caf23a9da112b3a to your computer and use it in GitHub Desktop.
Save VincentSit/b5b112d273513f153caf23a9da112b3a to your computer and use it in GitHub Desktop.
Automatically update the PAC for ShadowsocksX. Only tested on OS X. (Deprecated)
#!/bin/bash
# update_gfwlist.sh
# Author : VincentSit
# Copyright (c) http://xuexuefeng.com
#
# Example usage
#
# ./whatever-you-name-this.sh
#
# Task Scheduling (Optional)
#
# crontab -e
#
# add:
# 30 9 * * * sh /path/whatever-you-name-this.sh
#
# Now it will update the PAC at 9:30 every day.
#
# Remember to chmod +x the script.
GFWLIST="https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt"
PROXY="127.0.0.1:1080"
USER_RULE_NAME="user-rule.txt"
check_module_installed()
{
pip list | grep gfwlist2pac &> /dev/null
if [ $? -eq 1 ]; then
echo "Installing gfwlist2pac."
pip install gfwlist2pac
fi
}
update_gfwlist()
{
echo "Downloading gfwlist."
curl -s "$GFWLIST" --fail --socks5-hostname "$PROXY" --output /tmp/gfwlist.txt
if [[ $? -ne 0 ]]; then
echo "abort due to error occurred."
exit 1
fi
cd ~/.ShadowsocksX || exit 1
if [ -f "gfwlist.js" ]; then
mv gfwlist.js ~/.Trash
fi
if [ ! -f $USER_RULE_NAME ]; then
touch $USER_RULE_NAME
fi
/usr/local/bin/gfwlist2pac \
--input /tmp/gfwlist.txt \
--file gfwlist.js \
--proxy "SOCKS5 $PROXY; SOCKS $PROXY; DIRECT" \
--user-rule $USER_RULE_NAME \
--precise
rm -f /tmp/gfwlist.txt
echo "Updated."
}
check_module_installed
update_gfwlist
@langjun
Copy link

langjun commented Aug 10, 2016

Good job!

@janeluck
Copy link

@xujchen I have the same problem, is there any way to use python3?

@linkdesu
Copy link

THX!!! Line 63 --precise is useless and will cause error .

@lol2025
Copy link

lol2025 commented Aug 25, 2016

i want to know how to cancel

@d4rkb1ue
Copy link

@fuurose you should run it like sudo -H update_gfwlist.sh

@d4rkb1ue
Copy link

@Femtometer you can change line 48 as cd /Users/[YOUR_USER_NAME]/.ShadowsocksX || exit 1 to solve the problem

@chesterlyd
Copy link

我运行脚本./update_gfwlist.sh以后显示

DEPRECATION: The default format will switch to columns in the future. 
You can use --format=(legacy|columns)
 (or define a format=(legacy|columns)
 in your pip.conf under the [list] section) to disable this warning.\
Downloading gfwlist.
abort due to error occurred.

系统是OS X 10.11 ,请问一下,该怎么解决

@holyen
Copy link

holyen commented Mar 9, 2017

Desktop xxxx$ python update_gfwlist.sh
File "update_gfwlist.sh", line 28
pip list | grep gfwlist2pac &> /dev/null
^
SyntaxError: invalid syntax

@VincentSit
Copy link
Author

这个脚本已经不需要了,也不维护了,请自行去下载 ShadowsocksX-NG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment