Skip to content

Instantly share code, notes, and snippets.

@Journalist-HK
Created May 12, 2024 09:17
Show Gist options
  • Save Journalist-HK/ad38bc0bbd53385dae6a0eb07283c6d5 to your computer and use it in GitHub Desktop.
Save Journalist-HK/ad38bc0bbd53385dae6a0eb07283c6d5 to your computer and use it in GitHub Desktop.
Update mihomo config
#!/bin/bash
FILE="config.yaml"
CONFIG_DIR=/home/pi/.config/mihomo
TEMP_DIR=/tmp/mihomo_config
CONFIG_FILE="${CONFIG_DIR}/${FILE}"
TEMP_FILE="${TEMP_DIR}/${FILE}"
DEFAULT_SECRET='_secret_'
MIHOMO_SECRET='123456'
mkdir -p $TEMP_DIR
# Construct the download URL
DOWNLOAD_URL="https://www.example.com/config.yaml"
# Download the binary
echo "Downloading config..."
wget -O $TEMP_FILE $DOWNLOAD_URL
if [ $? -ne 0 ]; then
echo "Download failed."
exit 1
fi
sed -i "s/$DEFAULT_SECRET/$MIHOMO_SECRET/g" $TEMP_FILE
mihomo -t -f $TEMP_FILE
if [ $? -ne 0 ]; then
echo "Config file verification failed."
exit 1
fi
# Move the binary to CONFIG_DIR
sudo mv $TEMP_FILE $CONFIG_FILE
# Reload config
curl -X PUT \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${CLASH_SECRET}" \
-d "{\"path\":\"${CONFIG_FILE}\"}" \
http://127.0.0.1:9090/configs
rm -rf $TEMP_DIR
echo "${FILE} update completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment