Skip to content

Instantly share code, notes, and snippets.

@techom
Forked from VincentSit/update_gfwlist.sh
Created November 25, 2016 09:27
Show Gist options
  • Select an option

  • Save techom/f985728212296b90c35e419acbde7eb7 to your computer and use it in GitHub Desktop.

Select an option

Save techom/f985728212296b90c35e419acbde7eb7 to your computer and use it in GitHub Desktop.

Revisions

  1. @VincentSit VincentSit revised this gist May 24, 2016. No changes.
  2. @VincentSit VincentSit revised this gist May 24, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion update_gfwlist.sh
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,7 @@ update_gfwlist()
    exit 1
    fi

    cd ~/.ShadowsocksX
    cd ~/.ShadowsocksX || exit 1

    if [ -f "gfwlist.js" ]; then
    mv gfwlist.js ~/.Trash
  3. @VincentSit VincentSit revised this gist May 17, 2016. 1 changed file with 14 additions and 3 deletions.
    17 changes: 14 additions & 3 deletions update_gfwlist.sh
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@
    #
    # Now it will update the PAC at 9:30 every day.
    #
    # Remember to chmod +x the script
    # Remember to chmod +x the script.


    GFWLIST="https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt"
    @@ -28,12 +28,23 @@ 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

    if [ -f "gfwlist.js" ]; then
    @@ -44,8 +55,6 @@ update_gfwlist()
    touch $USER_RULE_NAME
    fi

    curl "$GFWLIST" --socks5-hostname "$PROXY" > /tmp/gfwlist.txt

    /usr/local/bin/gfwlist2pac \
    --input /tmp/gfwlist.txt \
    --file gfwlist.js \
    @@ -54,6 +63,8 @@ update_gfwlist()
    --precise

    rm -f /tmp/gfwlist.txt

    echo "Updated."
    }

    check_module_installed
  4. @VincentSit VincentSit created this gist May 16, 2016.
    60 changes: 60 additions & 0 deletions update_gfwlist.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    #!/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
    pip install gfwlist2pac
    fi
    }

    update_gfwlist()
    {
    cd ~/.ShadowsocksX

    if [ -f "gfwlist.js" ]; then
    mv gfwlist.js ~/.Trash
    fi

    if [ ! -f $USER_RULE_NAME ]; then
    touch $USER_RULE_NAME
    fi

    curl "$GFWLIST" --socks5-hostname "$PROXY" > /tmp/gfwlist.txt

    /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
    }

    check_module_installed
    update_gfwlist