diff --git a/Dockerfile b/Dockerfile index 0b04c5b..21ff895 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,8 @@ ARG WORK_DIR=/pagermaid/workdir ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ SHELL=/bin/bash \ LANG=zh_CN.UTF-8 \ - PS1="\u@\h:\w \$ " + PS1="\u@\h:\w \$ " \ + RUN_AS_ROOT=true SHELL ["/bin/bash", "-c"] WORKDIR $WORK_DIR RUN source ~/.bashrc \ @@ -46,6 +47,7 @@ RUN source ~/.bashrc \ && apt-get install --no-install-recommends -y \ ## 这是跨平台交叉编译要用到的包,如果自行构建,有可能不需要 build-essential \ + apt-utils \ python3-dev \ libxslt1-dev \ libxml2-dev \ @@ -89,6 +91,7 @@ RUN source ~/.bashrc \ ## 卸载编译依赖,清理安装缓存 && sudo apt-get purge --auto-remove -y \ build-essential \ + apt-utils \ python3-dev \ libxslt1-dev \ libxml2-dev \ diff --git a/README.md b/README.md index 1ff0f31..e69381c 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Pagermaid 是一个用在 Telegram 的实用工具。 [一键脚本](https://t.me/PagerMaid_Modify/58) -[Docker 脚本](https://t.me/PagerMaid_Modify/60) +[Docker安装](utils/docker.md) # 对存在使用本项目用户群组的提醒 diff --git a/docker-compose.gen.yml b/docker-compose.gen.yml index a7a07b9..89cdd80 100644 --- a/docker-compose.gen.yml +++ b/docker-compose.gen.yml @@ -4,11 +4,12 @@ services: image: mrwangzhe/pagermaid_modify restart: always container_name: pagermaid - hostname: "pagermaid" - #ports: + hostname: pagermaid + #ports: # 是否开启网页控制面板 #- "3333:3333" volumes: - ./:/pagermaid/workdir environment: - - PUID=917 - - PGID=917 + - RUN_AS_ROOT=true # 是否以root权限运行pagermaid,true为是 + - PUID=917 # 当 RUN_AS_ROOT=false 才生效,即以普通用户权限运行pagermaid + - PGID=917 # 当 RUN_AS_ROOT=false 才生效,即以普通用户权限运行pagermaid diff --git a/s6/etc/cont-init.d/10-adduser b/s6/etc/cont-init.d/10-adduser index b618425..d2bba68 100755 --- a/s6/etc/cont-init.d/10-adduser +++ b/s6/etc/cont-init.d/10-adduser @@ -1,7 +1,8 @@ #!/usr/bin/with-contenv bash -PUID=${PUID:-917} -PGID=${PGID:-917} - -groupmod -o -g "$PGID" pagermaid -usermod -o -u "$PUID" pagermaid +if [[ $RUN_AS_ROOT != true ]]; then + PUID=${PUID:-917} + PGID=${PGID:-917} + groupmod -o -g "$PGID" pagermaid + usermod -o -u "$PUID" pagermaid +fi diff --git a/s6/etc/cont-init.d/30-config b/s6/etc/cont-init.d/30-config index 70c95a9..b5da116 100755 --- a/s6/etc/cont-init.d/30-config +++ b/s6/etc/cont-init.d/30-config @@ -1,3 +1,5 @@ #!/usr/bin/with-contenv bash -chown -R pagermaid:pagermaid /pagermaid \ No newline at end of file +if [[ $RUN_AS_ROOT != true ]]; then + chown -R pagermaid:pagermaid /pagermaid +fi \ No newline at end of file diff --git a/s6/etc/cont-init.d/40-redis b/s6/etc/cont-init.d/40-redis index b1a6081..7ff0c62 100755 --- a/s6/etc/cont-init.d/40-redis +++ b/s6/etc/cont-init.d/40-redis @@ -1,3 +1,7 @@ #!/usr/bin/with-contenv bash -exec s6-setuidgid pagermaid redis-server --daemonize yes \ No newline at end of file +if [[ $RUN_AS_ROOT != true ]]; then + exec s6-setuidgid pagermaid redis-server --daemonize yes +else + redis-server --daemonize yes +fi \ No newline at end of file diff --git a/s6/etc/services.d/pagermaid/run b/s6/etc/services.d/pagermaid/run index 69cb117..854663f 100755 --- a/s6/etc/services.d/pagermaid/run +++ b/s6/etc/services.d/pagermaid/run @@ -1,5 +1,9 @@ #!/usr/bin/with-contenv bash cd /pagermaid/workdir -exec s6-setuidgid pagermaid python -m pagermaid +if [[ $RUN_AS_ROOT != true ]]; then + exec s6-setuidgid pagermaid python -m pagermaid +else + python -m pagermaid +fi diff --git a/utils/docker.md b/utils/docker.md new file mode 100644 index 0000000..1a5f054 --- /dev/null +++ b/utils/docker.md @@ -0,0 +1,28 @@ +## 一、一键脚本 + +``` +wget https://raw.githubusercontent.com/Xtao-Labs/PagerMaid-Modify/master/utils/docker.sh +bash docker.sh +``` + +*注:一键脚本安装的Docker将以root权限运行,在使用pagermaid时最方便。* + +## docker-compose 安装 + +1. 准备脚本 + +``` +git clone https://github.com/Xtao-Labs/PagerMaid-Modify pagermaid +cd pagermaid +cp config.gen.yml config.yml +cp docker-compose.gen.yml docker-compose.yml +``` + +2. 编辑刚刚复制的`docker-compose.yml`为你自己的信息,如不想解决权限问题,建议`RUN_AS_ROOT=true`。 + +3. 如果会配置,就自己编辑刚刚复制的`config.yml`。如果不会就直接下一步。 + +4. 启动容器`docker-compose up -d`。 + +5. 如第3步未配置`config.yml`,则运行`docker exec -it <容器名> bash utils/docker-config.sh`进行配置。 + diff --git a/utils/docker.sh b/utils/docker.sh index 982e1b5..30b4f69 100644 --- a/utils/docker.sh +++ b/utils/docker.sh @@ -7,7 +7,7 @@ then exit 1 fi -welcome() { +welcome () { echo echo "安装即将开始" echo "如果您想取消安装," @@ -29,7 +29,7 @@ docker_check () { fi } -access_check() { +access_check () { echo "测试 Docker 环境 . . ." if [ -w /var/run/docker.sock ] then @@ -40,101 +40,159 @@ access_check() { fi } -build_docker() { +build_docker () { printf "请输入 PagerMaid 容器的名称:" read -r container_name <&1 - printf "请输入你想以哪个用户运行pagermaid,该用户的PUID值(如不懂请直接回车):" - read -r puid <&1 - PUID=${puid-:917} - printf "请输入你想以哪个用户运行pagermaid,该用户的PGID值(如不懂请直接回车):" - read -r pgid <&1 - PGID=${pgid-:917} echo "正在拉取 Docker 镜像 . . ." docker rm -f "$container_name" > /dev/null 2>&1 docker pull mrwangzhe/pagermaid_modify } -start_docker() { +start_docker () { echo "正在启动 Docker 容器 . . ." - docker run -dit -e PUID=$PUID -e PGID=$PGID --restart=always --name="$container_name" --hostname="$container_name" mrwangzhe/pagermaid_modify <&1 + docker run -dit --restart=always --name="$container_name" --hostname="$container_name" mrwangzhe/pagermaid_modify <&1 echo echo "开始配置参数 . . ." echo "在登录后,请按 Ctrl + C 使容器在后台模式下重新启动。" sleep 3 - docker exec -it -u pagermaid $container_name bash utils/docker-config.sh + docker exec -it $container_name bash utils/docker-config.sh echo echo "Docker 创建完毕。" echo - shon_online } -start_installation() { +data_persistence () { + echo "数据持久化可以在升级或重新部署容器时保留配置文件和插件。" + printf "请确认是否进行数据持久化操作 [Y/n] :" + read -r persistence <&1 + case $persistence in + [yY][eE][sS] | [yY]) + printf "请输入将数据保留在宿主机哪个路径(绝对路径),同时请确保该路径下没有名为 workdir 的文件夹 :" + read -r data_path <&1 + if [ -d $data_path ]; then + if [[ -z $container_name ]]; then + printf "请输入 PagerMaid 容器的名称:" + read -r container_name <&1 + fi + if docker inspect $container_name &>/dev/null; then + docker cp $container_name:/pagermaid/workdir $data_path + docker stop $container_name &>/dev/null + docker rm $container_name &>/dev/null + docker run -dit -e PUID=$PUID -e PGID=$PGID -v $data_path/workdir:/pagermaid/workdir --restart=always --name="$container_name" --hostname="$container_name" mrwangzhe/pagermaid_modify <&1 + echo + echo "数据持久化操作完成。" + echo + shon_online + else + echo "不存在名为 $container_name 的容器,退出。" + exit 1 + fi + else + echo "路径 $data_path 不存在,退出。" + exit 1 + fi + ;; + [nN][oO] | [nN]) + echo "结束。" + ;; + *) + echo "输入错误 . . ." + exit 1 + ;; + esac +} + +start_installation () { welcome docker_check access_check build_docker start_docker + data_persistence } -cleanup(){ +cleanup () { printf "请输入 PagerMaid 容器的名称:" read -r container_name <&1 - echo "正在删除 Docker 镜像 . . ." - docker rm -f "$container_name" > /dev/null 2>&1 - echo "" - shon_online + echo "开始删除 Docker 镜像 . . ." + if docker inspect $container_name &>/dev/null; then + docker rm -f "$container_name" &>/dev/null + echo + shon_online + else + echo "不存在名为 $container_name 的容器,退出。" + exit 1 + fi } -stop_pager(){ +stop_pager () { printf "请输入 PagerMaid 容器的名称:" read -r container_name <&1 echo "正在关闭 Docker 镜像 . . ." - docker stop "$container_name" > /dev/null 2>&1 - echo "" - shon_online + if docker inspect $container_name &>/dev/null; then + docker stop "$container_name" &>/dev/null + echo + shon_online + else + echo "不存在名为 $container_name 的容器,退出。" + exit 1 + fi } -start_pager(){ +start_pager () { printf "请输入 PagerMaid 容器的名称:" read -r container_name <&1 echo "正在启动 Docker 容器 . . ." - docker start $container_name > /dev/null 2>&1 - echo "" - echo "Docker 启动完毕。" - echo "" - shon_online + if docker inspect $container_name &>/dev/null; then + docker start $container_name &>/dev/null + echo + echo "Docker 启动完毕。" + echo + shon_online + else + echo "不存在名为 $container_name 的容器,退出。" + exit 1 + fi } -restart_pager(){ +restart_pager () { printf "请输入 PagerMaid 容器的名称:" read -r container_name <&1 echo "正在重新启动 Docker 容器 . . ." - docker restart $container_name > /dev/null 2>&1 - echo "" - echo "Docker 重新启动完毕。" - echo "" - shon_online + if docker inspect $container_name &>/dev/null; then + docker restart $container_name &>/dev/null + echo + echo "Docker 重新启动完毕。" + echo + shon_online + else + echo "不存在名为 $container_name 的容器,退出。" + exit 1 + fi } -reinstall_pager(){ +reinstall_pager () { + cleanup build_docker start_docker + data_persistence } -shon_online(){ +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) 重新安装 PagerMaid" - echo " 7) 退出脚本" + echo " 3) Docker 关闭 PagerMaid" + echo " 4) Docker 启动 PagerMaid" + echo " 5) Docker 重启 PagerMaid" + echo " 6) Docker 重装 PagerMaid" + echo " 7) 将 PagerMaid 数据持久化" + echo " 8) 退出脚本" echo - echo " Version:0.3.0" + echo " Version:0.3.1" echo echo -n "请输入编号: " read N @@ -158,6 +216,9 @@ shon_online(){ reinstall_pager ;; 7) + data_persistence + ;; + 8) exit 0 ;; *)