fix: optimize clashupdate

This commit is contained in:
--global committed 2024-12-30 13:59:07 +08:00
1 parent d3e3d99bea
commit d098029076
3 files changed
+22 -20

No files matched your search

+1
View File
@@ -74,6 +74,7 @@ $ clashupdate log
```
- 不指定 `url` 默认使用安装时填的订阅。
- 通过粘贴配置内容安装的,更新配置步骤:[pr#24](https://github.com/nelvko/clash-for-linux-install/pull/24#issuecomment-2565054701)
- 可通过 `crontab -e` 修改更新频率及订阅链接。
- 依赖 [`yq`](https://github.com/mikefarah/yq/releases) 命令实现 [`Mixin`](#mixin-配置),如下载失败请自行安装到 `PATH` 路径内。
+11 -11
View File
@@ -3,8 +3,8 @@
# shellcheck disable=SC2155
# clash快捷指令
function clashon() {
sudo systemctl start clash && echo '😼 已开启代理环境' \
|| echo '😾 启动失败: 执行 "systemctl status clash" 查看日志' || return 1
sudo systemctl start clash && _okcat '已开启代理环境' \
|| _failcat '启动失败: 执行 "systemctl status clash" 查看日志' || return 1
_get_port
local proxy_addr=http://127.0.0.1:${MIXED_PORT}
export http_proxy=$proxy_addr
@@ -14,8 +14,8 @@ function clashon() {
}
function clashoff() {
sudo systemctl stop clash && echo '😼 已关闭代理环境' \
|| echo '😾 关闭失败: 执行 "systemctl status clash" 查看日志' || return 1
sudo systemctl stop clash && _okcat '已关闭代理环境' \
|| _failcat '关闭失败: 执行 "systemctl status clash" 查看日志' || return 1
unset http_proxy
unset https_proxy
unset HTTP_PROXY
@@ -141,21 +141,21 @@ function clashupdate() {
return $?
;;
*)
url=$1
[ -n "$1" ] && url=$1
;;
esac
# 如果没有提供有效的订阅链接(url为空或者不是http开头),则使用默认配置文件
if [ -z "$url" ] || [ "${url:0:4}" != 'http' ]; then
_okcat "没有提供有效的订阅链接,使用默认配置文件进行更新..."
url="file://$(realpath ./resource/config.yaml)"
fi
[ -z "$url" ] || [ "${url:0:4}" != "http" ] && {
_failcat "没有提供有效的订阅链接,使用${CLASH_CONFIG_RAW}进行更新..."
url="file://$CLASH_CONFIG_RAW"
}
# 如果是自动更新模式,则设置定时任务
if [ "$is_auto" = true ]; then
[ "$is_auto" = true ] && {
grep -qs 'clashupdate' "$CLASH_CRON_TAB" || echo "0 0 */2 * * . $BASHRC;clashupdate $url" >> "$CLASH_CRON_TAB"
_okcat "定时任务设置成功" && return 0
fi
}
# 下载配置文件
_download_config "$url" "$CLASH_CONFIG_RAW"
+10 -9
View File
@@ -75,15 +75,16 @@ 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'
wget --timeout=5 \
--tries=1 \
--no-check-certificate \
--user-agent="$agent" \
-O "$output" \
curl --connect-timeout 5 \
--retry 2 \
--user-agent "$agent" \
-k \
-o "$output" \
"$url" \
|| curl --connect-timeout 5 \
--retry 2 \
--user-agent "$agent" \
-k -o "$output" \
|| wget --timeout=5 \
--tries=1 \
--user-agent="$agent" \
--no-check-certificate \
-O "$output" \
"$url"
}