Merge pull request #2626 from DDS-Derek/dev

This commit is contained in:
jxxghp
2024-08-05 16:06:36 +08:00
committed by GitHub
2 changed files with 78 additions and 89 deletions
+78 -47
View File
@@ -41,8 +41,8 @@ function install_backend_and_download_resources() {
if download_and_unzip "${GITHUB_PROXY}https://github.com/jxxghp/MoviePilot/archive/refs/${1}" "App"; then if download_and_unzip "${GITHUB_PROXY}https://github.com/jxxghp/MoviePilot/archive/refs/${1}" "App"; then
INFO "后端程序下载成功" INFO "后端程序下载成功"
INFO "依赖安装中..." INFO "依赖安装中..."
pip install ${PIP_OPTIONS} --upgrade --root-user-action pip > /dev/null pip install ${PIP_OPTIONS} --upgrade --root-user-action=ignore pip > /dev/null
if pip install ${PIP_OPTIONS} --root-user-action -r /tmp/App/requirements.txt > /dev/null; then if pip install ${PIP_OPTIONS} --root-user-action=ignore -r /tmp/App/requirements.txt > /dev/null; then
INFO "安装依赖成功" INFO "安装依赖成功"
frontend_version=$(curl ${CURL_OPTIONS} "https://api.github.com/repos/jxxghp/MoviePilot-Frontend/releases/latest" ${CURL_HEADERS} | jq -r .tag_name) frontend_version=$(curl ${CURL_OPTIONS} "https://api.github.com/repos/jxxghp/MoviePilot-Frontend/releases/latest" ${CURL_HEADERS} | jq -r .tag_name)
if [[ "${frontend_version}" == *v* ]]; then if [[ "${frontend_version}" == *v* ]]; then
@@ -80,7 +80,7 @@ function install_backend_and_download_resources() {
# 插件仓库 # 插件仓库
rsync -av --remove-source-files /tmp/Plugins/plugins/* /app/app/plugins/ > /dev/null rsync -av --remove-source-files /tmp/Plugins/plugins/* /app/app/plugins/ > /dev/null
# 提前安装插件依赖 # 提前安装插件依赖
find /app/app/plugins -name requirements.txt -exec pip install --root-user-action ${PIP_OPTIONS} -r {} \; > /dev/null find /app/app/plugins -name requirements.txt -exec pip install --root-user-action=ignore ${PIP_OPTIONS} -r {} \; > /dev/null
# 清理临时目录 # 清理临时目录
rm -rf /tmp/* rm -rf /tmp/*
INFO "插件更新成功" INFO "插件更新成功"
@@ -116,55 +116,86 @@ function install_backend_and_download_resources() {
fi fi
} }
# 使用python进行URL解析,$1为PROXY_HOST function test_connectivity_pip() {
function parse_url() { pip uninstall -y pip-hello-world > /dev/null 2>&1
local result case "$1" in
result=$(python3 /app/parse_url.py ${1}) 0)
# 解析结果并提取各项 if [[ -n "${PIP_PROXY}" ]]; then
PROTOCOL=$(echo "$result" | grep "^SCHEME:" | awk '{print $2}') if pip install -i ${PIP_PROXY} pip-hello-world > /dev/null 2>&1; then
HOST=$(echo "$result" | grep "^HOST:" | awk '{print $2}') PIP_OPTIONS="-i ${PIP_PROXY}"
PORT=$(echo "$result" | grep "^PORT:" | awk '{print $2}') PIP_LOG="使用Pip镜像代理更新环境依赖"
return 0
fi
fi
return 1
;;
1)
if [[ -n "${PROXY_HOST}" ]]; then
if pip install --proxy=${PROXY_HOST} pip-hello-world > /dev/null 2>&1; then
PIP_OPTIONS="--proxy=${PROXY_HOST}"
PIP_LOG="使用全局代理更新环境依赖"
return 0
fi
fi
return 1
;;
2)
PIP_OPTIONS=""
PIP_LOG="不使用代理更新环境依赖"
return 0
;;
esac
}
function test_connectivity_github() {
case "$1" in
0)
if [[ -n "${GITHUB_PROXY}" ]]; then
if curl -sL "${GITHUB_PROXY}https://raw.githubusercontent.com/jxxghp/MoviePilot/main/README.md" > /dev/null 2>&1; then
PIP_LOG="使用Pip镜像代理更新环境依赖"
return 0
fi
fi
return 1
;;
1)
if [[ -n "${PROXY_HOST}" ]]; then
if curl -sL -x ${PROXY_HOST} https://raw.githubusercontent.com/jxxghp/MoviePilot/main/README.md > /dev/null 2>&1; then
CURL_OPTIONS="-sL -x ${PROXY_HOST}"
GITHUB_LOG="使用全局代理更新程序"
return 0
fi
fi
return 1
;;
2)
CURL_OPTIONS="-sL"
GITHUB_LOG="不使用代理更新程序"
return 0
;;
esac
} }
if [[ "${MOVIEPILOT_AUTO_UPDATE}" = "true" ]] || [[ "${MOVIEPILOT_AUTO_UPDATE}" = "release" ]] || [[ "${MOVIEPILOT_AUTO_UPDATE}" = "dev" ]]; then if [[ "${MOVIEPILOT_AUTO_UPDATE}" = "true" ]] || [[ "${MOVIEPILOT_AUTO_UPDATE}" = "release" ]] || [[ "${MOVIEPILOT_AUTO_UPDATE}" = "dev" ]]; then
# 解析代理地址,判断代理合法性
if [[ -n "${PROXY_HOST}" ]]; then
parse_url "${PROXY_HOST}"
INFO "检测到代理地址,开始解析..."
if [[ "${PROTOCOL}" =~ ^(http|https|socks4|socks4a|socks5|socks5h)$ ]] && [[ -n "${HOST}" && -n "${PORT}" ]]; then
PROXY_HOST_MODE="true"
else
PROXY_HOST_MODE="false"
WARN "【PROXY_HOST】代理地址不符合要求,无法使用全局代理环境,开始使用其他更新方式"
fi
fi
# 初始化变量
PIP_PROXY=${PIP_PROXY:-""}
GITHUB_PROXY=${GITHUB_PROXY:-""}
PIP_OPTIONS=""
CURL_OPTIONS="-sL"
# 优先级:镜像站 > 全局 > 不代理 # 优先级:镜像站 > 全局 > 不代理
# pip # pip
if [[ -n "${PIP_PROXY}" ]]; then retries=0
PIP_OPTIONS="-i ${PIP_PROXY}" while true; do
PIP_LOG="使用Pip镜像代理更新环境依赖" if test_connectivity_pip ${retries}; then
elif [[ -n "${PROXY_HOST}" && "${PROXY_HOST_MODE}" = "true" ]]; then break
PIP_OPTIONS="--proxy=${PROXY_HOST}" else
PIP_LOG="使用全局代理更新环境依赖" retries=$((retries + 1))
else fi
PIP_OPTIONS="" done
PIP_LOG="不使用代理更新环境依赖" # Github
fi retries=0
# GitHub while true; do
if [[ -n "${GITHUB_PROXY}" ]]; then if test_connectivity_github ${retries}; then
GITHUB_LOG="使用Github镜像代理更新程序" break
elif [[ -n "${PROXY_HOST}" && "${PROXY_HOST_MODE}" = "true" ]]; then else
CURL_OPTIONS="-sL -x ${PROXY_HOST}" retries=$((retries + 1))
GITHUB_LOG="使用全局代理更新程序" fi
else done
CURL_OPTIONS="-sL"
GITHUB_LOG="不使用代理更新程序"
fi
INFO "${PIP_LOG}${GITHUB_LOG}" INFO "${PIP_LOG}${GITHUB_LOG}"
if [ -n "${GITHUB_TOKEN}" ]; then if [ -n "${GITHUB_TOKEN}" ]; then
CURL_HEADERS="--oauth2-bearer ${GITHUB_TOKEN}" CURL_HEADERS="--oauth2-bearer ${GITHUB_TOKEN}"
-42
View File
@@ -1,42 +0,0 @@
import sys
from urllib.parse import urlparse
def parse_url(url):
parsed_url = urlparse(url)
# 提取各个部分
protocol = parsed_url.scheme or ""
hostname = parsed_url.hostname or ""
port = parsed_url.port or ""
if hostname:
hostname = hostname.lower()
if not port:
if protocol == "https":
port = 443
elif protocol == "http":
port = 80
elif protocol in {"socks5", "socks5h", "socks4", "socks4a"}:
port = 1080
if protocol:
protocol = protocol.lower()
# 打印提取的部分
print(f"SCHEME:{protocol}")
print(f"HOST:{hostname}")
print(f"PORT:{port}")
if __name__ == "__main__":
# 参数不全,直接返回空解析结果
if len(sys.argv) != 2:
print(f"SCHEME:''")
print(f"HOST:''")
print(f"PORT:''")
# 参数全,解析URL
else:
PROXY_HOST = sys.argv[1]
parse_url(url=PROXY_HOST)