From 63381105307389461b08bf1fd8c8d2ab52ff3429 Mon Sep 17 00:00:00 2001 From: juewuy Date: Mon, 22 Dec 2025 21:23:50 +0800 Subject: [PATCH] =?UTF-8?q?~=E6=8B=86=E5=88=86=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/libs/set_proxy.sh | 2 +- scripts/libs/web_get.sh | 48 +++++++++++++++++++++++++++++++++++++ scripts/libs/web_get_bin.sh | 18 ++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 scripts/libs/web_get.sh create mode 100644 scripts/libs/web_get_bin.sh diff --git a/scripts/libs/set_proxy.sh b/scripts/libs/set_proxy.sh index 44a083bb..ce32d02e 100644 --- a/scripts/libs/set_proxy.sh +++ b/scripts/libs/set_proxy.sh @@ -1,7 +1,7 @@ setproxy(){ [ -n "$(pidof CrashCore)" ] && { - [ -n "$authentication" ] && auth="$authentication@" + [ -n "$authentication" ] && auth="$authentication@" || auth="" [ -z "$mix_port" ] && mix_port=7890 export https_proxy="http://${auth}127.0.0.1:$mix_port" } diff --git a/scripts/libs/web_get.sh b/scripts/libs/web_get.sh new file mode 100644 index 00000000..d68e3105 --- /dev/null +++ b/scripts/libs/web_get.sh @@ -0,0 +1,48 @@ +. "$CRASHDIR"/libs/set_proxy.sh + +webget(){ + if pidof CrashCore >/dev/null; then + setproxy #设置临时代理 + url=$(printf '%s\n' "$3" | + sed -e 's#https://.*jsdelivr.net/gh/juewuy/ShellCrash[@|/]#https://raw.githubusercontent.com/juewuy/ShellCrash/#' \ + -e 's#https://gh.jwsc.eu.org/#https://raw.githubusercontent.com/juewuy/ShellCrash/#') + else + url=$(printf '%s\n' "$3" | + sed 's#https://raw.githubusercontent.com/juewuy/ShellCrash/#https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@#') + fi + #参数【$2】代表下载目录,【$3】代表在线地址 + #参数【$4】代表输出显示,【$5】不启用重定向 + #参数【$6】代表验证证书,【$7】使用自定义UA + [ -n "$7" ] && agent="--user-agent \"$7\"" + if wget --help 2>&1 | grep -q 'show-progress' >/dev/null 2>&1; then + [ "$4" = "echooff" ] && progress='-q' || progress='-q --show-progress' + [ "$5" = "rediroff" ] && redirect='--max-redirect=0' || redirect='' + [ "$6" = "skipceroff" ] && certificate='' || certificate='--no-check-certificate' + wget -Y on $agent $progress $redirect $certificate --timeout=3 -O "$2" "$url" && return 0 #成功则退出否则重试 + wget -Y off $agent $progress $redirect $certificate --timeout=5 -O "$2" "$3" + return $? + elif curl --version >/dev/null 2>&1; then + [ "$4" = "echooff" ] && progress='-s' || progress='-#' + [ "$5" = "rediroff" ] && redirect='' || redirect='-L' + [ "$6" = "skipceroff" ] && certificate='' || certificate='-k' + if curl --version | grep -q '^curl 8.' && ckcmd base64; then + auth_b64=$(printf '%s' "$authentication" | base64) + result=$(curl $agent -w '%{http_code}' --connect-timeout 3 --proxy-header "Proxy-Authorization: Basic $auth_b64" $progress $redirect $certificate -o "$2" "$url") + else + result=$(curl $agent -w '%{http_code}' --connect-timeout 3 $progress $redirect $certificate -o "$2" "$url") + fi + [ "$result" = "200" ] && return 0 #成功则退出否则重试 + export all_proxy="" + result=$(curl $agent -w '%{http_code}' --connect-timeout 5 $progress $redirect $certificate -o "$2" "$3") + [ "$result" = "200" ] + return $? + elif ckcmd wget;then + [ "$4" = "echooff" ] && progress='-q' + wget -Y on $progress -O "$2" "$url" && return 0 #成功则退出否则重试 + wget -Y off $progress -O "$2" "$3" + return $? + else + echo "找不到可用下载工具!!!请安装Curl或Wget!!!" + return 1 + fi +} \ No newline at end of file diff --git a/scripts/libs/web_get_bin.sh b/scripts/libs/web_get_bin.sh new file mode 100644 index 00000000..67e40156 --- /dev/null +++ b/scripts/libs/web_get_bin.sh @@ -0,0 +1,18 @@ +. "$CRASHDIR"/libs/web_get.sh + +get_bin() { #专用于项目内部文件的下载 + [ -z "$update_url" ] && update_url=https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@master + if [ -n "$url_id" ]; then + echo "$2" | grep -q '^bin/' && release_type=update #/bin文件改为在update分支下载 + echo "$2" | grep -qE '^public/|^rules/' && release_type=dev #/public和/rules文件改为在dev分支下载 + [ -z "$release_type" ] && release_type=master + if [ "$url_id" = 101 -o "$url_id" = 104 ]; then + url="$(grep "$url_id" "$CRASHDIR"/configs/servers.list | awk '{print $3}')@$release_type/$2" #jsdelivr特殊处理 + else + url="$(grep "$url_id" "$CRASHDIR"/configs/servers.list | awk '{print $3}')/$release_type/$2" + fi + else + url="$update_url/$2" + fi + webget "$1" "$url" "$3" "$4" "$5" "$6" +} \ No newline at end of file