-
-
Save sko00o/43021bfd02d8a368215e570ce3539165 to your computer and use it in GitHub Desktop.
clash auto start and update subcribe configuration
This file contains hidden or 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 | |
# save this file to /usr/local/bin/clash-start | |
# save pid file | |
echo $$ > ${HOME}/.config/clash/clash.pid | |
CLASH_URL="your subscribe address" # NEED EDIT! | |
CLASH_REMOTE_CFG="${HOME}/.config/clash/config-remote.yaml" | |
CLASH_LOCAL_CFG="${HOME}/.config/clash/config-local.yaml" | |
CLASH_TMP_CFG="/tmp/clash-config.yaml" | |
CLASH_TARGET_CFG="${HOME}/.config/clash/config.yaml" | |
curl -s -o "${CLASH_REMOTE_CFG}" "${CLASH_URL}" | |
merge-yaml ${CLASH_LOCAL_CFG} ${CLASH_REMOTE_CFG} > ${CLASH_TMP_CFG} | |
if $(diff ${CLASH_TARGET_CFG} ${CLASH_TMP_CFG}); then | |
clash | |
else | |
TIME=`date '+%Y%m%d%H%M%S'` | |
cp ${CLASH_TARGET_CFG} "${CLASH_TARGET_CFG}.${TIME}.bak" | |
mv ${CLASH_TMP_CFG} ${CLASH_TARGET_CFG} | |
clash | |
fi |
This file contains hidden or 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 | |
# save this file to /usr/local/bin/clash-stop | |
# read pid file | |
PID=`cat ${HOME}/.config/clash/clash.pid` | |
kill -9 ${PID} | |
rm ${HOME}/.config/clash/clash.pid |
This file contains hidden or 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
# edit and save this file to /usr/lib/systemd/system/clash.service | |
[Unit] | |
Description=Clash | |
After=network.target | |
[Service] | |
ExecStart=/usr/local/bin/clash-start | |
ExecStop=/usr/local/bin/clash-stop | |
Environment="HOME=/root/" | |
User=root | |
[Install] | |
WantedBy=multi-user.target |
This file contains hidden or 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
# save in ${HOME}/.config/clash/config-local.yaml | |
port: 0 | |
socks-port: 0 | |
mixed-port: 7890 | |
external-controller: :9090 | |
allow-lan: true | |
# git clone https://github.com/Dreamacro/clash-dashboard.git ${HOME}/.config/clash/clash-dashboard | |
external-ui: clash-dashboard | |
secret: "A-Secret-Password" # NEED EDIT! |
This file contains hidden or 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
#!/usr/bin/python3 | |
# save in /usr/local/bin/merge-yaml | |
import yaml | |
import sys | |
def merge_yaml_files(input_files): | |
merged_data = {} | |
# Iterate through each input file | |
for file_path in input_files: | |
with open(file_path, 'r', encoding='utf-8') as file: | |
yaml_data = yaml.safe_load(file) | |
# Merge the array fields (lists) | |
for key, value in yaml_data.items(): | |
if isinstance(value, list): | |
if key in merged_data: | |
merged_data[key].extend(value) | |
else: | |
merged_data[key] = value | |
# Replace the key-value fields (dictionaries) | |
for key, value in yaml_data.items(): | |
if not isinstance(value, list): | |
if key not in merged_data: | |
merged_data[key] = value | |
# Convert the merged data to YAML | |
merged_yaml = yaml.dump(merged_data, allow_unicode=True) | |
# Output the merged YAML content in UTF-8 encoding | |
sys.stdout.buffer.write(merged_yaml.encode('utf-8')) | |
# Example usage | |
if __name__ == '__main__': | |
# Check if input file paths are provided | |
if len(sys.argv) < 2: | |
sys.exit("Please provide at least one input file path.") | |
input_files = sys.argv[1:] | |
merge_yaml_files(input_files) |
This file contains hidden or 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
#!/usr/bin/env bash | |
# save in ~/.local/bin/proxy | |
# and add this in ~/.bashrc | |
# . $HOME/.local/bin/proxy && proxy_set | |
hostip=127.0.0.1 | |
port=7890 | |
PROXY_HTTP="http://${hostip}:${port}" | |
proxy_set(){ | |
export http_proxy="${PROXY_HTTP}" | |
export HTTP_PROXY="${PROXY_HTTP}" | |
export https_proxy="${PROXY_HTTP}" | |
export HTTPS_proxy="${PROXY_HTTP}" | |
export no_proxy="10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,127.0.0.1,::1,localhost" | |
export NO_PROXY="10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,127.0.0.1,::1,localhost" | |
} | |
proxy_unset(){ | |
unset http_proxy | |
unset HTTP_PROXY | |
unset https_proxy | |
unset HTTPS_PROXY | |
unset NO_PROXY | |
unset no_proxy | |
} | |
proxy_test(){ | |
echo "Current proxy:" $https_proxy | |
} | |
if [ "$1" = "set" ] | |
then | |
proxy_set | |
elif [ "$1" = "unset" ] | |
then | |
proxy_unset | |
elif [ "$1" = "test" ] | |
then | |
proxy_test | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment