diff --git a/Dockerfile b/Dockerfile index a7251815..06b33adf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ ENV LANG="C.UTF-8" \ PUID=0 \ PGID=0 \ UMASK=000 \ + MOVIEPILOT_AUTO_UPDATE=true \ NGINX_PORT=3000 \ CONFIG_DIR="/config" \ API_TOKEN="moviepilot" \ @@ -45,6 +46,8 @@ RUN apt-get update \ curl \ busybox \ && cp -f nginx.conf /etc/nginx/nginx.template.conf \ + && cp update /usr/local/bin/mp_update \ + && chmod +x /usr/local/bin/mp_update \ && mkdir -p ${HOME} \ && groupadd -r moviepilot -g 911 \ && useradd -r moviepilot -g moviepilot -d ${HOME} -s /bin/bash -u 911 \ diff --git a/start.sh b/start.sh index 39936792..69e55d44 100644 --- a/start.sh +++ b/start.sh @@ -2,6 +2,12 @@ # 使用 `envsubst` 将模板文件中的 ${NGINX_PORT} 替换为实际的环境变量值 envsubst '${NGINX_PORT}' < /etc/nginx/nginx.template.conf > /etc/nginx/nginx.conf +# 自动更新 +if [ "${MOVIEPILOT_AUTO_UPDATE}" = "true" ]; then + mp_update +else + echo "程序自动升级已关闭,如需自动升级请在创建容器时设置环境变量:MOVIEPILOT_AUTO_UPDATE=true" +fi # 更改 moviepilot userid 和 groupid groupmod -o -g ${PGID} moviepilot usermod -o -u ${PUID} moviepilot diff --git a/update b/update new file mode 100644 index 00000000..865559f4 --- /dev/null +++ b/update @@ -0,0 +1,28 @@ +#!/bin/bash + +old_version=$(cat /app/version.py) +new_version=$(curl -sL https://raw.githubusercontent.com/jxxghp/MoviePilot/main/version.py) +release_version=v$(echo ${new_version} | sed -ne "s/APP_VERSION\s=\s'v\(.*\)'/\1/gp") + +if [ "${old_version}" != "${new_version}" ]; then + echo "发现新版本,开始更新程序..." + curl -sL "https://github.com/jxxghp/MoviePilot/archive/refs/tags/${release_version}.zip" | busybox unzip -d /tmp - + if [ $? -eq 0 ]; then + echo "后端下载成功" + curl -sL "https://github.com/jxxghp/MoviePilot-Frontend/releases/download/${release_version}/dist.zip" | busybox unzip -d /tmp - + if [ $? -eq 0 ]; then + echo "前端下载成功" + rm -rf /app + mv /tmp/MoviePilot* /app + rm -rf /public + mv /tmp/dist /public + echo "程序更新成功" + else + echo "前端下载失败,继续使用旧的程序来启动..." + fi + else + echo "后端下载失败,继续使用旧的程序来启动..." + fi +else + echo "未发现新版本,跳过更新步骤" +fi \ No newline at end of file