diff --git a/.env.versions b/.env.versions index 50db827..6b17219 100644 --- a/.env.versions +++ b/.env.versions @@ -1,16 +1,16 @@ # 本项目版本 -PROJECT_VERSION=0.6.21 +PROJECT_VERSION=0.7.0 #=== start === gui-base images ========================== # `stainless403/gui-base`镜像版本 -GUI_BASE_VERSION=0.3.0 +GUI_BASE_VERSION=0.4.0 # `stainless403/mdcx-builtin-gui-base`镜像版本 -GUI_BASE_MDCX_BUILTIN_VERSION=20231014 +GUI_BASE_MDCX_BUILTIN_VERSION=120231219 # `stainless403/mdcx-src-gui-base`镜像版本 -GUI_BASE_MDCX_SRC_VERSION=0.1.4 +GUI_BASE_MDCX_SRC_VERSION=0.2.0 #=== end === gui-base images ========================== @@ -21,10 +21,10 @@ GUI_BASE_MDCX_SRC_VERSION=0.1.4 WEBTOP_BASE_VERSION=0.1.2 # `stainless403/mdcx-builtin-webtop-base`镜像版本 -WEBTOP_BASE_MDCX_BUILTIN_VERSION=20231014 +WEBTOP_BASE_MDCX_BUILTIN_VERSION=120231219 # `stainless403/mdcx-src-webtop-base`镜像版本 -WEBTOP_BASE_MDCX_SRC_VERSION=0.1.9 +WEBTOP_BASE_MDCX_SRC_VERSION=0.2.0 #=== end === webtop-base images ========================== @@ -32,13 +32,13 @@ WEBTOP_BASE_MDCX_SRC_VERSION=0.1.9 #=== start === build-mdcx images ========================== # `stainless403/build-mdcx-base`镜像版本 -BUILD_MDCX_BASE_VERSION=0.3.0 +BUILD_MDCX_BASE_VERSION=0.4.0 # `stainless403/build-mdcx`镜像版本 -BUILD_MDCX_VERSION=20231014 +BUILD_MDCX_VERSION=120231219 #=== end === build-mdcx images ========================== # MDCx最新版本 -MDCX_APP_VERSION=20231014 \ No newline at end of file +MDCX_APP_VERSION=120231219 \ No newline at end of file diff --git a/.github/workflows/watch-mdcx.yml b/.github/workflows/watch-mdcx.yml index 37b9912..08e5cb3 100644 --- a/.github/workflows/watch-mdcx.yml +++ b/.github/workflows/watch-mdcx.yml @@ -16,7 +16,7 @@ on: type: boolean env: - RELEASE_URL: 'https://api.github.com/repos/anyabc/something/releases/latest' + RELEASE_URL: 'https://api.github.com/repos/sqzw-x/mdcx/releases/latest' ENABLE_WATCH: ${{ secrets.ENABLE_WATCH_MDCX_RELEASE }} GITHUB_CURRENT_REPO: ${{ github.event.repository.name }} GITHUB_API_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }} @@ -65,22 +65,28 @@ jobs: # 获取最新版本信息,返回值为数组,第一个元素为版本号,第二个元素为更新时间 getNewInfo() { - local content=$(curl -s "${{ env.RELEASE_URL }}") - local asset=$(echo $content | jq '.assets'| jq 'map(select(.browser_download_url | contains("-py-")))' | jq '.[0]') + local _content=$(curl -s "${{ env.RELEASE_URL }}") + + # tag名称,作为版本号 + local tagName=$(printf '%s' $_content | jq -r ".tag_name") + local archiveVersion=$(echo $tagName | sed 's/v//g') - if [[ -z "$asset" ]]; then - echo "❌ 查找不到符合条件的asset!" - return 1 + # 源码压缩包(tar格式)链接 + local archiveUrl=$(printf '%s' $_content | jq -r ".tarball_url") + + if [[ -z "$archiveUrl" ]]; then + echo "❌ 从请求结果获取源码压缩包文件下载链接失败!" + echo "🔘 请求链接:$_url" + echo "🔘 请求结果:$_content" + exit 1 fi # https://gitbook.curiouser.top/origin/linux-jq.html#%E4%B8%89%E3%80%81jq%E5%91%BD%E4%BB%A4%E5%8F%82%E6%95%B0 # -r 如果过滤的结果是一个字符串,那么直接写到标准输出(去掉字符串的引号); - local archiveUrl=$(echo $asset | jq -r '.browser_download_url') - local updatedAt=$(echo $asset | jq -r '.updated_at') - - if [[ -z "$archiveUrl" ]]; then - echo "❌ 获取下载链接失败!" - return 1 + local updatedAt=$(printf '%s' $_content | jq -r '.updated_at') + # 如果没有`updated_at`,则取`published_at` + if [[ -z "$updatedAt" ]]; then + updatedAt=$(printf '%s' $_content | jq -r '.published_at') fi if [[ -z "$updatedAt" ]]; then @@ -88,9 +94,6 @@ jobs: return 1 fi - local archiveFullName=$(echo $archiveUrl | grep -oi 'MDCx-py-[a-z0-9]\+.[a-z]\+') - local archiveVersion=$(echo $archiveFullName | sed 's/MDCx-py-//g' | sed 's/\.[^.]*$//') - local info=("$archiveVersion" "$updatedAt") echo "${info[@]}" return 0 @@ -159,7 +162,7 @@ jobs: 🎉 MDCx新版本! 📦 新版本号:${{ steps.check.outputs.newVersion }} 📅 更新时间:${{ steps.check.outputs.newTime }} - 🔗 发布链接:https://github.com/anyabc/something/releases/tag/MDCx + 🔗 发布链接:https://github.com/sqzw-x/mdcx/releases/tag/latest - name: TG Notification - For no new version uses: appleboy/telegram-action@master diff --git a/CHANGELOG.md b/CHANGELOG.md index 48b6d28..391564c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## 更新日志 +### [v0.7.0] - 2023-12-24 +- 1.更改上游源码项目为`sqzw-x/mdcx`,#32 + ### [v0.6.18] - 2023-10-13 - 1.修复: `mdcx-builtin-gui-base`和`mdcx-builtin-gui-base`镜像内的MDCx请求某些https链接时出现`cacert.pem`错误的问题,#25 diff --git a/README.md b/README.md index d1a8982..e3939c0 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,137 @@ [![GitHub stars](https://img.shields.io/github/stars/northsea4/mdcx-docker.svg?style=flat&label=Stars&maxAge=3600)](https://GitHub.com/northsea4/mdcx-docker) [![GitHub release](https://img.shields.io/github/release/northsea4/mdcx-docker.svg?style=flat&label=Release)](https://github.com/northsea4/mdcx-docker/releases/tag/latest) -⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ +👇🏻👇🏻👇🏻👇🏻👇🏻👇🏻👇🏻👇🏻👇🏻👇🏻👇🏻👇🏻👇🏻👇🏻👇🏻👇🏻👇🏻 -📢 上游项目(MDCx)已删库,可部署的最新版镜像为`20231014`,望悉知。 +📢 上游源码项目已更改为[sqzw-x/mdcx](https://github.com/sqzw-x/mdcx),请阅读下面的[更改新源码后的更新说明](https://github.com/northsea4/mdcx-docker#更改新源码后的更新说明)。 -⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ +👆🏻👆🏻👆🏻👆🏻👆🏻👆🏻👆🏻👆🏻👆🏻👆🏻👆🏻👆🏻👆🏻👆🏻👆🏻👆🏻👆🏻 +--- + +## 更改新源码后的更新说明 +由于上游源码变更,本项目也做了相应的调整。如果需要使用`20231014`之后的版本,请参考以下说明进行更新。 + +### 建议的操作 +直接部署新容器,然后将旧容器的配置文件等数据复制到新容器目录中。 + +如果想更新已有的容器,请参考下面的说明。 + +### builtin镜像 +即`mdcx-builtin-gui-base`和`mdcx-builtin-webtop-base`镜像。 + +简单来说,拉取新版镜像,然后重新部署即可。 + +> 注意`.env`里的`MDCX_BUILTIN_IMAGE_TAG`应该是`latest`或者最新的版本号。 + +> 建议先备份配置文件等数据,以免部署失败或未知问题导致数据丢失。 + + docker-compose方式,适用于`mdcx-builtin-gui-base`和`mdcx-builtin-webtop-base` +```shell +cd /path/to/mdcx-docker +# 拉取新版镜像 +docker-compose pull +# 重新部署 +docker-compose up -d +``` + +docker-cli方式,适用于`mdcx-builtin-gui-base` +```shell +cd /path/to/mdcx-docker +# 拉取新版镜像 +docker pull stainless403/mdcx-builtin-gui-base:latest +# 停止并删除容器,容器名称请根据实际情况修改 +docker stop mdcx_builtin_gui +docker rm mdcx_builtin_gui +# 重新部署,此处省略具体命令,请根据部署文档执行相关命令 +docker run ... +``` + +docker-cli方式,适用于`mdcx-builtin-webtop-base` +```shell +cd /path/to/mdcx-docker +# 拉取新版镜像 +docker pull stainless403/mdcx-builtin-webtop-base:latest +# 停止并删除容器,容器名称请根据实际情况修改 +docker stop mdcx_builtin_webtop +docker rm mdcx_builtin_webtop +# 重新部署,此处省略具体命令,请根据部署文档执行相关命令 +docker run ... +``` + +### src镜像 +即`mdcx-src-gui-base`和`mdcx-src-webtop-base`镜像。 + +简单来说,下载新版源码,拉取新版镜像,然后重新部署即可。 + +> 注意`.env`里的`MDCX_BUILTIN_IMAGE_TAG`应该是`latest`或者最新的版本号。 + +> 建议先备份配置文件等数据,以免部署失败或未知问题导致数据丢失。 + +#### 下载新版源码 +##### mdcx-src-gui-base +```shell +cd /path/to/mdcx-docker +# 备份旧版源码 +mv app app-bak +# 下载新版`下载源码脚本` +mv update-src.sh update-src.sh-bak +curl -fsSL https://github.com/northsea4/mdcx-docker/raw/main/gui-base/update-src.sh -o update-src.sh +# 下载新版源码 +bash update-src.sh --verbose +``` + +##### mdcx-src-webtop-base +```shell +cd /path/to/mdcx-docker +# 备份旧版源码 +mv app app-bak +# 下载新版`下载源码脚本` +mv update-src.sh update-src.sh-bak +curl -fsSL https://github.com/northsea4/mdcx-docker/raw/main/webtop-base/update-src.sh -o update-src.sh +# 下载新版源码 +bash update-src.sh --verbose +``` + +#### 重新部署 +##### docker-compose方式,适用于`mdcx-src-gui-base`和`mdcx-src-webtop-base` +```shell +cd /path/to/mdcx-docker +# 拉取新版镜像 +docker-compose pull +# 重新部署 +docker-compose up -d +``` + +##### docker-cli方式,适用于`mdcx-src-gui-base` +```shell +cd /path/to/mdcx-docker +# 拉取新版镜像 +docker pull stainless403/mdcx-src-gui-base:latest +# 停止并删除容器,容器名称请根据实际情况修改 +docker stop mdcx_src_gui +docker rm mdcx_src_gui +# 重新部署,此处省略具体命令,请根据部署文档执行相关命令 +docker run ... +``` + +##### docker-cli方式,适用于`mdcx-src-webtop-base` +```shell +cd /path/to/mdcx-docker +# 拉取新版镜像 +docker pull stainless403/mdcx-src-webtop-base:latest +# 停止并删除容器,容器名称请根据实际情况修改 +docker stop mdcx_src_webtop +docker rm mdcx_src_webtop +# 重新部署,此处省略具体命令,请根据部署文档执行相关命令 +docker run ... +``` + +--- ## 镜像 > 「builtin」表示内置已编译的应用,不需要额外下载安装包。 -> ~~「src」表示使用应用的python源码运行,需要额外下载源码。~~ +> 「src」表示使用应用的python源码运行,需要额外下载源码。 > 「gui」是最简单的版本,通过Web访问,且只能看到应用窗口。 > 「webtop」有比较完整的桌面环境,可以通过Web访问或RDP访问。 @@ -19,8 +140,8 @@ | --- | --- | --- | --- | --- | --- | | [mdcx-builtin-gui-base](https://hub.docker.com/r/stainless403/mdcx-builtin-gui-base/tags) | [查看](https://github.com/northsea4/mdcx-docker/blob/main/gui-base/mdcx-builtin.md) | ✅ | | | | | [mdcx-builtin-webtop-base](https://hub.docker.com/r/stainless403/mdcx-builtin-webtop-base/tags) | [查看](https://github.com/northsea4/mdcx-docker/blob/main/webtop-base/mdcx-builtin.md) | ✅ | ✅ | ✅ | ✅ | -| ~~[mdcx-src-gui-base](https://hub.docker.com/r/stainless403/mdcx-src-gui-base/tags)~~ | ~~[查看](https://github.com/northsea4/mdcx-docker/blob/main/gui-base/mdcx-src.md)~~ | ✅ | | | | -| ~~[mdcx-src-webtop-base](https://hub.docker.com/r/stainless403/mdcx-src-webtop-base/tags)~~ | ~~[查看](https://github.com/northsea4/mdcx-docker/blob/main/webtop-base/mdcx-src.md)~~ | ✅ | ✅ | ✅ | ✅ | +| [mdcx-src-gui-base](https://hub.docker.com/r/stainless403/mdcx-src-gui-base/tags) | [查看](https://github.com/northsea4/mdcx-docker/blob/main/gui-base/mdcx-src.md) | ✅ | | | | +| [mdcx-src-webtop-base](https://hub.docker.com/r/stainless403/mdcx-src-webtop-base/tags) | [查看](https://github.com/northsea4/mdcx-docker/blob/main/webtop-base/mdcx-src.md) | ✅ | ✅ | ✅ | ✅ | ## 使用脚本部署 diff --git a/build-mdcx/Dockerfile.build-mdcx b/build-mdcx/Dockerfile.build-mdcx index 2761648..15452ee 100644 --- a/build-mdcx/Dockerfile.build-mdcx +++ b/build-mdcx/Dockerfile.build-mdcx @@ -48,11 +48,16 @@ RUN python3 -m pip install -r requirements.txt --verbose -i $PYPI_MIRROR RUN pyinstaller -n MDCx \ # 图标是macOS和Windows专属 # -i Img/MDCx.ico \ - -F -w MDCx_Main.py \ - --add-data "Data:." \ - --add-data "Img:Img" \ + -F -w main.py \ + -p "./src" \ + # --add-data "Data:." \ + # --add-data "Img:Img" \ + --add-data "resources:resources" \ + --add-data "libs:." \ --hidden-import socks \ - --hidden-import urllib3 + --hidden-import urllib3 \ + --hidden-import _cffi_backend \ + --collect-all curl_cffi RUN pyinstaller MDCx.spec diff --git a/build-mdcx/Dockerfile.build-mdcx-base b/build-mdcx/Dockerfile.build-mdcx-base index 02dab84..5440405 100644 --- a/build-mdcx/Dockerfile.build-mdcx-base +++ b/build-mdcx/Dockerfile.build-mdcx-base @@ -35,7 +35,7 @@ RUN if [[ -n "$APT_SOURCE_HOST" ]]; then \ fi RUN apt update -y -RUN apt install python3 python3-pip python3-pyqt5 unrar wget curl -y +RUN apt install python3 python3-pip python3-pyqt5 unrar wget curl upx-ucl -y # RUN apt install fonts-wqy-zenhei fonts-noto-color-emoji -y diff --git a/gui-base/mdcx-config/.gitignore b/gui-base/mdcx-config/.gitignore index a8dfb80..3916b53 100644 --- a/gui-base/mdcx-config/.gitignore +++ b/gui-base/mdcx-config/.gitignore @@ -1,3 +1,4 @@ * !.gitignore -!MDCx.config \ No newline at end of file +!MDCx.config +!config.ini \ No newline at end of file diff --git a/gui-base/mdcx-config/config.ini b/gui-base/mdcx-config/config.ini new file mode 100644 index 0000000..e69de29 diff --git a/gui-base/mdcx-src.md b/gui-base/mdcx-src.md index 6040444..378bd5a 100644 --- a/gui-base/mdcx-src.md +++ b/gui-base/mdcx-src.md @@ -152,7 +152,9 @@ mkdir -p $MDCX_DOCKER_DIR && cd $MDCX_DOCKER_DIR # 必须:相关数据或日志目录 mkdir -p app mdcx-config logs data # 必须:配置文件目录标记文件 -echo "/mdcx-config/config.ini" > mdcx-config/MDCx.config +echo "/mdcx-config/config.ini" > mdcx-config/MDCx. +# 确保有config.ini文件 +touch mdcx-config/config.ini # !!!下载源码!!!最方便的就是使用`update-src.sh`脚本,自动下载源码文件到`app`目录 ./update-src.sh diff --git a/gui-base/update-src.sh b/gui-base/update-src.sh index b253aeb..a668613 100755 --- a/gui-base/update-src.sh +++ b/gui-base/update-src.sh @@ -7,6 +7,13 @@ else . .env fi +# 检查是否有jq命令 +if ! command -v jq &> /dev/null +then + echo "❌ 请先安装jq命令!参考:https://command-not-found.com/jq" + exit 1 +fi + FILE_INITIALIZED=".mdcx_initialized" @@ -62,7 +69,7 @@ if [ -n "$help" ]; then echo "示例-检查并更新: ./update-src.sh" echo "" echo "参数说明:" - echo "--restart 更新后重启容器,默认true。可选参数值: 1, 0; true, false" + echo "--restart 更新后重启容器,默认false。可选参数值: 1, 0; true, false" echo "--force 强制更新。默认情况下当已发布版本较新于本地版本时才会更新。" echo "--dry 只检查,不更新" echo "-h, --help 显示帮助信息" @@ -123,27 +130,33 @@ else exit 1 fi -_content=$(curl -s "https://api.github.com/repos/anyabc/something/releases/latest") +_url="https://api.github.com/repos/sqzw-x/mdcx/releases/latest" +_content=$(curl -s "$_url") + +# TODO github workflow里竟然会有比较大的概率获取失败 +if [[ -z "$_content" ]]; then + echo "❌ 请求 $_url 失败!" + exit 1 +fi + +# tag名称,作为版本号 +tagName=$(printf '%s' $_content | jq -r ".tag_name") +archiveVersion=$(echo $tagName | sed 's/v//g') -archiveUrl=$(echo $_content | grep -oi 'https://[a-zA-Z0-9./?=_%:-]*MDCx-py-[a-z0-9]\+.[a-z]\+') +# 源码压缩包(tar格式)链接 +archiveUrl=$(printf '%s' $_content | jq -r ".tarball_url") if [[ -z "$archiveUrl" ]]; then - echo "❌ 获取下载链接失败!" + echo "❌ 从请求结果获取源码压缩包文件下载链接失败!" + echo "🔘 请求链接:$_url" exit 1 fi -archiveFullName=$(echo $archiveUrl | grep -oi 'MDCx-py-[a-z0-9]\+.[a-z]\+') -archiveExt=$(echo $archiveFullName | grep -oi '[a-z]\+$') -archiveVersion=$(echo $archiveFullName | sed 's/MDCx-py-//g' | sed 's/\.[^.]*$//') -archivePureName=$(echo $archiveUrl | grep -oi 'MDCx-py-[a-z0-9]\+') - if [[ -n "$verbose" ]]; then - echo "🔗 下载链接:$archiveUrl" - echo "ℹ️ 压缩包全名:$archiveFullName" - echo "ℹ️ 压缩包文件名:$archivePureName" - echo "ℹ️ 压缩包后缀名:$archiveExt" + echo "ℹ️ TAG名称: $tagName" + echo "🔗 下载链接: $archiveUrl" fi -echo "ℹ️ 已发布版本:$archiveVersion" +echo "ℹ️ 已发布版本: $archiveVersion" # exit @@ -171,7 +184,7 @@ if [[ -n "$shouldUpdate" ]]; then exit 0 fi - archivePath="$archivePureName.rar" + archivePath="$archiveVersion.tar.gz" if [[ -n "$verbose" ]]; then curl -o $archivePath $archiveUrl -L @@ -182,38 +195,32 @@ if [[ -n "$shouldUpdate" ]]; then echo "✅ 下载成功" echo "⏳ 开始解压..." - UNRAR_PATH=$(which unrar) - if [[ -z "$UNRAR_PATH" ]]; then - echo "❌ 没有unrar命令!" - else - # 解压 - unrar x -o+ $archivePath - cp -rfp $archivePureName/* $appPath - # 删除压缩包 - rm -f $archivePath - # 删除解压出来的目录 - rm -rf $archivePureName - echo "✅ 源码已覆盖到 $appPath" - - if [ -f ".env.versions" ]; then - echo "✅ 更新 .env.versions MDCX_APP_VERSION=$archiveVersion" - sed -i -e "s/MDCX_APP_VERSION=[0-9.]\+/MDCX_APP_VERSION=$archiveVersion/" .env.versions - fi + # 解压新的源码到app目录 + tar -zxvf $archivePath -C $appPath --strip-components 1 + # 删除压缩包 + rm -f $archivePath + echo "✅ 源码已覆盖到 $appPath" + + if [ -f ".env.versions" ]; then + echo "✅ 更新 .env.versions MDCX_APP_VERSION=$archiveVersion" + sed -i -e "s/MDCX_APP_VERSION=[0-9.]\+/MDCX_APP_VERSION=$archiveVersion/" .env.versions + fi + if [ -f ".env" ]; then echo "✅ 更新 .env APP_VERSION=$archiveVersion" sed -i -e "s/APP_VERSION=[0-9.]\+/APP_VERSION=$archiveVersion/" .env + fi + + echo "ℹ️ 删除标记文件 $appPath/$FILE_INITIALIZED" + rm -f "$appPath/$FILE_INITIALIZED" - echo "ℹ️ 删除标记文件 $appPath/$FILE_INITIALIZED" - rm -f "$appPath/$FILE_INITIALIZED" - - if [[ -n "MDCX_SRC_CONTAINER_NAME" ]]; then - if [[ "$restart" == "1" || "$restart" == "true" ]]; then - echo "⏳ 重启容器..." - docker restart $MDCX_SRC_CONTAINER_NAME - else - echo "ℹ️ 如果已经部署过容器,执行以下命令重启容器" - echo "docker restart $MDCX_SRC_CONTAINER_NAME" - fi + if [[ -n "MDCX_SRC_CONTAINER_NAME" ]]; then + if [[ "$restart" == "1" || "$restart" == "true" ]]; then + echo "⏳ 重启容器..." + docker restart $MDCX_SRC_CONTAINER_NAME + else + echo "ℹ️ 如果已经部署过容器,执行以下命令重启容器" + echo "docker restart $MDCX_SRC_CONTAINER_NAME" fi fi else diff --git a/install.sh b/install.sh index 2f0e672..7805613 100755 --- a/install.sh +++ b/install.sh @@ -1,9 +1,9 @@ #!/bin/bash -# 检查是否有unrar命令 -if ! command -v unrar &> /dev/null +# 检查是否有jq命令 +if ! command -v jq &> /dev/null then - echo "❌ 未找到unrar命令,请先安装unrar命令。" + echo "❌ 请先安装jq命令!参考:https://command-not-found.com/jq" exit 1 fi @@ -298,31 +298,36 @@ else fi downloadSrc() { - local _url="https://api.github.com/repos/anyabc/something/releases/latest" + local _url="https://api.github.com/repos/sqzw-x/mdcx/releases/latest" local _content=$(curl -s "$_url") - local archiveUrl=$(echo $_content | grep -oi 'https://[a-zA-Z0-9./?=_%:-]*MDCx-py-[a-z0-9]\+.[a-z]\+') + # TODO github workflow里竟然会有比较大的概率获取失败 + if [[ -z "$_content" ]]; then + echo "❌ 请求 $_url 失败!" + exit 1 + fi + + # tag名称,作为版本号 + tagName=$(printf '%s' $_content | jq -r ".tag_name") + archiveVersion=$(echo $tagName | sed 's/v//g') + + # 源码压缩包(tar格式)链接 + archiveUrl=$(printf '%s' $_content | jq -r ".tarball_url") if [[ -z "$archiveUrl" ]]; then - echo "❌ 请求Github API失败!" + echo "❌ 从请求结果获取源码压缩包文件下载链接失败!" echo "🔘 请求链接:$_url" on_error "${DIR_FULL_PATH}" fi - local archiveFullName=$(echo $archiveUrl | grep -oi 'MDCx-py-[a-z0-9]\+.[a-z]\+') - local archiveExt=$(echo $archiveFullName | grep -oi '[a-z]\+$') - local archiveVersion=$(echo $archiveFullName | sed 's/MDCx-py-//g' | sed 's/\.[^.]*$//') - local archivePureName=$(echo $archiveUrl | grep -oi 'MDCx-py-[a-z0-9]\+') - - echo "🔗 下载链接:$archiveUrl" - echo "🔘 压缩包全名:$archiveFullName" - echo "🔘 压缩包文件名:$archivePureName" - echo "🔘 压缩包后缀名:$archiveExt" - - echo "🔘 已发布版本:$archiveVersion" + if [[ -n "$verbose" ]]; then + echo "ℹ️ TAG名称: $tagName" + echo "🔗 下载链接: $archiveUrl" + fi + echo "ℹ️ 已发布版本: $archiveVersion" - archivePath="$archivePureName.rar" + archivePath="$archiveVersion.tar.gz" curl -o $archivePath $archiveUrl -L @@ -333,12 +338,9 @@ downloadSrc() { mkdir -p $appPath # 解压 - unrar x -o+ $archivePath - cp -rfp $archivePureName/* $appPath + tar -zxvf $archivePath -C $appPath --strip-components 1 # 删除压缩包 rm -f $archivePath - # 删除解压出来的目录 - rm -rf $archivePureName echo "✅ 源码已覆盖到 $appPath" echo "🔘 删除标记文件 $appPath/$FILE_INITIALIZED" diff --git a/prepare-src.sh b/prepare-src.sh index 432de64..6d8ab82 100755 --- a/prepare-src.sh +++ b/prepare-src.sh @@ -2,6 +2,14 @@ # 脚本说明:下载应用源码并解压到指定的目录(通过`context`指定)下的`.mdcx_src`目录 # 一般只用于构建镜像流程,普通用户可以忽略。 +# UPDATE 2023-12-24 17:08:03 使用新的源码仓库:https://github.com/sqzw-x/mdcx + +# 检查是否有jq命令 +if ! command -v jq &> /dev/null +then + echo "❌ 请先安装jq命令!参考:https://command-not-found.com/jq" + exit 1 +fi while [[ $# -gt 0 ]] do @@ -41,26 +49,32 @@ cd $context echo "ℹ️ 将从发布仓库下载源码进行构建" -_content=$(curl -s "https://api.github.com/repos/anyabc/something/releases/latest") - -archiveUrl=$(echo $_content | grep -oi 'https://[a-zA-Z0-9./?=_%:-]*MDCx-py-[a-z0-9]\+.[a-z]\+') +_url="https://api.github.com/repos/sqzw-x/mdcx/releases/latest" +_content=$(curl -s "$_url") # TODO github workflow里竟然会有比较大的概率获取失败 -if [[ -z "$archiveUrl" ]]; then - echo "❌ 获取下载链接失败!" +if [[ -z "$_content" ]]; then + echo "❌ 请求 $_url 失败!" exit 1 fi -archiveFullName=$(echo $archiveUrl | grep -oi 'MDCx-py-[a-z0-9]\+.[a-z]\+') -archiveExt=$(echo $archiveFullName | grep -oi '[a-z]\+$') -archiveVersion=$(echo $archiveFullName | sed 's/MDCx-py-//g' | sed 's/\.[^.]*$//') -archivePureName=$(echo $archiveUrl | grep -oi 'MDCx-py-[a-z0-9]\+') +# tag名称,作为版本号 +tagName=$(printf '%s' $_content | jq -r ".tag_name") +archiveVersion=$(echo $tagName | sed 's/v//g') + +# 源码压缩包(tar格式)链接 +archiveUrl=$(printf '%s' $_content | jq -r ".tarball_url") + +if [[ -z "$archiveUrl" ]]; then + echo "❌ 从请求结果获取源码压缩包文件下载链接失败!" + echo "🔘 请求链接:$_url" + echo "🔘 请求结果:$_content" + exit 1 +fi if [[ -n "$verbose" ]]; then + echo "ℹ️ TAG名称: $tagName" echo "🔗 下载链接: $archiveUrl" - echo "ℹ️ 压缩包全名: $archiveFullName" - echo "ℹ️ 压缩包文件名: $archivePureName" - echo "ℹ️ 压缩包后缀名: $archiveExt" fi echo "ℹ️ 已发布版本: $archiveVersion" @@ -71,7 +85,7 @@ fi echo "⏳ 下载文件..." -archivePath="$archivePureName.rar" +archivePath="$archiveVersion.tar.gz" srcDir=".mdcx_src" if [[ -n "$verbose" ]]; then @@ -83,22 +97,12 @@ fi echo "✅ 下载成功" echo "⏳ 开始解压..." -UNRAR_PATH=$(which unrar) -if [[ -z "$UNRAR_PATH" ]]; then - echo "❌ 没有unrar命令!" - exit 1 -else - rm -rf $srcDir - # 解压 - unrar x -o+ $archivePath - mkdir -p $srcDir - cp -rfp $archivePureName/* $srcDir - # 删除压缩包 - rm -f $archivePath - # 删除解压出来的目录 - rm -rf $archivePureName - echo "✅ 源码已解压到 $srcDir" -fi +# 使用tar命令解压 +rm -rf $srcDir +mkdir -p $srcDir +tar -zxvf $archivePath -C $srcDir --strip-components 1 +rm -f $archivePath +echo "✅ 源码已解压到 $srcDir" if [ -n "$GITHUB_ACTIONS" ]; then echo "APP_VERSION=$archiveVersion" >> $GITHUB_OUTPUT diff --git a/scripts/run-src.sh b/scripts/run-src.sh index b89aba4..07f8098 100755 --- a/scripts/run-src.sh +++ b/scripts/run-src.sh @@ -26,6 +26,9 @@ echo "🐍 Python版本: $PYTHON_VERSION" cd /app +# 模块路径在/app/src,所以需要将/app/src加入到PYTHONPATH +export PYTHONPATH=/app/src:$PYTHONPATH + if [ -f "${FILE_INITIALIZED}" -a -f "${FILE_INITIALIZED_INSIDE}" ]; then echo "✅ 应用已初始化" else @@ -63,7 +66,7 @@ fi echo "🚀 启动应用..." -python3 MDCx_Main.py +python3 main.py # 如果启动失败,就删除标记文件,下次启动时重新初始化 if [ $? -ne 0 ]; then diff --git a/webtop-base/Dockerfile.mdcx-builtin-webtop-base b/webtop-base/Dockerfile.mdcx-builtin-webtop-base index c6232c9..8cd690e 100644 --- a/webtop-base/Dockerfile.mdcx-builtin-webtop-base +++ b/webtop-base/Dockerfile.mdcx-builtin-webtop-base @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1.4 -ARG BASE_IMAGE_TAG="ubuntu-22.04" +ARG BASE_IMAGE_TAG="ubuntu-kde-22.04" # 已编译应用的镜像tag ARG MDCX_BIN_IMAGE_TAG="latest" diff --git a/webtop-base/mdcx-config/.gitignore b/webtop-base/mdcx-config/.gitignore index a8dfb80..3916b53 100644 --- a/webtop-base/mdcx-config/.gitignore +++ b/webtop-base/mdcx-config/.gitignore @@ -1,3 +1,4 @@ * !.gitignore -!MDCx.config \ No newline at end of file +!MDCx.config +!config.ini \ No newline at end of file diff --git a/webtop-base/mdcx-config/config.ini b/webtop-base/mdcx-config/config.ini new file mode 100644 index 0000000..e69de29 diff --git a/webtop-base/mdcx-src.md b/webtop-base/mdcx-src.md index 6ce2ce9..e8ad87e 100644 --- a/webtop-base/mdcx-src.md +++ b/webtop-base/mdcx-src.md @@ -166,6 +166,8 @@ mkdir -p $MDCX_DOCKER_DIR && cd $MDCX_DOCKER_DIR mkdir -p app mdcx-config logs data # 必须:配置文件目录标记文件 echo "/mdcx-config/config.ini" > mdcx-config/MDCx.config +# 确保有config.ini文件 +touch mdcx-config/config.ini # !!!下载源码!!!最方便的就是使用`update-src.sh`脚本,自动下载源码文件到`app`目录 ./update-src.sh diff --git a/webtop-base/rootfs-src/app-assets/scripts/run-src.sh b/webtop-base/rootfs-src/app-assets/scripts/run-src.sh index ea08c5a..e333143 100755 --- a/webtop-base/rootfs-src/app-assets/scripts/run-src.sh +++ b/webtop-base/rootfs-src/app-assets/scripts/run-src.sh @@ -42,6 +42,9 @@ echo "🐍 Python版本: $PYTHON_VERSION" cd /app +# 模块路径在/app/src,所以需要将/app/src加入到PYTHONPATH +export PYTHONPATH=/app/src:$PYTHONPATH + if [ -f "${FILE_INITIALIZED}" -a -f "${FILE_INITIALIZED_INSIDE}" ]; then echo "✅ 应用已初始化" else @@ -79,7 +82,7 @@ fi echo "🚀 启动应用..." -python3 MDCx_Main.py +python3 main.py # 如果发生错误 if [ $? -ne 0 ]; then diff --git a/webtop-base/rootfs-src/app-assets/scripts/update-src.sh b/webtop-base/rootfs-src/app-assets/scripts/update-src.sh index 96b316c..d69f357 100755 --- a/webtop-base/rootfs-src/app-assets/scripts/update-src.sh +++ b/webtop-base/rootfs-src/app-assets/scripts/update-src.sh @@ -2,10 +2,10 @@ export LC_ALL=zh_CN.UTF-8 -# 检查是否有unrar命令 -if ! command -v unrar &> /dev/null +# 检查是否有jq命令 +if ! command -v jq &> /dev/null then - echo "❌ 未找到unrar命令,请先安装unrar命令。" + echo "❌ 请先安装jq命令!参考:https://command-not-found.com/jq" exit 1 fi @@ -117,28 +117,33 @@ else appVersion=0 fi +_url="https://api.github.com/repos/sqzw-x/mdcx/releases/latest" +_content=$(curl -s "$_url") -_content=$(curl -s "https://api.github.com/repos/anyabc/something/releases/latest") +# TODO github workflow里竟然会有比较大的概率获取失败 +if [[ -z "$_content" ]]; then + echo "❌ 请求 $_url 失败!" + exit 1 +fi -archiveUrl=$(echo $_content | grep -oi 'https://[a-zA-Z0-9./?=_%:-]*MDCx-py-[a-z0-9]\+.[a-z]\+') +# tag名称,作为版本号 +tagName=$(printf '%s' $_content | jq -r ".tag_name") +archiveVersion=$(echo $tagName | sed 's/v//g') + +# 源码压缩包(tar格式)链接 +archiveUrl=$(printf '%s' $_content | jq -r ".tarball_url") if [[ -z "$archiveUrl" ]]; then - echo "❌ 获取下载链接失败!" + echo "❌ 从请求结果获取源码压缩包文件下载链接失败!" + echo "🔘 请求链接:$_url" exit 1 fi -archiveFullName=$(echo $archiveUrl | grep -oi 'MDCx-py-[a-z0-9]\+.[a-z]\+') -archiveExt=$(echo $archiveFullName | grep -oi '[a-z]\+$') -archiveVersion=$(echo $archiveFullName | sed 's/MDCx-py-//g' | sed 's/\.[^.]*$//') -archivePureName=$(echo $archiveUrl | grep -oi 'MDCx-py-[a-z0-9]\+') - if [[ -n "$verbose" ]]; then - echo " 下载链接:$archiveUrl" - echo "ℹ️ 压缩包全名:$archiveFullName" - echo "ℹ️ 压缩包文件名:$archivePureName" - echo "ℹ️ 压缩包后缀名:$archiveExt" + echo "ℹ️ TAG名称: $tagName" + echo "🔗 下载链接: $archiveUrl" fi -echo "ℹ️ 已发布版本:$archiveVersion" +echo "ℹ️ 已发布版本: $archiveVersion" compareVersion $archiveVersion $appVersion @@ -165,7 +170,7 @@ if [[ -n "$shouldUpdate" ]]; then exit 0 fi - archivePath="$archivePureName.rar" + archivePath="$archiveVersion.tar.gz" if [[ -n "$verbose" ]]; then curl -o $archivePath $archiveUrl -L @@ -176,13 +181,10 @@ if [[ -n "$shouldUpdate" ]]; then echo "✅ 下载成功" echo "⏳ 开始解压..." - # 解压 - unrar x -o+ $archivePath - cp -rfp $archivePureName/* $appPath + # 解压新的源码到app目录 + tar -zxvf $archivePath -C $appPath --strip-components 1 # 删除压缩包 rm -f $archivePath - # 删除解压出来的目录 - rm -rf $archivePureName echo "✅ 源码已覆盖到 $appPath" echo "ℹ️ 删除标记文件 $appPath/$FILE_INITIALIZED" diff --git a/webtop-base/update-src.sh b/webtop-base/update-src.sh index 16baf6b..4c7f1fd 100755 --- a/webtop-base/update-src.sh +++ b/webtop-base/update-src.sh @@ -7,6 +7,13 @@ else . .env fi +# 检查是否有jq命令 +if ! command -v jq &> /dev/null +then + echo "❌ 请先安装jq命令!参考:https://command-not-found.com/jq" + exit 1 +fi + FILE_INITIALIZED=".mdcx_initialized" @@ -62,7 +69,7 @@ if [ -n "$help" ]; then echo "示例-检查并更新: ./update-src.sh" echo "" echo "参数说明:" - echo "--restart 更新后重启容器,默认true。可选参数值: 1, 0; true, false" + echo "--restart 更新后重启容器,默认false。可选参数值: 1, 0; true, false" echo "--force 强制更新。默认情况下当已发布版本较新于本地版本时才会更新。" echo "--dry 只检查,不更新" echo "-h, --help 显示帮助信息" @@ -123,27 +130,33 @@ else exit 1 fi -_content=$(curl -s "https://api.github.com/repos/anyabc/something/releases/latest") +_url="https://api.github.com/repos/sqzw-x/mdcx/releases/latest" +_content=$(curl -s "$_url") + +# TODO github workflow里竟然会有比较大的概率获取失败 +if [[ -z "$_content" ]]; then + echo "❌ 请求 $_url 失败!" + exit 1 +fi + +# tag名称,作为版本号 +tagName=$(printf '%s' $_content | jq -r ".tag_name") +archiveVersion=$(echo $tagName | sed 's/v//g') -archiveUrl=$(echo $_content | grep -oi 'https://[a-zA-Z0-9./?=_%:-]*MDCx-py-[a-z0-9]\+.[a-z]\+') +# 源码压缩包(tar格式)链接 +archiveUrl=$(printf '%s' $_content | jq -r ".tarball_url") if [[ -z "$archiveUrl" ]]; then - echo "❌ 获取下载链接失败!" + echo "❌ 从请求结果获取源码压缩包文件下载链接失败!" + echo "🔘 请求链接:$_url" exit 1 fi -archiveFullName=$(echo $archiveUrl | grep -oi 'MDCx-py-[a-z0-9]\+.[a-z]\+') -archiveExt=$(echo $archiveFullName | grep -oi '[a-z]\+$') -archiveVersion=$(echo $archiveFullName | sed 's/MDCx-py-//g' | sed 's/\.[^.]*$//') -archivePureName=$(echo $archiveUrl | grep -oi 'MDCx-py-[a-z0-9]\+') - if [[ -n "$verbose" ]]; then - echo "🔗 下载链接:$archiveUrl" - echo "ℹ️ 压缩包全名:$archiveFullName" - echo "ℹ️ 压缩包文件名:$archivePureName" - echo "ℹ️ 压缩包后缀名:$archiveExt" + echo "ℹ️ TAG名称: $tagName" + echo "🔗 下载链接: $archiveUrl" fi -echo "ℹ️ 已发布版本:$archiveVersion" +echo "ℹ️ 已发布版本: $archiveVersion" # exit @@ -171,7 +184,7 @@ if [[ -n "$shouldUpdate" ]]; then exit 0 fi - archivePath="$archivePureName.rar" + archivePath="$archiveVersion.tar.gz" if [[ -n "$verbose" ]]; then curl -o $archivePath $archiveUrl -L @@ -182,38 +195,32 @@ if [[ -n "$shouldUpdate" ]]; then echo "✅ 下载成功" echo "⏳ 开始解压..." - UNRAR_PATH=$(which unrar) - if [[ -z "$UNRAR_PATH" ]]; then - echo "❌ 没有unrar命令!" - else - # 解压 - unrar x -o+ $archivePath - cp -rfp $archivePureName/* $appPath - # 删除压缩包 - rm -f $archivePath - # 删除解压出来的目录 - rm -rf $archivePureName - echo "✅ 源码已覆盖到 $appPath" - - if [ -f ".env.versions" ]; then - echo "✅ 更新 .env.versions MDCX_APP_VERSION=$archiveVersion" - sed -i -e "s/MDCX_APP_VERSION=[0-9.]\+/MDCX_APP_VERSION=$archiveVersion/" .env.versions - fi + # 解压新的源码到app目录 + tar -zxvf $archivePath -C $appPath --strip-components 1 + # 删除压缩包 + rm -f $archivePath + echo "✅ 源码已覆盖到 $appPath" + + if [ -f ".env.versions" ]; then + echo "✅ 更新 .env.versions MDCX_APP_VERSION=$archiveVersion" + sed -i -e "s/MDCX_APP_VERSION=[0-9.]\+/MDCX_APP_VERSION=$archiveVersion/" .env.versions + fi + if [ -f ".env" ]; then echo "✅ 更新 .env APP_VERSION=$archiveVersion" sed -i -e "s/APP_VERSION=[0-9.]\+/APP_VERSION=$archiveVersion/" .env + fi + + echo "ℹ️ 删除标记文件 $appPath/$FILE_INITIALIZED" + rm -f "$appPath/$FILE_INITIALIZED" - echo "ℹ️ 删除标记文件 $appPath/$FILE_INITIALIZED" - rm -f "$appPath/$FILE_INITIALIZED" - - if [[ -n "MDCX_SRC_CONTAINER_NAME" ]]; then - if [[ "$restart" == "1" || "$restart" == "true" ]]; then - echo "⏳ 重启容器..." - docker restart $MDCX_SRC_CONTAINER_NAME - else - echo "ℹ️ 如果已经部署过容器,执行以下命令重启容器" - echo "docker restart $MDCX_SRC_CONTAINER_NAME" - fi + if [[ -n "MDCX_SRC_CONTAINER_NAME" ]]; then + if [[ "$restart" == "1" || "$restart" == "true" ]]; then + echo "⏳ 重启容器..." + docker restart $MDCX_SRC_CONTAINER_NAME + else + echo "ℹ️ 如果已经部署过容器,执行以下命令重启容器" + echo "docker restart $MDCX_SRC_CONTAINER_NAME" fi fi else