diff --git a/Dockerfile.persistant b/Dockerfile.persistant index 52ff81b..067af49 100644 --- a/Dockerfile.persistant +++ b/Dockerfile.persistant @@ -38,7 +38,5 @@ RUN git clone -b master https://github.com/xtaodada/PagerMaid-Modify.git /pagerm WORKDIR /pagermaid/workdir RUN python3 -m virtualenv venv RUN source venv/bin/activate; pip3 install -r requirements.txt -USER root -RUN cd /pagermaid/workdir CMD ["sh","utils/docker-run.sh"] diff --git a/utils/docker-run.sh b/utils/docker-run.sh index dffb660..a1f3b23 100644 --- a/utils/docker-run.sh +++ b/utils/docker-run.sh @@ -70,44 +70,21 @@ configure() { login() { echo "" - echo "下面进行程序试运行。" - echo "请在账户授权完毕后按 Ctrl + C 退出" + echo "下面进行程序运行。" + echo "请在账户授权完毕后,按 Ctrl + D 使 Docker 在后台模式下运行。" echo "" sleep 2 - /pagermaid/workdir/venv/bin/python -m pagermaid - echo "" - echo "程序试运行完毕。" - echo "" + while true + do + /pagermaid/workdir/venv/bin/python -m pagermaid + done } -systemctl_reload(){ - echo "正在写入系统进程守护 . . ." - echo "[Unit] - Description=PagerMaid-Modify telegram utility daemon - After=network.target - [Install] - WantedBy=multi-user.target - [Service] - User=pagermaid - Type=simple - WorkingDirectory=/pagermaid/workdir - ExecStart=/pagermaid/workdir/venv/bin/python -m pagermaid - Restart=always - ">/etc/systemd/system/pagermaid.service - chmod 755 pagermaid.service >> /dev/null 2>&1 - systemctl daemon-reload >> /dev/null 2>&1 - systemctl enable pagermaid >> /dev/null 2>&1 - echo "" - echo "请在脚本退出后输入 exit 退出 Docker" - echo "" - exit -} start_installation() { welcome configure login - systemctl_reload } start_installation diff --git a/utils/docker.sh b/utils/docker.sh index 5e87d8e..31cbd2f 100644 --- a/utils/docker.sh +++ b/utils/docker.sh @@ -8,7 +8,6 @@ fi welcome() { echo "" - echo "欢迎使用 PagerMaid-Modify 一键安装程序。" echo "安装即将开始" echo "如果您想取消安装," echo "请在 5 秒钟内按 Ctrl+C 终止此脚本。" @@ -66,23 +65,83 @@ start_docker() { echo "在登录后,请按 Ctrl + C 使容器在后台模式下重新启动。" sleep 3 docker run -it --restart=always --name="$container_name" --hostname="$container_name" pagermaid_"$container_name" <&1 - docker restart $container_name > /dev/null 2>&1 + echo "" + echo "Docker 创建完毕。" + echo "" + shon_online } -cleanup() { - echo "正在清理临时文件 . . ." - rm -rf /tmp/pagermaid -} start_installation() { - check_sys welcome docker_check git_check access_check build_docker start_docker - cleanup } -start_installation +cleanup(){ + printf "请输入 PagerMaid 容器的名称:" + read -r container_name <&1 + echo "正在删除 Docker 镜像 . . ." + docker rm -f "$container_name" > /dev/null 2>&1 + echo "" + shon_online +} + +stop_pager(){ + printf "请输入 PagerMaid 容器的名称:" + read -r container_name <&1 + echo "正在关闭 Docker 镜像 . . ." + docker stop -f "$container_name" > /dev/null 2>&1 + echo "" + shon_online +} + +start_pager(){ + printf "请输入 PagerMaid 容器的名称:" + read -r container_name <&1 + echo "正在启动 Docker 容器 . . ." + echo "在登录后,请按 Ctrl + D 使 Docker 在后台模式下运行。" + sleep 3 + docker run -it --restart=always --name="$container_name" --hostname="$container_name" pagermaid_"$container_name" <&1 + echo "" + echo "Docker 启动完毕。" + echo "" + shon_online +} + +reinstall_pager(){ + build_docker + start_docker +} + +shon_online(){ +echo "" +echo "欢迎使用 PagerMaid-Modify Docker 一键安装脚本。" +echo "" +echo "请选择您需要进行的操作:" +echo " 1) Docker 安装 PagerMaid" +echo " 2) Docker 卸载 PagerMaid" +echo " 3) 关闭 PagerMaid" +echo " 4) 启动 PagerMaid" +echo " 5) 重新安装 PagerMaid" +echo " 6) 退出脚本" +echo "" +echo " Version:0.1.0" +echo "" +echo -n "请输入编号: " +read N +case $N in + 1) start_installation ;; + 2) cleanup ;; + 3) stop_pager ;; + 4) start_pager ;; + 5) reinstall_pager ;; + 6) exit ;; + *) echo "Wrong input!" ;; +esac +} + +shon_online