diff --git a/script/clashctl.sh b/script/clashctl.sh index 09bc951..990af89 100644 --- a/script/clashctl.sh +++ b/script/clashctl.sh @@ -85,7 +85,7 @@ _valid_yq() { _concat_config_restart() { _valid_config "$CLASH_CONFIG_MIXIN" || _error_quit "Mixin 配置验证失败,请检查" _valid_yq || return 1 - yq -n "load(\"$CLASH_CONFIG_RAW\") * load(\"$CLASH_CONFIG_MIXIN\")" > "$CLASH_CONFIG_RUNTIME" && clashrestart + sudo yq -n "load(\"$CLASH_CONFIG_RAW\") * load(\"$CLASH_CONFIG_MIXIN\")" | sudo tee "$CLASH_CONFIG_RUNTIME" >&/dev/null && clashrestart } _tunstatus() { @@ -165,10 +165,10 @@ function clashupdate() { _valid_config "$CLASH_CONFIG_RAW" && { _mark_raw _concat_config_restart && _okcat '配置更新成功,已重启生效' - echo "$url" > "$CLASH_CONFIG_URL" - echo "$(date +"%Y-%m-%d %H:%M:%S") 配置更新成功 ✅ $url" >> "${CLASH_UPDATE_LOG}" + echo "$url" | sudo tee "$CLASH_CONFIG_URL" >&/dev/null + echo "$(date +"%Y-%m-%d %H:%M:%S") 配置更新成功 ✅ $url" | sudo tee -a "${CLASH_UPDATE_LOG}" >&/dev/null } || { - echo "$(date +"%Y-%m-%d %H:%M:%S") 配置更新失败 ❌ $url" >> "${CLASH_UPDATE_LOG}" + echo "$(date +"%Y-%m-%d %H:%M:%S") 配置更新失败 ❌ $url" | sudo tee -a "${CLASH_UPDATE_LOG}" >&/dev/null _error_quit '配置无效:请检查配置内容' } } diff --git a/script/common.sh b/script/common.sh index a374457..ee31f1b 100644 --- a/script/common.sh +++ b/script/common.sh @@ -39,7 +39,7 @@ function _get_os() { _get_os function _mark_raw() { - sed -i -e '1i\# raw-config-start' -e '$a\# raw-config-end\n' "${CLASH_CONFIG_RAW}" + sudo sed -i -e '1i\# raw-config-start' -e '$a\# raw-config-end\n' "${CLASH_CONFIG_RAW}" } function _okcat() { @@ -75,13 +75,13 @@ function _download_config() { local url=$1 local output=$2 local agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0' - curl --connect-timeout 5 \ + sudo curl --connect-timeout 5 \ --retry 2 \ --user-agent "$agent" \ -k \ -o "$output" \ "$url" \ - || wget --timeout=5 \ + || sudo wget --timeout=5 \ --tries=1 \ --user-agent="$agent" \ --no-check-certificate \