Skip to content

Instantly share code, notes, and snippets.

@iguoli
Forked from VincentSit/update_gfwlist.sh
Last active August 6, 2018 03:44
Show Gist options
  • Save iguoli/80a648c10dae67a583760d0eba1fc08e to your computer and use it in GitHub Desktop.
Save iguoli/80a648c10dae67a583760d0eba1fc08e 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()
{
# just worked for python2.x
pip list | grep gfwlist2pac &> /dev/null
if [ $? -eq 1 ]; then
echo "Installing gfwlist2pac."
pip install gfwlist2pac
fi
}
update_gfwlist()
{
cd ~/.ShadowsocksX || exit 1
echo "Downloading gfwlist."
curl -fs "$GFWLIST" --socks5 "$PROXY" -o gfwlist.txt
if [[ $? -ne 0 ]]; then
echo "abort due to error occurred."
exit 1
fi
if [ -f "gfwlist.js" ]; then
mv gfwlist.js ~/.Trash
fi
if [ ! -f $USER_RULE_NAME ]; then
touch $USER_RULE_NAME
fi
gfwlist2pac \
--input gfwlist.txt \
--file gfwlist.js \
--proxy "SOCKS5 $PROXY; SOCKS $PROXY; DIRECT" \
--user-rule $USER_RULE_NAME \
--precise
echo "Updated."
}
check_module_installed
update_gfwlist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment