Skip to content

Commit daa8d80

Browse files
DDSRemDDSDerekhonue
committed
feat: startup and update script optimization
1. 修复Shellcheck指出的问题,增强脚本稳定性。 2. 对于更新部分:采取先更新主程序和前端,插件和资源包再更新的原则;主要解决如果插件或资源包没有下载成功,主程序就无法更新成功的问题,但是其实资源包和插件是不影响主程序更新的。 Co-Authored-By: DDSDerek <108336573+DDSDerek@users.noreply.github.com> Co-Authored-By: Summer⛱ <57806936+honue@users.noreply.github.com>
1 parent f43efab commit daa8d80

File tree

2 files changed

+55
-52
lines changed

2 files changed

+55
-52
lines changed

entrypoint

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#!/bin/bash
2+
# shellcheck shell=bash
3+
# shellcheck disable=SC2016
24

35
# 使用 `envsubst` 将模板文件中的 ${NGINX_PORT} 替换为实际的环境变量值
46
envsubst '${NGINX_PORT}${PORT}' < /etc/nginx/nginx.template.conf > /etc/nginx/nginx.conf
57
# 自动更新
68
cd /
79
/usr/local/bin/mp_update
8-
cd /app
10+
cd /app || exit
911
# 更改 moviepilot userid 和 groupid
10-
groupmod -o -g ${PGID} moviepilot
11-
usermod -o -u ${PUID} moviepilot
12+
groupmod -o -g "${PGID}" moviepilot
13+
usermod -o -u "${PUID}" moviepilot
1214
# 更改文件权限
1315
chown -R moviepilot:moviepilot \
14-
${HOME} \
16+
"${HOME}" \
1517
/app \
1618
/public \
1719
/config \
@@ -27,6 +29,6 @@ if [ -S "/var/run/docker.sock" ]; then
2729
haproxy -f /app/haproxy.cfg
2830
fi
2931
# 设置后端服务权限掩码
30-
umask ${UMASK}
32+
umask "${UMASK}"
3133
# 启动后端服务
3234
exec dumb-init gosu moviepilot:moviepilot python3 app/main.py

update

+48-47
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,76 @@
11
#!/bin/bash
2+
# shellcheck shell=bash
23

34
# 下载及解压
45
download_and_unzip() {
56
url="$1"
67
target_dir="$2"
78
echo "正在下载 ${url}..."
8-
curl ${CURL_OPTIONS} "$url" ${CURL_HEADERS} | busybox unzip -d /tmp -
9-
if [ $? -eq 0 ]; then
10-
if [ -e /tmp/MoviePilot-* ]; then
11-
mv /tmp/MoviePilot-* /tmp/${target_dir}
12-
fi
9+
if curl "${CURL_OPTIONS}" "${url}" "${CURL_HEADERS}" | busybox unzip -d /tmp -; then
10+
mv /tmp/MoviePilot-* /tmp/"${target_dir}"
1311
else
1412
return 1
1513
fi
1614
}
1715

1816
# 下载程序资源,$1: 后端版本路径
1917
install_backend_and_download_resources() {
20-
download_and_unzip "https://github.com/jxxghp/MoviePilot/archive/refs/${1}" "App"
21-
if [ $? -eq 0 ]; then
18+
if download_and_unzip "https://github.com/jxxghp/MoviePilot/archive/refs/${1}" "App"; then
2219
echo "后端程序下载成功"
23-
pip install ${PIP_OPTIONS} --upgrade pip
24-
pip install ${PIP_OPTIONS} -r /tmp/App/requirements.txt
25-
if [ $? -eq 0 ]; then
20+
pip install "${PIP_OPTIONS}" --upgrade pip
21+
if pip install "${PIP_OPTIONS}" -r /tmp/App/requirements.txt; then
2622
echo "安装依赖成功"
27-
download_and_unzip "https://github.com/jxxghp/MoviePilot-Plugins/archive/refs/heads/main.zip" "Plugins"
28-
if [ $? -eq 0 ]; then
29-
echo "插件下载成功"
30-
download_and_unzip "https://github.com/jxxghp/MoviePilot-Resources/archive/refs/heads/main.zip" "Resources"
31-
if [ $? -eq 0 ]; then
32-
echo "资源包下载成功"
33-
frontend_version=$(curl ${CURL_OPTIONS} "https://api.github.com/repos/jxxghp/MoviePilot-Frontend/releases/latest" ${CURL_HEADERS} | jq -r .tag_name)
34-
if [[ "${frontend_version}" == *v* ]]; then
35-
download_and_unzip "https://github.com/jxxghp/MoviePilot-Frontend/releases/download/${frontend_version}/dist.zip" "dist"
36-
if [ $? -eq 0 ]; then
37-
echo "前端程序下载成功"
38-
# 备份插件目录
39-
rm -rf /plugins
40-
mkdir -p /plugins
41-
cp -a /app/app/plugins/* /plugins/
42-
# 不备份__init__.py
43-
rm -f /plugins/__init__.py
44-
# 清空目录
45-
rm -rf /app
46-
mkdir -p /app
47-
# 后端程序
48-
cp -a /tmp/App/* /app/
49-
# 恢复插件目录
50-
cp -a /plugins/* /app/app/plugins/
51-
# 插件仓库
52-
rsync -av --remove-source-files /tmp/Plugins/plugins/* /app/app/plugins/
23+
frontend_version=$(curl "${CURL_OPTIONS}" "https://api.github.com/repos/jxxghp/MoviePilot-Frontend/releases/latest" "${CURL_HEADERS}" | jq -r .tag_name)
24+
if [[ "${frontend_version}" == *v* ]]; then
25+
if download_and_unzip "https://github.com/jxxghp/MoviePilot-Frontend/releases/download/${frontend_version}/dist.zip" "dist"; then
26+
echo "前端程序下载成功"
27+
# 清空目录
28+
rm -rf /app
29+
mkdir -p /app
30+
# 后端程序
31+
cp -a /tmp/App/* /app/
32+
# 前端程序
33+
rm -rf /public
34+
mkdir -p /public
35+
cp -a /tmp/dist/* /public/
36+
# 清理临时目录
37+
rm -rf /tmp/*
38+
echo "程序部分更新成功,前端版本:${frontend_version},后端版本:${1}"s
39+
echo "开始更新插件..."
40+
if download_and_unzip "https://github.com/jxxghp/MoviePilot-Plugins/archive/refs/heads/main.zip" "Plugins"; then
41+
echo "插件下载成功"
42+
# 备份插件目录
43+
rm -rf /plugins
44+
mkdir -p /plugins
45+
cp -a /app/app/plugins/* /plugins/
46+
# 不备份__init__.py
47+
rm -f /plugins/__init__.py
48+
# 恢复插件目录
49+
cp -a /plugins/* /app/app/plugins/
50+
# 插件仓库
51+
rsync -av --remove-source-files /tmp/Plugins/plugins/* /app/app/plugins/
52+
# 清理临时目录
53+
rm -rf /tmp/*
54+
echo "插件更新成功"
55+
echo "开始更新资源包..."
56+
if download_and_unzip "https://github.com/jxxghp/MoviePilot-Resources/archive/refs/heads/main.zip" "Resources"; then
57+
echo "资源包下载成功"
5358
# 资源包
5459
cp -a /tmp/Resources/resources/* /app/app/helper/
55-
# 前端程序
56-
rm -rf /public
57-
mkdir -p /public
58-
cp -a /tmp/dist/* /public/
5960
# 清理临时目录
6061
rm -rf /tmp/*
61-
echo "程序更新成功,前端版本:${frontend_version},后端版本:${1}"
62+
echo "资源包更新成功"
6263
else
63-
echo "前端程序下载失败,继续使用旧的程序来启动..."
64+
echo "资源包下载失败,继续使用旧的资源包来启动..."
6465
fi
6566
else
66-
echo "前端最新版本号获取失败,继续启动..."
67+
echo "插件下载失败,继续使用旧的插件来启动..."
6768
fi
6869
else
69-
echo "资源包下载失败,继续使用旧的程序来启动..."
70+
echo "前端程序下载失败,继续使用旧的程序来启动..."
7071
fi
7172
else
72-
echo "插件下载失败,继续使用旧的程序来启动..."
73+
echo "前端最新版本号获取失败,继续启动..."
7374
fi
7475
else
7576
echo "安装依赖失败,请重新拉取镜像"
@@ -100,9 +101,9 @@ if [[ "${MOVIEPILOT_AUTO_UPDATE}" = "true" ]] || [[ "${MOVIEPILOT_AUTO_UPDATE}"
100101
echo "Release 更新模式"
101102
old_version=$(cat /app/version.py)
102103
if [[ "${old_version}" == *APP_VERSION* ]]; then
103-
current_version=v$(echo ${old_version} | sed -ne "s/APP_VERSION\s=\s'v\(.*\)'/\1/gp")
104+
current_version=v$(echo "${old_version}" | sed -ne "s/APP_VERSION\s=\s'v\(.*\)'/\1/gp")
104105
echo "当前版本号:${current_version}"
105-
new_version=$(curl ${CURL_OPTIONS} "https://api.github.com/repos/jxxghp/MoviePilot/releases/latest" ${CURL_HEADERS} | jq -r .tag_name)
106+
new_version=$(curl "${CURL_OPTIONS}" "https://api.github.com/repos/jxxghp/MoviePilot/releases/latest" "${CURL_HEADERS}" | jq -r .tag_name)
106107
if [[ "${new_version}" == *v* ]]; then
107108
release_version=${new_version}
108109
echo "最新版本号:${release_version}"

0 commit comments

Comments
 (0)