From a3c5f67e458c166c0ba5489a224c55094cebbcf5 Mon Sep 17 00:00:00 2001 From: Fushinn Date: Fri, 19 Jan 2024 16:21:56 +0800 Subject: [PATCH] =?UTF-8?q?0.9.8.14=20#####=201.=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=84=9A=E6=9C=AC,=E4=BF=AE=E5=A4=8D=E8=AF=B8=E5=A4=9A?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=202.=20=E4=BF=AE=E5=A4=8D=E8=BD=AF=E4=BB=B6?= =?UTF-8?q?=E6=BA=90=E8=B6=85=E6=97=B6=E5=90=8E=E7=A8=8B=E5=BA=8F=E5=A0=B5?= =?UTF-8?q?=E5=A1=9E=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ##### --- .shell/get-taichi.sh | 61 ++++++++++++++++++++++++++++++++++---------- core/index/views.py | 15 ++++++----- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/.shell/get-taichi.sh b/.shell/get-taichi.sh index 858cffd..e72a720 100644 --- a/.shell/get-taichi.sh +++ b/.shell/get-taichi.sh @@ -818,7 +818,7 @@ EOF echo "Python源码编译" make install echo "安装软件依赖, 更换国内源" - cd /usr/taichi + cd /usr/taichi/TaiChi_OS-master /usr/taichi/python/bin/pip3 install -i https://mirrors.aliyun.com/pypi/simple/ pip -U /usr/taichi/python/bin/pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/ /usr/taichi/python/bin/pip3 install -r requirements.txt @@ -837,7 +837,7 @@ EOF [Service] WorkingDirectory=/usr/taichi - ExecStart=/usr/taichi/python/bin/python3 /usr/taichi/run.py --port=${port} + ExecStart=/usr/taichi/python/bin/python3 /usr/taichi/TaiChi_OS-master/run.py --port=${port} Restart=on-abnormal RestartSec=5s KillMode=mixed @@ -962,11 +962,15 @@ update_taichi() { python_update_taichi() { systemctl stop taichi - mv /usr/taichi/python /tmp/taichi/python + mv /usr/taichi/python /tmp/ + mv /usr/taichi/TaiChi_OS-master/config.json /tmp/ + mv /usr/taichi/TaiChi_OS-master/data.db /tmp/ rm -rf /usr/taichi/* - mv /tmp/taichi/python /usr/taichi/python wget -P /usr/taichi https://codeload.github.com/Xingsandesu/TaiChi_OS/zip/refs/heads/master unzip /usr/taichi/master -d /usr/taichi + mv /tmp/python /usr/taichi/python + mv /tmp/config.json /usr/taichi/TaiChi_OS-master/config.json + mv /tmp/data.db /usr/taichi/TaiChi_OS-master/data.db systemctl start taichi systemctl daemon-reload } @@ -1014,31 +1018,57 @@ case $operation in if systemctl --all --type=service | grep -q 'taichi'; then systemctl restart taichi - else + else docker restart taichi - fi + fi echo "重启完毕" ;; 5) # 恢复默认设置 echo "开始恢复默认设置..." - rm /usr/taichi/config.json + rm -rf /usr/taichi/TaiChi_OS-master/config.json + if systemctl --all --type=service | grep -q 'taichi'; then + systemctl restart taichi + + else + docker restart taichi + fi echo "恢复默认设置完毕" ;; 6) # 重置账号密码 echo "开始重置账号密码..." - rm /usr/taichi/data.db + rm /usr/taichi/TaiChi_OS-master/data.db + if systemctl --all --type=service | grep -q 'taichi'; then + systemctl restart taichi + + else + docker restart taichi + fi echo "重置账号密码完毕" ;; 7) # 更换端口 echo "请输入新的端口:" read new_port - sed -i "s/--port=[0-9]*/--port=${new_port}/g" /etc/systemd/system/taichi.service - systemctl daemon-reload - systemctl restart taichi - echo "端口更新完毕" + if docker ps -a --format '{{.Names}}' | grep -q '^taichios$'; then + docker stop taichios + docker rm taichios + docker run -itd \ + -p ${new_port}:80 \ + -v /var/run/docker.sock:/var/run/docker.sock \ + --mount type=bind,source=/usr/taichi/config.json,target=/taichi_os/config.json \ + --mount type=bind,source=/usr/taichi/data.db,target=/taichi_os/data.db \ + --name taichios \ + --restart=always \ + fushin/taichios + echo "Docker 端口更新完毕" + else + sed -i "s/--port=[0-9]*/--port=${new_port}/g" /etc/systemd/system/taichi.service + systemctl daemon-reload + systemctl restart taichi + echo "端口更新完毕" + fi ;; 8) # 更换软件源 @@ -1047,7 +1077,12 @@ case $operation in if [[ $new_source != http://* ]]; then new_source="http://${new_source}" fi - sed -i "s|\"source_url\": \".*\"|\"source_url\": \"${new_source}\"|g" /usr/taichi/config.json + sed -i 's|\("source_url": "\)[^"]*"|\1'${new_source}'"|' /usr/taichi/TaiChi_OS-master/config.json + if systemctl --all --type=service | grep -q 'taichi'; then + systemctl restart taichi + else + docker restart taichi + fi ;; 9) echo "Docker安装开始" diff --git a/core/index/views.py b/core/index/views.py index c56c3c4..19b5952 100644 --- a/core/index/views.py +++ b/core/index/views.py @@ -29,13 +29,16 @@ def none_back(): @bp.route('/install') # /install @login_required def install(): - response = requests.get(SOURCE_URL + '/app.json') - logging.info(response.text) try: - apps = response.json() - except JSONDecodeError: - logging.error("解析JSON时出错") - return "解析JSON时出错, 可能是网络原因或者软件源没有app.json" + response = requests.get(SOURCE_URL + '/app.json', timeout=1) + logging.info(response.text) + try: + apps = response.json() + except JSONDecodeError: + logging.error("解析JSON时出错") + return "解析JSON时出错, 可能是网络原因或者软件源没有app.json" + except requests.exceptions.Timeout: + return "请求超时,请检查网络或者软件源" return render_template('install.html', apps=apps)