forked from jxxghp/MoviePilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate
121 lines (118 loc) · 5.37 KB
/
update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
# 下载及解压
download_and_unzip() {
url="$1"
target_dir="$2"
echo "正在下载 ${url}..."
curl ${CURL_OPTIONS} "$url" ${CURL_HEADERS} | busybox unzip -d /tmp -
if [ $? -eq 0 ]; then
if [ -e /tmp/MoviePilot-* ]; then
mv /tmp/MoviePilot-* /tmp/${target_dir}
fi
else
return 1
fi
}
# 下载程序资源,$1: 后端版本路径
install_backend_and_download_resources() {
download_and_unzip "https://github.com/jxxghp/MoviePilot/archive/refs/${1}" "App"
if [ $? -eq 0 ]; then
echo "后端程序下载成功"
pip install ${PIP_OPTIONS} --upgrade pip
pip install ${PIP_OPTIONS} -r /tmp/App/requirements.txt
if [ $? -eq 0 ]; then
echo "安装依赖成功"
download_and_unzip "https://github.com/jxxghp/MoviePilot-Plugins/archive/refs/heads/main.zip" "Plugins"
if [ $? -eq 0 ]; then
echo "插件下载成功"
download_and_unzip "https://github.com/jxxghp/MoviePilot-Resources/archive/refs/heads/main.zip" "Resources"
if [ $? -eq 0 ]; then
echo "资源包下载成功"
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
download_and_unzip "https://github.com/jxxghp/MoviePilot-Frontend/releases/download/${frontend_version}/dist.zip" "dist"
if [ $? -eq 0 ]; then
echo "前端程序下载成功"
# 备份插件目录
rm -rf /plugins
mv /app/app/plugins /plugins
# 清空目录
rm -rf /app
# 后端程序
mv /tmp/App /app
# 恢复插件目录
mv -f /plugins/* /app/app/plugins/
# 插件仓库
rsync -av --remove-source-files /tmp/Plugins/plugins/* /app/app/plugins/
# 资源包
mv -f /tmp/Resources/resources/* /app/app/helper/
# 前端程序
rm -rf /public
mv /tmp/dist /public
# 清理临时目录
rm -rf /tmp/*
echo "程序更新成功,前端版本:${frontend_version},后端版本:${1}"
else
echo "前端程序下载失败,继续使用旧的程序来启动..."
fi
else
echo "前端最新版本号获取失败,继续启动..."
fi
else
echo "资源包下载失败,继续使用旧的程序来启动..."
fi
else
echo "插件下载失败,继续使用旧的程序来启动..."
fi
else
echo "安装依赖失败,请重新拉取镜像"
fi
else
echo "后端程序下载失败,继续使用旧的程序来启动..."
fi
}
if [[ "${MOVIEPILOT_AUTO_UPDATE}" = "true" ]] || [[ "${MOVIEPILOT_AUTO_UPDATE}" = "release" ]] || [[ "${MOVIEPILOT_AUTO_UPDATE}" = "dev" ]]; then
if [ -n "${PROXY_HOST}" ]; then
CURL_OPTIONS="-sL -x ${PROXY_HOST}"
PIP_OPTIONS="--proxy=${PROXY_HOST}"
echo "使用代理更新程序"
else
CURL_OPTIONS="-sL"
echo "不使用代理更新程序"
fi
if [ -n "${GITHUB_TOKEN}" ]; then
CURL_HEADERS="--header 'Authorization: Bearer ${GITHUB_TOKEN}'"
else
CURL_HEADERS=""
fi
if [ "${MOVIEPILOT_AUTO_UPDATE}" = "dev" ]; then
echo "Dev 更新模式"
install_backend_and_download_resources "heads/main.zip"
else
echo "Release 更新模式"
old_version=$(cat /app/version.py)
if [[ "${old_version}" == *APP_VERSION* ]]; then
current_version=v$(echo ${old_version} | sed -ne "s/APP_VERSION\s=\s'v\(.*\)'/\1/gp")
echo "当前版本号:${current_version}"
new_version=$(curl ${CURL_OPTIONS} "https://api.github.com/repos/jxxghp/MoviePilot/releases/latest" ${CURL_HEADERS} | jq -r .tag_name)
if [[ "${new_version}" == *v* ]]; then
release_version=${new_version}
echo "最新版本号:${release_version}"
if [ "${current_version}" != "${release_version}" ]; then
echo "发现新版本,开始自动升级..."
install_backend_and_download_resources "tags/${release_version}.zip"
else
echo "未发现新版本,跳过更新步骤..."
fi
else
echo "最新版本号获取失败,继续启动..."
fi
else
echo "当前版本号获取失败,继续启动..."
fi
fi
elif [[ "${MOVIEPILOT_AUTO_UPDATE}" = "false" ]]; then
echo "程序自动升级已关闭,如需自动升级请在创建容器时设置环境变量:MOVIEPILOT_AUTO_UPDATE=release"
else
echo "MOVIEPILOT_AUTO_UPDATE 变量设置错误"
fi