#!/bin/bash ######################################################################################### ### bash <(curl -fsSL https://raw.lhy.life/sing-box-update.sh) --version=1.12.5 --resetcmd="" ######################################################################################### ## GetArgValue ## ./script --key=value g_args=("$@") function GetArgValue() { local key="$1" local defvalue="$2" for arg in "${g_args[@]}" do if [[ "$arg" == "--$key="* ]] then echo "${arg#*=}" return fi done echo "$defvalue" } function CheckCmd() { local cmd="$1" if ! command -v "$cmd" &>/dev/null; then echo "Error: command \"$cmd\" not found." exit 1 fi } function GetLatestVer() { local ver=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases/latest" | jq -r '.name') echo "$ver" } CheckCmd "curl" CheckCmd "jq" VERSION=$(GetArgValue "version" "$(GetLatestVer)") RESETCMD=$(GetArgValue "resetcmd" "") mkdir -p "$HOME/apps/sing-box/data" cd "$HOME/apps/sing-box" rm -rf tempdown mkdir tempdown wget -O "tempdown/sing-box-$VERSION-linux-amd64.tar.gz" "https://github.com/SagerNet/sing-box/releases/download/v$VERSION/sing-box-$VERSION-linux-amd64.tar.gz" || exit 1 tar -xf tempdown/sing-box-$VERSION-linux-amd64.tar.gz -C tempdown if [ -f sing-box ]; then mv sing-box sing-box.bak fi mv tempdown/sing-box-$VERSION-linux-amd64/sing-box ./ chmod +x sing-box if [ -n "$RESETCMD" ]; then cp data/box.log data/box.log.bak echo "" > data/box.log $RESETCMD restart sing-box fi ./sing-box version rm -rf tempdown