-
-
Save d4rkb1ue/4272302e9e9b12370a87eac385fcd0fa to your computer and use it in GitHub Desktop.
Usage(On Mac) `sudo -H ./update_gfwlist.sh`
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
#!/bin/bash | |
# update_gfwlist.sh | |
# Author : VincentSit | |
# Copyright (c) http://xuexuefeng.com | |
# ---Modified by d4rkb1ue drkbl.com--- | |
# Trouble shooting | |
# `sudo: ./update_gfwlist.sh: command not found` | |
# run `chmod +x update_gfwlist.sh` | |
# usage | |
# | |
# `sudo -H ./update_gfwlist.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 /Users/$(logname)/.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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
change
cd ~/.ShadowsocksX || exit 1
tocd /Users/$(logname)/.ShadowsocksX || exit 1
, cause whensudo
current user change toroot
instead of real log user.