Skip to content

Instantly share code, notes, and snippets.

@akillcool
Last active April 19, 2024 12:27
Show Gist options
  • Select an option

  • Save akillcool/40e4021f8063bae8274217d5747eb3ca to your computer and use it in GitHub Desktop.

Select an option

Save akillcool/40e4021f8063bae8274217d5747eb3ca to your computer and use it in GitHub Desktop.

Revisions

  1. akillcool revised this gist Feb 15, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion start-clash.sh
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ then
    /usr/bin/clash
    else
    TIME=`date '+%Y-%m-%d %H:%M:%S'`
    cp ${HOME}/.config/clash/config.yaml ${HOME}/.config/clash/config.yaml.bak${TIME}
    cp ${HOME}/.config/clash/config.yaml "${HOME}/.config/clash/config.yaml.bak${TIME}"
    curl -L -o ${HOME}/.config/clash/config.yaml ${CLASH_URL}
    /usr/bin/clash
    fi
  2. akillcool created this gist Feb 14, 2020.
    14 changes: 14 additions & 0 deletions clash.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # edit and save this file to /usr/lib/systemd/system/clash.service
    [Unit]
    Description=clash
    After=network.target

    [Service]
    WorkingDirectory="your home directory"/.config/clash
    ExecStart="your home directory"/.config/clash/start-clash.sh
    ExecStop="your home directory"/.config/clash/stop-clash.sh
    Environment="HOME=your home directory"
    Environment="CLASH_URL=your subscribe address"

    [Install]
    WantedBy=multi-user.target
    16 changes: 16 additions & 0 deletions start-clash.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/bin/bash
    # save this file to ${HOME}/.config/clash/start-clash.sh

    # save pid file
    echo $$ > ${HOME}/.config/clash/clash.pid

    diff ${HOME}/.config/clash/config.yaml <(curl -s ${CLASH_URL})
    if [ "$?" == 0 ]
    then
    /usr/bin/clash
    else
    TIME=`date '+%Y-%m-%d %H:%M:%S'`
    cp ${HOME}/.config/clash/config.yaml ${HOME}/.config/clash/config.yaml.bak${TIME}
    curl -L -o ${HOME}/.config/clash/config.yaml ${CLASH_URL}
    /usr/bin/clash
    fi
    7 changes: 7 additions & 0 deletions stop-clash.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    #!/bin/bash
    # save this file to ${HOME}/.config/clash/stop-clash.sh

    # read pid file
    PID=`cat ${HOME}/.config/clash/clash.pid`
    kill -9 ${PID}
    rm ${HOME}/.config/clash/clash.pid