|
1 | 1 | #!/bin/bash
|
| 2 | +# shellcheck shell=bash |
2 | 3 |
|
3 | 4 | # 下载及解压
|
4 | 5 | download_and_unzip() {
|
5 | 6 | url="$1"
|
6 | 7 | target_dir="$2"
|
7 | 8 | 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}" |
13 | 11 | else
|
14 | 12 | return 1
|
15 | 13 | fi
|
16 | 14 | }
|
17 | 15 |
|
18 | 16 | # 下载程序资源,$1: 后端版本路径
|
19 | 17 | 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 |
22 | 19 | 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 |
26 | 22 | 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 "资源包下载成功" |
53 | 58 | # 资源包
|
54 | 59 | cp -a /tmp/Resources/resources/* /app/app/helper/
|
55 |
| - # 前端程序 |
56 |
| - rm -rf /public |
57 |
| - mkdir -p /public |
58 |
| - cp -a /tmp/dist/* /public/ |
59 | 60 | # 清理临时目录
|
60 | 61 | rm -rf /tmp/*
|
61 |
| - echo "程序更新成功,前端版本:${frontend_version},后端版本:${1}" |
| 62 | + echo "资源包更新成功" |
62 | 63 | else
|
63 |
| - echo "前端程序下载失败,继续使用旧的程序来启动..." |
| 64 | + echo "资源包下载失败,继续使用旧的资源包来启动..." |
64 | 65 | fi
|
65 | 66 | else
|
66 |
| - echo "前端最新版本号获取失败,继续启动..." |
| 67 | + echo "插件下载失败,继续使用旧的插件来启动..." |
67 | 68 | fi
|
68 | 69 | else
|
69 |
| - echo "资源包下载失败,继续使用旧的程序来启动..." |
| 70 | + echo "前端程序下载失败,继续使用旧的程序来启动..." |
70 | 71 | fi
|
71 | 72 | else
|
72 |
| - echo "插件下载失败,继续使用旧的程序来启动..." |
| 73 | + echo "前端最新版本号获取失败,继续启动..." |
73 | 74 | fi
|
74 | 75 | else
|
75 | 76 | echo "安装依赖失败,请重新拉取镜像"
|
@@ -100,9 +101,9 @@ if [[ "${MOVIEPILOT_AUTO_UPDATE}" = "true" ]] || [[ "${MOVIEPILOT_AUTO_UPDATE}"
|
100 | 101 | echo "Release 更新模式"
|
101 | 102 | old_version=$(cat /app/version.py)
|
102 | 103 | 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") |
104 | 105 | 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) |
106 | 107 | if [[ "${new_version}" == *v* ]]; then
|
107 | 108 | release_version=${new_version}
|
108 | 109 | echo "最新版本号:${release_version}"
|
|
0 commit comments