#!/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 |
This comment has been minimized.
This comment has been minimized.
Thanks @snowleopardw. Before running the script, please make sure you have installed the |
This comment has been minimized.
This comment has been minimized.
Femtometer
commented
May 19, 2016
Downloading gfwlist. Note, seems directory does not fit others' laptop. |
This comment has been minimized.
This comment has been minimized.
Hi @Femtometer As I mentioned in the description, I only tested on OS X. Anyone can modify this code based on their needs. |
This comment has been minimized.
This comment has been minimized.
HoneyLuka
commented
May 25, 2016
@VincentSit Thanks |
This comment has been minimized.
This comment has been minimized.
jingchen-xu
commented
May 28, 2016
when I run your script
Is that because I am using python version 3.x ? |
This comment has been minimized.
This comment has been minimized.
@xujchen Hi, sorry for the delay, because Gist comments and mentions don't trigger notifications. Yes, gfwlist2pac needs python 2.7. |
This comment has been minimized.
This comment has been minimized.
For OS X users, if crontab does't running your script, please consider specify PATH variable in the Crontab. |
This comment has been minimized.
This comment has been minimized.
zwpaper
commented
Jun 5, 2016
thanks for the code, but it would be better if could check the version of python. |
This comment has been minimized.
This comment has been minimized.
tony-haibo-zhu
commented
Jun 19, 2016
Your bash is fine. |
This comment has been minimized.
This comment has been minimized.
mitoop
commented
Jul 21, 2016
@tony-haibo-zhu Just close your ShadowsockX and restart it. |
This comment has been minimized.
This comment has been minimized.
fuurose
commented
Aug 5, 2016
•
The script returns:
Is this because of an error with the gfwlist2pac install? The gfwlist2pac install returns: Does this mean the installation was unsuccessful? |
This comment has been minimized.
This comment has been minimized.
langjun
commented
Aug 10, 2016
Good job! |
This comment has been minimized.
This comment has been minimized.
janeluck
commented
Aug 18, 2016
@xujchen I have the same problem, is there any way to use python3? |
This comment has been minimized.
This comment has been minimized.
linkdesu
commented
Aug 19, 2016
THX!!! Line 63 |
This comment has been minimized.
This comment has been minimized.
juyfchn
commented
Aug 25, 2016
i want to know how to cancel |
This comment has been minimized.
This comment has been minimized.
d4rkb1ue
commented
Oct 13, 2016
@fuurose you should run it like |
This comment has been minimized.
This comment has been minimized.
d4rkb1ue
commented
Oct 13, 2016
@Femtometer you can change line 48 as |
This comment has been minimized.
This comment has been minimized.
chesterlyd
commented
Dec 13, 2016
我运行脚本
系统是OS X 10.11 ,请问一下,该怎么解决 |
This comment has been minimized.
This comment has been minimized.
holyen
commented
Mar 9, 2017
•
Desktop xxxx$ python update_gfwlist.sh |
This comment has been minimized.
This comment has been minimized.
这个脚本已经不需要了,也不维护了,请自行去下载 ShadowsocksX-NG。 |
This comment has been minimized.
snowleopardw commentedMay 16, 2016
sudo easy_install pip
sudo pip install gfwlist2pac