From 69dc6d83e0ef7ad5e80dd71c5513924ec44ca127 Mon Sep 17 00:00:00 2001 From: nevinen <83165391+nevinen@users.noreply.github.com> Date: Sun, 2 May 2021 00:48:32 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Thorough=20Docker=20iteration=20?= =?UTF-8?q?(#69)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 👷 彻底的 Docker 迭代 (#69) --- .github/workflows/main.yml | 78 ++- .gitignore | 6 +- Dockerfile | 133 ++++- Dockerfile.persistant | 58 -- docker-compose.gen.yml | 11 +- install.sh | 994 ++++++++++++++++---------------- s6/etc/cont-init.d/10-adduser | 7 + s6/etc/cont-init.d/30-config | 3 + s6/etc/services.d/pagermaid/run | 5 + s6/etc/services.d/redis/run | 3 + utils/docker-config.sh | 95 +++ utils/docker-run.sh | 98 ---- utils/docker.sh | 259 ++++----- utils/entrypoint.sh | 4 - 14 files changed, 939 insertions(+), 815 deletions(-) delete mode 100644 Dockerfile.persistant create mode 100755 s6/etc/cont-init.d/10-adduser create mode 100755 s6/etc/cont-init.d/30-config create mode 100755 s6/etc/services.d/pagermaid/run create mode 100755 s6/etc/services.d/redis/run create mode 100644 utils/docker-config.sh delete mode 100644 utils/docker-run.sh delete mode 100644 utils/entrypoint.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1ab7e54..80e9ceb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: "Docker" +name: "构建PagerMaid" # Controls when the action will run. on: @@ -9,17 +9,69 @@ on: jobs: build: runs-on: ubuntu-latest - name: Build PagerMaid Image + name: 构建PagerMaid + env: + DOCKER_BUILDKIT: 1 + DOCKER_CLI_EXPERIMENTAL: enabled + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKERHUB_REPOSITORY: ${{ secrets.DOCKER_USERNAME }}/pagermaid_modify steps: - - name: Checkout master - uses: actions/checkout@master - - name: Build and publish image - uses: ilteoood/docker_buildx@master + - name: Checkout + uses: actions/checkout@v2 + + - name: Login to DockerHub + uses: docker/login-action@v1 with: - publish: true - imageName: mrwangzhe/pagermaid_modify - dockerFile: Dockerfile - platform: linux/amd64,linux/arm64,linux/arm/v7 - tag: latest - dockerUser: ${{ secrets.DOCKER_USERNAME }} - dockerPassword: ${{ secrets.DOCKER_PASSWORD }} + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Setup Docker Buildx + uses: crazy-max/ghaction-docker-buildx@v3 + + - name: Buildx cache + uses: actions/cache@v2 + id: buildx-cache + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx + + - name: Build + run: | + FULL_VERSION=$(curl https://api.github.com/repos/just-containers/s6-overlay/releases/latest | jq -r '.tag_name') + + declare -a IMAGES + + echo "Build amd64" + docker buildx build \ + --cache-from "type=local,src=/tmp/.buildx-cache" \ + --cache-to "type=local,dest=/tmp/.buildx-cache" \ + --output "type=image,push=true" \ + --platform linux/amd64 \ + --build-arg "S6_VERSION=${FULL_VERSION}" \ + --build-arg "S6_ARCH=amd64" \ + --tag "${DOCKERHUB_REPOSITORY}:latest-amd64" \ + -f pagermaid/Dockerfile \ + . + IMAGES+=( "${DOCKERHUB_REPOSITORY}:latest-amd64" ) + + echo "Build arm64-v8" + docker buildx build \ + --cache-from "type=local,src=/tmp/.buildx-cache" \ + --cache-to "type=local,dest=/tmp/.buildx-cache" \ + --output "type=image,push=true" \ + --platform linux/arm64/v8 \ + --build-arg "S6_VERSION=${FULL_VERSION}" \ + --build-arg "S6_ARCH=aarch64" \ + --tag "${DOCKERHUB_REPOSITORY}:latest-arm64-v8" \ + -f pagermaid/Dockerfile \ + . + IMAGES+=( "${DOCKERHUB_REPOSITORY}:latest-arm64-v8" ) + + echo "Create manifest lists" + docker manifest create "${DOCKERHUB_REPOSITORY}:latest" "${IMAGES[@]}" + + echo "Annotate manifest lists to add architecture variants that aren't picked up automatically" + docker manifest annotate "${DOCKERHUB_REPOSITORY}:latest" "${DOCKERHUB_REPOSITORY}:latest-arm64-v8" --variant "v8" + + echo "Push manifest lists & delete local copies" + docker manifest push --purge "${DOCKERHUB_REPOSITORY}:latest" diff --git a/.gitignore b/.gitignore index 39f334a..b06ddb5 100644 --- a/.gitignore +++ b/.gitignore @@ -120,8 +120,7 @@ pagermaid.session pagermaid.session-journal *.pagermaid docker-compose.yml -plugins/*.py -plugins/*.py.disabled +plugins/ data/* pagermaid.egg-info/ @@ -142,3 +141,6 @@ dmypy.json # Pyre type checker .pyre/ + +# docker +install.lock \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d21d738..b8dbda4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,125 @@ -FROM mrwangzhe/pagermaid_os:latest -USER pagermaid -RUN mkdir /pagermaid/workdir -RUN git clone -b master https://github.com/Xtao-Labs/PagerMaid-Modify.git /pagermaid/workdir -WORKDIR /pagermaid/workdir -RUN python -m pip install -r requirements.txt \ - && rm -rf /pagermaid/.cache -CMD ["sh","utils/docker-run.sh"] +FROM ubuntu:hirsute +ARG S6_VERSION=v2.2.0.3 +ARG S6_ARCH=amd64 +ARG DEBIAN_FRONTEND=noninteractive +ARG USER_NAME=pagermaid +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 \$ " +SHELL ["/bin/bash", "-c"] +WORKDIR $WORK_DIR +RUN source ~/.bashrc \ + ## 安装运行环境依赖,自编译建议修改为国内镜像源 +# && sed -i 's/archive.ubuntu.com/mirrors.bfsu.edu.cn/g' /etc/apt/sources.list \ +# && sed -i 's/security.ubuntu.com/mirrors.bfsu.edu.cn/g' /etc/apt/sources.list \ +# && sed -i 's/ports.ubuntu.com/mirrors.bfsu.edu.cn/g' /etc/apt/sources.list \ + && apt-get update \ + && apt-get upgrade -y \ + && apt-get install --no-install-recommends -y \ + python3 \ + python3-pip \ + tesseract-ocr \ + tesseract-ocr-eng \ + tesseract-ocr-chi-sim \ + language-pack-zh-hans \ + sudo \ + git \ + openssl \ + redis-server \ + curl \ + wget \ + neofetch \ + imagemagick \ + ffmpeg \ + fortune-mod \ + figlet \ + libmagic1 \ + libzbar0 \ + ## 安装s6 + && curl -L -o /tmp/s6-overlay-installer https://github.com/just-containers/s6-overlay/releases/download/${S6_VERSION}/s6-overlay-${S6_ARCH}-installer \ + && chmod +x /tmp/s6-overlay-installer \ + && /tmp/s6-overlay-installer / \ + ## 安装编译依赖 + && apt-get update \ + && apt-get install --no-install-recommends -y \ + ## 这是跨平台交叉编译要用到的包,如果自行构建,有可能不需要 + build-essential \ + python3-dev \ + libxslt1-dev \ + libxml2-dev \ + libssl-dev \ + libffi-dev \ + zlib1g-dev \ + tcl8.6-dev \ + tk8.6-dev \ + libimagequant-dev \ + libraqm-dev \ + libjpeg-dev \ + libtiff5-dev \ + libopenjp2-7-dev \ + libfreetype6-dev \ + liblcms2-dev \ + libwebp-dev \ + python3-tk \ + libharfbuzz-dev \ + libfribidi-dev \ + libxcb1-dev \ + pkg-config \ + ## 设置时区 + && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && echo "Asia/Shanghai" > /etc/timezone \ + ## python软链接 + && ln -sf /usr/bin/python3 /usr/bin/python \ + ## 升级pip +# && pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple \ + && python -m pip install --upgrade pip \ + ## 添加用户 + && useradd $USER_NAME -u 917 -U -r -m -d /$USER_NAME -s /bin/bash \ + && usermod -aG sudo,users $USER_NAME \ + && echo "$USER_NAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USER_NAME \ + ## 克隆仓库 + && git clone -b master https://github.com/nevinen/PagerMaid-Modify.git $WORK_DIR \ + && git config --global pull.ff only \ + ## 复制s6启动脚本 + && cp -r s6/* / \ + ## pip install + && pip install -r requirements.txt \ + ## 卸载编译依赖,清理安装缓存 + && sudo apt-get purge --auto-remove -y \ + build-essential \ + python3-dev \ + libxslt1-dev \ + libxml2-dev \ + libssl-dev \ + libffi-dev \ + zlib1g-dev \ + tcl8.6-dev \ + tk8.6-dev \ + libimagequant-dev \ + libraqm-dev \ + libjpeg-dev \ + libtiff5-dev \ + libopenjp2-7-dev \ + libfreetype6-dev \ + liblcms2-dev \ + libwebp-dev \ + python3-tk \ + libharfbuzz-dev \ + libfribidi-dev \ + libxcb1-dev \ + pkg-config \ + && apt-get clean -y \ + && rm -rf \ + ## 删除apt和pip的安装缓存 + /tmp/* \ + /var/lib/apt/lists/* \ + /var/tmp/* \ + ~/.cache \ + ## 最后改成国内源 + && sed -i 's/archive.ubuntu.com/mirrors.bfsu.edu.cn/g' /etc/apt/sources.list \ + && sed -i 's/security.ubuntu.com/mirrors.bfsu.edu.cn/g' /etc/apt/sources.list \ + && sed -i 's/ports.ubuntu.com/mirrors.bfsu.edu.cn/g' /etc/apt/sources.list \ + && pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple +ENTRYPOINT ["/init"] diff --git a/Dockerfile.persistant b/Dockerfile.persistant deleted file mode 100644 index b2aaf7f..0000000 --- a/Dockerfile.persistant +++ /dev/null @@ -1,58 +0,0 @@ -FROM ubuntu:hirsute -ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ - LANG=zh_CN.UTF-8 \ - SHELL=/bin/bash \ - PS1="\u@\h:\w \$ " \ - PAGERMAID_DIR=/pagermaid \ - DEBIAN_FRONTEND=noninteractive -SHELL ["/bin/bash", "-c"] -RUN source ~/.bashrc \ - && apt update \ - && apt upgrade -y \ - && apt install --no-install-recommends -y \ - software-properties-common \ - build-essential \ - python3 \ - python3-dev \ - python3-pip \ - python3-magic \ - python3-dateparser \ - tesseract-ocr \ - tesseract-ocr-eng \ - tesseract-ocr-chi-sim \ - git \ - openssl \ - redis-server \ - curl \ - wget \ - neofetch \ - imagemagick \ - ffmpeg \ - fortune-mod \ - figlet \ - libzbar-dev \ - libxslt1-dev \ - libxml2-dev \ - libfreetype-dev \ - libffi-dev \ - libopenblas-dev \ - liblapack-dev \ - libpqxx-dev \ - && apt clean -y \ - && apt autoclean -y -RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ - && echo "Asia/Shanghai" > /etc/timezone -RUN ln -sf /usr/bin/python3 /usr/bin/python \ - && python -m pip install --upgrade pip \ - && pip install wheel \ - && pip install eyed3 pycryptodome -RUN sed -e 's;^# \(%wheel.*NOPASSWD.*\);\1;g' -i /etc/sudoers -RUN useradd pagermaid -r -m -d /pagermaid -RUN usermod -aG wheel,users pagermaid -USER pagermaid -RUN mkdir /pagermaid -RUN git clone -b master https://github.com/Xtao-Labs/PagerMaid-Modify.git /pagermaid -WORKDIR /pagermaid -RUN pip -m pip install -r requirements.txt -RUN sudo rm -rf /root/.cache -CMD ["sh","utils/docker-run.sh"] diff --git a/docker-compose.gen.yml b/docker-compose.gen.yml index a8ce3e5..a7a07b9 100644 --- a/docker-compose.gen.yml +++ b/docker-compose.gen.yml @@ -1,11 +1,14 @@ -version: "1.3" +version: "2.0" services: pagermaid: image: mrwangzhe/pagermaid_modify restart: always - container_name: "pagermaid" + container_name: pagermaid hostname: "pagermaid" #ports: - #- "3333:3333" + #- "3333:3333" volumes: - - ./:/pagermaid/workdir + - ./:/pagermaid/workdir + environment: + - PUID=917 + - PGID=917 diff --git a/install.sh b/install.sh index 6d2d16f..a6a5738 100644 --- a/install.sh +++ b/install.sh @@ -1,405 +1,405 @@ #!/bin/bash if [[ $EUID -ne 0 ]]; then - clear - echo "错误:本脚本需要 root 权限执行。" 1>&2 - exit 1 + clear + echo "错误:本脚本需要 root 权限执行。" 1>&2 + exit 1 fi check_sys() { - if [[ -f /etc/redhat-release ]]; then - release="centos" - elif cat /etc/issue | grep -q -E -i "debian"; then - release="debian" - elif cat /etc/issue | grep -q -E -i "ubuntu"; then - release="ubuntu" - elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then - release="centos" - elif cat /proc/version | grep -q -E -i "debian"; then - release="debian" - elif cat /proc/version | grep -q -E -i "ubuntu"; then - release="ubuntu" - elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then - release="centos" - fi + if [[ -f /etc/redhat-release ]]; then + release="centos" + elif cat /etc/issue | grep -q -E -i "debian"; then + release="debian" + elif cat /etc/issue | grep -q -E -i "ubuntu"; then + release="ubuntu" + elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then + release="centos" + elif cat /proc/version | grep -q -E -i "debian"; then + release="debian" + elif cat /proc/version | grep -q -E -i "ubuntu"; then + release="ubuntu" + elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then + release="centos" + fi } welcome() { - echo "" - echo "欢迎使用 PagerMaid-Modify 一键安装程序。" - echo "安装即将开始" - echo "如果您想取消安装," - echo "请在 5 秒钟内按 Ctrl+C 终止此脚本。" - echo "" - sleep 5 + echo "" + echo "欢迎使用 PagerMaid-Modify 一键安装程序。" + echo "安装即将开始" + echo "如果您想取消安装," + echo "请在 5 秒钟内按 Ctrl+C 终止此脚本。" + echo "" + sleep 5 } yum_update() { - echo "正在优化 yum . . ." - yum install yum-utils epel-release -y >>/dev/null 2>&1 + echo "正在优化 yum . . ." + yum install yum-utils epel-release -y >>/dev/null 2>&1 } yum_git_check() { - echo "正在检查 Git 安装情况 . . ." - if command -v git >>/dev/null 2>&1; then - echo "Git 似乎存在,安装过程继续 . . ." - else - echo "Git 未安装在此系统上,正在进行安装" - yum install git -y >>/dev/null 2>&1 - fi + echo "正在检查 Git 安装情况 . . ." + if command -v git >>/dev/null 2>&1; then + echo "Git 似乎存在,安装过程继续 . . ." + else + echo "Git 未安装在此系统上,正在进行安装" + yum install git -y >>/dev/null 2>&1 + fi } yum_python_check() { - echo "正在检查 python 安装情况 . . ." - if command -v python3 >>/dev/null 2>&1; then - U_V1=$(python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1}') - U_V2=$(python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $2}') - if [ $U_V1 -gt 3 ]; then - echo 'Python 3.6+ 存在 . . .' - elif [ $U_V2 -ge 6 ]; then - echo 'Python 3.6+ 存在 . . .' - PYV=$U_V1.$U_V2 - PYV=$(which python$PYV) - else - if command -v python3.6 >>/dev/null 2>&1; then - echo 'Python 3.6+ 存在 . . .' - PYV=$(which python3.6) - else - echo "Python3.6 未安装在此系统上,正在进行安装" - yum install python3 -y >>/dev/null 2>&1 - update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 >>/dev/null 2>&1 - PYV=$(which python3.6) - fi - fi - else - echo "Python3.6 未安装在此系统上,正在进行安装" - yum install python3 -y >>/dev/null 2>&1 - update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 >>/dev/null 2>&1 - fi - if command -v pip3 >>/dev/null 2>&1; then - echo 'pip 存在 . . .' - else - echo "pip3 未安装在此系统上,正在进行安装" - yum install -y python3-pip >>/dev/null 2>&1 - fi + echo "正在检查 python 安装情况 . . ." + if command -v python3 >>/dev/null 2>&1; then + U_V1=$(python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1}') + U_V2=$(python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $2}') + if [ $U_V1 -gt 3 ]; then + echo 'Python 3.6+ 存在 . . .' + elif [ $U_V2 -ge 6 ]; then + echo 'Python 3.6+ 存在 . . .' + PYV=$U_V1.$U_V2 + PYV=$(which python$PYV) + else + if command -v python3.6 >>/dev/null 2>&1; then + echo 'Python 3.6+ 存在 . . .' + PYV=$(which python3.6) + else + echo "Python3.6 未安装在此系统上,正在进行安装" + yum install python3 -y >>/dev/null 2>&1 + update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 >>/dev/null 2>&1 + PYV=$(which python3.6) + fi + fi + else + echo "Python3.6 未安装在此系统上,正在进行安装" + yum install python3 -y >>/dev/null 2>&1 + update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 >>/dev/null 2>&1 + fi + if command -v pip3 >>/dev/null 2>&1; then + echo 'pip 存在 . . .' + else + echo "pip3 未安装在此系统上,正在进行安装" + yum install -y python3-pip >>/dev/null 2>&1 + fi } yum_screen_check() { - echo "正在检查 Screen 安装情况 . . ." - if command -v screen >>/dev/null 2>&1; then - echo "Screen 似乎存在, 安装过程继续 . . ." - else - echo "Screen 未安装在此系统上,正在进行安装" - yum install screen -y >>/dev/null 2>&1 - fi + echo "正在检查 Screen 安装情况 . . ." + if command -v screen >>/dev/null 2>&1; then + echo "Screen 似乎存在, 安装过程继续 . . ." + else + echo "Screen 未安装在此系统上,正在进行安装" + yum install screen -y >>/dev/null 2>&1 + fi } yum_require_install() { - echo "正在安装系统所需依赖,可能需要几分钟的时间 . . ." - yum install python-devel python3-devel zbar zbar-devel ImageMagick wget -y >>/dev/null 2>&1 - wget -T 2 -O /etc/yum.repos.d/konimex-neofetch-epel-7.repo https://copr.fedorainfracloud.org/coprs/konimex/neofetch/repo/epel-7/konimex-neofetch-epel-7.repo >>/dev/null 2>&1 - yum groupinstall "Development Tools" -y >>/dev/null 2>&1 - yum-config-manager --add-repo https://download.opensuse.org/repositories/home:/Alexander_Pozdnyakov/CentOS_7/ >>/dev/null 2>&1 - sudo rpm --import https://build.opensuse.org/projects/home:Alexander_Pozdnyakov/public_key >>/dev/null 2>&1 - yum list updates >>/dev/null 2>&1 - yum install neofetch figlet tesseract tesseract-langpack-chi-sim tesseract-langpack-eng -y >>/dev/null 2>&1 + echo "正在安装系统所需依赖,可能需要几分钟的时间 . . ." + yum install python-devel python3-devel zbar zbar-devel ImageMagick wget -y >>/dev/null 2>&1 + wget -T 2 -O /etc/yum.repos.d/konimex-neofetch-epel-7.repo https://copr.fedorainfracloud.org/coprs/konimex/neofetch/repo/epel-7/konimex-neofetch-epel-7.repo >>/dev/null 2>&1 + yum groupinstall "Development Tools" -y >>/dev/null 2>&1 + yum-config-manager --add-repo https://download.opensuse.org/repositories/home:/Alexander_Pozdnyakov/CentOS_7/ >>/dev/null 2>&1 + sudo rpm --import https://build.opensuse.org/projects/home:Alexander_Pozdnyakov/public_key >>/dev/null 2>&1 + yum list updates >>/dev/null 2>&1 + yum install neofetch figlet tesseract tesseract-langpack-chi-sim tesseract-langpack-eng -y >>/dev/null 2>&1 } apt_update() { - echo "正在优化 apt-get . . ." - apt-get install sudo -y >>/dev/null 2>&1 - apt-get update >>/dev/null 2>&1 + echo "正在优化 apt-get . . ." + apt-get install sudo -y >>/dev/null 2>&1 + apt-get update >>/dev/null 2>&1 } apt_git_check() { - echo "正在检查 Git 安装情况 . . ." - if command -v git >>/dev/null 2>&1; then - echo "Git 似乎存在, 安装过程继续 . . ." - else - echo "Git 未安装在此系统上,正在进行安装" - apt-get install git -y >>/dev/null 2>&1 - fi + echo "正在检查 Git 安装情况 . . ." + if command -v git >>/dev/null 2>&1; then + echo "Git 似乎存在, 安装过程继续 . . ." + else + echo "Git 未安装在此系统上,正在进行安装" + apt-get install git -y >>/dev/null 2>&1 + fi } apt_python_check() { - echo "正在检查 python 安装情况 . . ." - if command -v python3 >>/dev/null 2>&1; then - U_V1=$(python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1}') - U_V2=$(python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $2}') - if [ $U_V1 -gt 3 ]; then - echo 'Python 3.6+ 存在 . . .' - elif [ $U_V2 -ge 6 ]; then - echo 'Python 3.6+ 存在 . . .' - PYV=$U_V1.$U_V2 - PYV=$(which python$PYV) - else - if command -v python3.6 >>/dev/null 2>&1; then - echo 'Python 3.6+ 存在 . . .' - PYV=$(which python3.6) - else - echo "Python3.6 未安装在此系统上,正在进行安装" - add-apt-repository ppa:deadsnakes/ppa -y - apt-get update >>/dev/null 2>&1 - apt-get install python3.6 -y >>/dev/null 2>&1 - update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 >>/dev/null 2>&1 - PYV=$(which python3.6) - fi - fi - else - echo "Python3.6 未安装在此系统上,正在进行安装" - add-apt-repository ppa:deadsnakes/ppa -y - apt-get update >>/dev/null 2>&1 - apt-get install python3.6 -y >>/dev/null 2>&1 - update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 >>/dev/null 2>&1 - fi - if command -v pip3 >>/dev/null 2>&1; then - echo 'pip 存在 . . .' - else - echo "pip3 未安装在此系统上,正在进行安装" - apt-get install -y python3-pip >>/dev/null 2>&1 - fi + echo "正在检查 python 安装情况 . . ." + if command -v python3 >>/dev/null 2>&1; then + U_V1=$(python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1}') + U_V2=$(python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $2}') + if [ $U_V1 -gt 3 ]; then + echo 'Python 3.6+ 存在 . . .' + elif [ $U_V2 -ge 6 ]; then + echo 'Python 3.6+ 存在 . . .' + PYV=$U_V1.$U_V2 + PYV=$(which python$PYV) + else + if command -v python3.6 >>/dev/null 2>&1; then + echo 'Python 3.6+ 存在 . . .' + PYV=$(which python3.6) + else + echo "Python3.6 未安装在此系统上,正在进行安装" + add-apt-repository ppa:deadsnakes/ppa -y + apt-get update >>/dev/null 2>&1 + apt-get install python3.6 -y >>/dev/null 2>&1 + update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 >>/dev/null 2>&1 + PYV=$(which python3.6) + fi + fi + else + echo "Python3.6 未安装在此系统上,正在进行安装" + add-apt-repository ppa:deadsnakes/ppa -y + apt-get update >>/dev/null 2>&1 + apt-get install python3.6 -y >>/dev/null 2>&1 + update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 >>/dev/null 2>&1 + fi + if command -v pip3 >>/dev/null 2>&1; then + echo 'pip 存在 . . .' + else + echo "pip3 未安装在此系统上,正在进行安装" + apt-get install -y python3-pip >>/dev/null 2>&1 + fi } debian_python_check() { - echo "正在检查 python 安装情况 . . ." - if command -v python3 >>/dev/null 2>&1; then - U_V1=$(python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1}') - U_V2=$(python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $2}') - if [ $U_V1 -gt 3 ]; then - echo 'Python 3.6+ 存在 . . .' - elif [ $U_V2 -ge 6 ]; then - echo 'Python 3.6+ 存在 . . .' - PYV=$U_V1.$U_V2 - PYV=$(which python$PYV) - else - if command -v python3.6 >>/dev/null 2>&1; then - echo 'Python 3.6+ 存在 . . .' - PYV=$(which python3.6) - else - echo "Python3.6 未安装在此系统上,正在进行安装" - apt-get update -y >>/dev/null 2>&1 - apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev >>/dev/null 2>&1 - wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz >>/dev/null 2>&1 - tar -xvf Python-3.6.5.tgz >>/dev/null 2>&1 - chmod -R +x Python-3.6.5 >>/dev/null 2>&1 - cd Python-3.6.5 >>/dev/null 2>&1 - ./configure >>/dev/null 2>&1 - make && make install >>/dev/null 2>&1 - cd .. >>/dev/null 2>&1 - rm -rf Python-3.6.5 Python-3.6.5.tar.gz >>/dev/null 2>&1 - PYP=$(which python3.6) - update-alternatives --install $PYP python3 $PYV 1 >>/dev/null 2>&1 - fi - fi - else - echo "Python3.6 未安装在此系统上,正在进行安装" - apt-get update -y >>/dev/null 2>&1 - apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev >>/dev/null 2>&1 - wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz >>/dev/null 2>&1 - tar -xvf Python-3.6.5.tgz >>/dev/null 2>&1 - chmod -R +x Python-3.6.5 >>/dev/null 2>&1 - cd Python-3.6.5 >>/dev/null 2>&1 - ./configure >>/dev/null 2>&1 - make && make install >>/dev/null 2>&1 - cd .. >>/dev/null 2>&1 - rm -rf Python-3.6.5 Python-3.6.5.tar.gz >>/dev/null 2>&1 - PYP=$(which python3) - update-alternatives --install $PYP python3 $PYV 1 >>/dev/null 2>&1 - fi - echo "正在检查 pip3 安装情况 . . ." - if command -v pip3 >>/dev/null 2>&1; then - echo 'pip 存在 . . .' - else - echo "pip3 未安装在此系统上,正在进行安装" - apt-get install -y python3-pip >>/dev/null 2>&1 - fi + echo "正在检查 python 安装情况 . . ." + if command -v python3 >>/dev/null 2>&1; then + U_V1=$(python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1}') + U_V2=$(python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $2}') + if [ $U_V1 -gt 3 ]; then + echo 'Python 3.6+ 存在 . . .' + elif [ $U_V2 -ge 6 ]; then + echo 'Python 3.6+ 存在 . . .' + PYV=$U_V1.$U_V2 + PYV=$(which python$PYV) + else + if command -v python3.6 >>/dev/null 2>&1; then + echo 'Python 3.6+ 存在 . . .' + PYV=$(which python3.6) + else + echo "Python3.6 未安装在此系统上,正在进行安装" + apt-get update -y >>/dev/null 2>&1 + apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev >>/dev/null 2>&1 + wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz >>/dev/null 2>&1 + tar -xvf Python-3.6.5.tgz >>/dev/null 2>&1 + chmod -R +x Python-3.6.5 >>/dev/null 2>&1 + cd Python-3.6.5 >>/dev/null 2>&1 + ./configure >>/dev/null 2>&1 + make && make install >>/dev/null 2>&1 + cd .. >>/dev/null 2>&1 + rm -rf Python-3.6.5 Python-3.6.5.tar.gz >>/dev/null 2>&1 + PYP=$(which python3.6) + update-alternatives --install $PYP python3 $PYV 1 >>/dev/null 2>&1 + fi + fi + else + echo "Python3.6 未安装在此系统上,正在进行安装" + apt-get update -y >>/dev/null 2>&1 + apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev >>/dev/null 2>&1 + wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz >>/dev/null 2>&1 + tar -xvf Python-3.6.5.tgz >>/dev/null 2>&1 + chmod -R +x Python-3.6.5 >>/dev/null 2>&1 + cd Python-3.6.5 >>/dev/null 2>&1 + ./configure >>/dev/null 2>&1 + make && make install >>/dev/null 2>&1 + cd .. >>/dev/null 2>&1 + rm -rf Python-3.6.5 Python-3.6.5.tar.gz >>/dev/null 2>&1 + PYP=$(which python3) + update-alternatives --install $PYP python3 $PYV 1 >>/dev/null 2>&1 + fi + echo "正在检查 pip3 安装情况 . . ." + if command -v pip3 >>/dev/null 2>&1; then + echo 'pip 存在 . . .' + else + echo "pip3 未安装在此系统上,正在进行安装" + apt-get install -y python3-pip >>/dev/null 2>&1 + fi } apt_screen_check() { - echo "正在检查 Screen 安装情况 . . ." - if command -v screen >>/dev/null 2>&1; then - echo "Screen 似乎存在, 安装过程继续 . . ." - else - echo "Screen 未安装在此系统上,正在进行安装" - apt-get install screen -y >>/dev/null 2>&1 - fi + echo "正在检查 Screen 安装情况 . . ." + if command -v screen >>/dev/null 2>&1; then + echo "Screen 似乎存在, 安装过程继续 . . ." + else + echo "Screen 未安装在此系统上,正在进行安装" + apt-get install screen -y >>/dev/null 2>&1 + fi } apt_require_install() { - echo "正在安装系统所需依赖,可能需要几分钟的时间 . . ." - apt-get install python3.6-dev python3-dev imagemagick software-properties-common tesseract-ocr tesseract-ocr-chi-sim libzbar-dev -y >>/dev/null 2>&1 - add-apt-repository ppa:dawidd0811/neofetch -y - apt-get install neofetch -y >>/dev/null 2>&1 + echo "正在安装系统所需依赖,可能需要几分钟的时间 . . ." + apt-get install python3.6-dev python3-dev imagemagick software-properties-common tesseract-ocr tesseract-ocr-chi-sim libzbar-dev -y >>/dev/null 2>&1 + add-apt-repository ppa:dawidd0811/neofetch -y + apt-get install neofetch -y >>/dev/null 2>&1 } debian_require_install() { - echo "正在安装系统所需依赖,可能需要几分钟的时间 . . ." - apt-get install imagemagick software-properties-common tesseract-ocr tesseract-ocr-chi-sim libzbar-dev neofetch -y >>/dev/null 2>&1 + echo "正在安装系统所需依赖,可能需要几分钟的时间 . . ." + apt-get install imagemagick software-properties-common tesseract-ocr tesseract-ocr-chi-sim libzbar-dev neofetch -y >>/dev/null 2>&1 } download_repo() { - echo "下载 repository 中 . . ." - rm -rf /var/lib/pagermaid >>/dev/null 2>&1 - git clone https://github.com/xtaodada/PagerMaid-Modify.git /var/lib/pagermaid >>/dev/null 2>&1 - cd /var/lib/pagermaid >>/dev/null 2>&1 - echo "Hello World!" >/var/lib/pagermaid/public.lock + echo "下载 repository 中 . . ." + rm -rf /var/lib/pagermaid >>/dev/null 2>&1 + git clone https://github.com/xtaodada/PagerMaid-Modify.git /var/lib/pagermaid >>/dev/null 2>&1 + cd /var/lib/pagermaid >>/dev/null 2>&1 + echo "Hello World!" >/var/lib/pagermaid/public.lock } pypi_install() { - echo "下载安装 pypi 依赖中 . . ." - $PYV -m pip install --upgrade pip >>/dev/null 2>&1 - $PYV -m pip install -r requirements.txt >>/dev/null 2>&1 - sudo -H $PYV -m pip install --ignore-installed PyYAML >>/dev/null 2>&1 + echo "下载安装 pypi 依赖中 . . ." + $PYV -m pip install --upgrade pip >>/dev/null 2>&1 + $PYV -m pip install -r requirements.txt >>/dev/null 2>&1 + sudo -H $PYV -m pip install --ignore-installed PyYAML >>/dev/null 2>&1 } configure() { - config_file=config.yml - echo "生成配置文件中 . . ." - cp config.gen.yml config.yml - echo "api_key、api_hash 申请地址: https://my.telegram.org/" - printf "请输入应用程序 api_key:" - read -r api_key <&1 - sed -i "s/ID_HERE/$api_key/" $config_file - printf "请输入应用程序 api_hash:" - read -r api_hash <&1 - sed -i "s/HASH_HERE/$api_hash/" $config_file - printf "请输入应用程序语言(默认:zh-cn):" - read -r application_language <&1 - if [ -z "$application_language" ]; then - echo "语言设置为 简体中文" - else - sed -i "s/zh-cn/$application_language/" $config_file - fi - printf "请输入应用程序地区(默认:China):" - read -r application_region <&1 - if [ -z "$application_region" ]; then - echo "地区设置为 中国" - else - sed -i "s/China/$application_region/" $config_file - fi - printf "请输入 Google TTS 语言(默认:zh-CN):" - read -r application_tts <&1 - if [ -z "$application_tts" ]; then - echo "tts发音语言设置为 简体中文" - else - sed -i "s/zh-CN/$application_tts/" $config_file - fi - printf "启用日志记录? [Y/n]" - read -r logging_confirmation <&1 - case $logging_confirmation in - [yY][eE][sS] | [yY]) - printf "请输入您的日志记录群组/频道的 ChatID (如果要发送给 原 PagerMaid 作者 ,请按Enter):" - read -r log_chatid <&1 - if [ -z "$log_chatid" ]; then - echo "LOG 将发送到 原 PagerMaid 作者." - else - sed -i "s/503691334/$log_chatid/" $config_file - fi - sed -i "s/log: False/log: True/" $config_file - ;; - [nN][oO] | [nN]) - echo "安装过程继续 . . ." - ;; - *) - echo "输入错误 . . ." - exit 1 - ;; - esac + config_file=config.yml + echo "生成配置文件中 . . ." + cp config.gen.yml config.yml + echo "api_key、api_hash 申请地址: https://my.telegram.org/" + printf "请输入应用程序 api_key:" + read -r api_key <&1 + sed -i "s/ID_HERE/$api_key/" $config_file + printf "请输入应用程序 api_hash:" + read -r api_hash <&1 + sed -i "s/HASH_HERE/$api_hash/" $config_file + printf "请输入应用程序语言(默认:zh-cn):" + read -r application_language <&1 + if [ -z "$application_language" ]; then + echo "语言设置为 简体中文" + else + sed -i "s/zh-cn/$application_language/" $config_file + fi + printf "请输入应用程序地区(默认:China):" + read -r application_region <&1 + if [ -z "$application_region" ]; then + echo "地区设置为 中国" + else + sed -i "s/China/$application_region/" $config_file + fi + printf "请输入 Google TTS 语言(默认:zh-CN):" + read -r application_tts <&1 + if [ -z "$application_tts" ]; then + echo "tts发音语言设置为 简体中文" + else + sed -i "s/zh-CN/$application_tts/" $config_file + fi + printf "启用日志记录? [Y/n]" + read -r logging_confirmation <&1 + case $logging_confirmation in + [yY][eE][sS] | [yY]) + printf "请输入您的日志记录群组/频道的 ChatID (如果要发送给 原 PagerMaid 作者 ,请按Enter):" + read -r log_chatid <&1 + if [ -z "$log_chatid" ]; then + echo "LOG 将发送到 原 PagerMaid 作者." + else + sed -i "s/503691334/$log_chatid/" $config_file + fi + sed -i "s/log: False/log: True/" $config_file + ;; + [nN][oO] | [nN]) + echo "安装过程继续 . . ." + ;; + *) + echo "输入错误 . . ." + exit 1 + ;; + esac } read_checknum() { - while :; do - read -p "请输入您的登录验证码: " checknum - if [ "$checknum" == "" ]; then - continue - fi - read -p "请再次输入您的登录验证码:" checknum2 - if [ "$checknum" != "$checknum2" ]; then - echo "两次验证码不一致!请重新输入您的登录验证码" - continue + while :; do + read -p "请输入您的登录验证码: " checknum + if [ "$checknum" == "" ]; then + continue + fi + read -p "请再次输入您的登录验证码:" checknum2 + if [ "$checknum" != "$checknum2" ]; then + echo "两次验证码不一致!请重新输入您的登录验证码" + continue - else - screen -x -S userbot -p 0 -X stuff "$checknum" - screen -x -S userbot -p 0 -X stuff $'\n' - break - fi + else + screen -x -S userbot -p 0 -X stuff "$checknum" + screen -x -S userbot -p 0 -X stuff $'\n' + break + fi done - read -p "有没有二次登录验证码? [Y/n]" choi - if [ "$choi" == "y" ] || [ "$choi" == "Y" ]; then - read -p "请输入您的二次登录验证码: " twotimepwd - screen -x -S userbot -p 0 -X stuff "$twotimepwd" - screen -x -S userbot -p 0 -X stuff $'\n' - fi - + read -p "有没有二次登录验证码? [Y/n]" choi + if [ "$choi" == "y" ] || [ "$choi" == "Y" ]; then + read -p "请输入您的二次登录验证码: " twotimepwd + screen -x -S userbot -p 0 -X stuff "$twotimepwd" + screen -x -S userbot -p 0 -X stuff $'\n' + fi + } login_screen() { - screen -S userbot -X quit >>/dev/null 2>&1 - screen -dmS userbot - sleep 1 - screen -x -S userbot -p 0 -X stuff "cd /var/lib/pagermaid && $PYV -m pagermaid" - screen -x -S userbot -p 0 -X stuff $'\n' - sleep 3 - if [ "$(ps -def | grep [p]agermaid | grep -v grep)" == "" ]; then - echo "PagerMaid 运行时发生错误,错误信息:" - cd /var/lib/pagermaid && $PYV -m pagermaid >err.log - cat err.log - screen -S userbot -X quit >>/dev/null 2>&1 - exit 1 - fi - while :; do - read -p "请输入您的 Telegram 手机号码(带国际区号 如 +8618888888888): " phonenum + screen -S userbot -X quit >>/dev/null 2>&1 + screen -dmS userbot + sleep 1 + screen -x -S userbot -p 0 -X stuff "cd /var/lib/pagermaid && $PYV -m pagermaid" + screen -x -S userbot -p 0 -X stuff $'\n' + sleep 3 + if [ "$(ps -def | grep [p]agermaid | grep -v grep)" == "" ]; then + echo "PagerMaid 运行时发生错误,错误信息:" + cd /var/lib/pagermaid && $PYV -m pagermaid >err.log + cat err.log + screen -S userbot -X quit >>/dev/null 2>&1 + exit 1 + fi + while :; do + read -p "请输入您的 Telegram 手机号码(带国际区号 如 +8618888888888): " phonenum - if [ "$phonenum" == "" ]; then - continue - fi + if [ "$phonenum" == "" ]; then + continue + fi - screen -x -S userbot -p 0 -X stuff "$phonenum" - screen -x -S userbot -p 0 -X stuff $'\n' + screen -x -S userbot -p 0 -X stuff "$phonenum" + screen -x -S userbot -p 0 -X stuff $'\n' - if [ "$(ps -def | grep [p]agermaid | grep -v grep)" == "" ]; then - echo "手机号输入错误!请确认您是否带了区号(中国号码为 +86 如 +8618888888888)" - screen -x -S userbot -p 0 -X stuff "cd /var/lib/pagermaid && $PYV -m pagermaid" - screen -x -S userbot -p 0 -X stuff $'\n' - continue - fi + if [ "$(ps -def | grep [p]agermaid | grep -v grep)" == "" ]; then + echo "手机号输入错误!请确认您是否带了区号(中国号码为 +86 如 +8618888888888)" + screen -x -S userbot -p 0 -X stuff "cd /var/lib/pagermaid && $PYV -m pagermaid" + screen -x -S userbot -p 0 -X stuff $'\n' + continue + fi - sleep 1 - if [ "$(ps -def | grep [p]agermaid | grep -v grep)" == "" ]; then - echo "PagerMaid 运行时发生错误,可能是因为发送验证码失败,请检查您的 API_KEY 和 API_HASH" - exit 1 - fi + sleep 1 + if [ "$(ps -def | grep [p]agermaid | grep -v grep)" == "" ]; then + echo "PagerMaid 运行时发生错误,可能是因为发送验证码失败,请检查您的 API_KEY 和 API_HASH" + exit 1 + fi - read -p "请输入您的登录验证码: " checknum - if [ "$checknum" == "" ]; then - read_checknum - break - fi + read -p "请输入您的登录验证码: " checknum + if [ "$checknum" == "" ]; then + read_checknum + break + fi - read -p "请再次输入您的登录验证码:" checknum2 - if [ "$checknum" != "$checknum2" ]; then - echo "两次验证码不一致!请重新输入您的登录验证码" - read_checknum - break - else - screen -x -S userbot -p 0 -X stuff "$checknum" - screen -x -S userbot -p 0 -X stuff $'\n' - fi + read -p "请再次输入您的登录验证码:" checknum2 + if [ "$checknum" != "$checknum2" ]; then + echo "两次验证码不一致!请重新输入您的登录验证码" + read_checknum + break + else + screen -x -S userbot -p 0 -X stuff "$checknum" + screen -x -S userbot -p 0 -X stuff $'\n' + fi - read -p "有没有二次登录验证码? [Y/n]" choi - if [ "$choi" == "y" ] || [ "$choi" == "Y" ]; then - read -p "请输入您的二次登录验证码: " twotimepwd - screen -x -S userbot -p 0 -X stuff "$twotimepwd" - screen -x -S userbot -p 0 -X stuff $'\n' - break - fi - done - sleep 5 - screen -S userbot -X quit >>/dev/null 2>&1 + read -p "有没有二次登录验证码? [Y/n]" choi + if [ "$choi" == "y" ] || [ "$choi" == "Y" ]; then + read -p "请输入您的二次登录验证码: " twotimepwd + screen -x -S userbot -p 0 -X stuff "$twotimepwd" + screen -x -S userbot -p 0 -X stuff $'\n' + break + fi + done + sleep 5 + screen -S userbot -X quit >>/dev/null 2>&1 } systemctl_reload() { - echo "正在写入系统进程守护 . . ." - echo "[Unit] + echo "正在写入系统进程守护 . . ." + echo "[Unit] Description=PagerMaid-Modify telegram utility daemon After=network.target [Install] @@ -410,199 +410,199 @@ systemctl_reload() { ExecStart=$PYV -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 start pagermaid >>/dev/null 2>&1 - systemctl enable pagermaid >>/dev/null 2>&1 + chmod 755 pagermaid.service >>/dev/null 2>&1 + systemctl daemon-reload >>/dev/null 2>&1 + systemctl start pagermaid >>/dev/null 2>&1 + systemctl enable pagermaid >>/dev/null 2>&1 } start_installation() { - if [ "$release" = "centos" ]; then - echo "系统检测通过。" - welcome - yum_update - yum_git_check - yum_python_check - yum_screen_check - yum_require_install - download_repo - pypi_install - configure - login_screen - systemctl_reload - echo "PagerMaid 已经安装完毕 在telegram对话框中输入 -help 并发送查看帮助列表" - elif [ "$release" = "ubuntu" ]; then - echo "系统检测通过。" - welcome - apt_update - apt_git_check - apt_python_check - apt_screen_check - apt_require_install - download_repo - pypi_install - configure - login_screen - systemctl_reload - echo "PagerMaid 已经安装完毕 在telegram对话框中输入 -help 并发送查看帮助列表" - elif [ "$release" = "debian" ]; then - echo "系统检测通过。" - welcome - apt_update - apt_git_check - debian_python_check - apt_screen_check - debian_require_install - download_repo - pypi_install - configure - login_screen - systemctl_reload - echo "PagerMaid 已经安装完毕 在telegram对话框中输入 -help 并发送查看帮助列表" - else - echo "目前暂时不支持此系统。" - fi - exit 1 + if [ "$release" = "centos" ]; then + echo "系统检测通过。" + welcome + yum_update + yum_git_check + yum_python_check + yum_screen_check + yum_require_install + download_repo + pypi_install + configure + login_screen + systemctl_reload + echo "PagerMaid 已经安装完毕 在telegram对话框中输入 -help 并发送查看帮助列表" + elif [ "$release" = "ubuntu" ]; then + echo "系统检测通过。" + welcome + apt_update + apt_git_check + apt_python_check + apt_screen_check + apt_require_install + download_repo + pypi_install + configure + login_screen + systemctl_reload + echo "PagerMaid 已经安装完毕 在telegram对话框中输入 -help 并发送查看帮助列表" + elif [ "$release" = "debian" ]; then + echo "系统检测通过。" + welcome + apt_update + apt_git_check + debian_python_check + apt_screen_check + debian_require_install + download_repo + pypi_install + configure + login_screen + systemctl_reload + echo "PagerMaid 已经安装完毕 在telegram对话框中输入 -help 并发送查看帮助列表" + else + echo "目前暂时不支持此系统。" + fi + exit 1 } cleanup() { - if [ ! -x "/var/lib/pagermaid" ]; then - echo "目录不存在不需要卸载。" - else - echo "正在关闭 PagerMaid . . ." - systemctl disable pagermaid >>/dev/null 2>&1 - systemctl stop pagermaid >>/dev/null 2>&1 - echo "正在删除 PagerMaid 文件 . . ." - rm -rf /etc/systemd/system/pagermaid.service >>/dev/null 2>&1 - rm -rf /var/lib/pagermaid >>/dev/null 2>&1 - echo "卸载完成 . . ." - fi + if [ ! -x "/var/lib/pagermaid" ]; then + echo "目录不存在不需要卸载。" + else + echo "正在关闭 PagerMaid . . ." + systemctl disable pagermaid >>/dev/null 2>&1 + systemctl stop pagermaid >>/dev/null 2>&1 + echo "正在删除 PagerMaid 文件 . . ." + rm -rf /etc/systemd/system/pagermaid.service >>/dev/null 2>&1 + rm -rf /var/lib/pagermaid >>/dev/null 2>&1 + echo "卸载完成 . . ." + fi } reinstall() { - cleanup - start_installation + cleanup + start_installation } cleansession() { - if [ ! -x "/var/lib/pagermaid" ]; then - echo "目录不存在请重新安装 PagerMaid。" - exit 1 - fi - echo "正在关闭 PagerMaid . . ." - systemctl stop pagermaid >>/dev/null 2>&1 - echo "正在删除账户授权文件 . . ." - rm -rf /var/lib/pagermaid/pagermaid.session >>/dev/null 2>&1 - echo "请进行重新登陆. . ." - if [ "$release" = "centos" ]; then - yum_python_check - yum_screen_check - elif [ "$release" = "ubuntu" ]; then - apt_python_check - apt_screen_check - elif [ "$release" = "debian" ]; then - debian_python_check - apt_screen_check - else - echo "目前暂时不支持此系统。" - fi - login_screen - systemctl start pagermaid >>/dev/null 2>&1 + if [ ! -x "/var/lib/pagermaid" ]; then + echo "目录不存在请重新安装 PagerMaid。" + exit 1 + fi + echo "正在关闭 PagerMaid . . ." + systemctl stop pagermaid >>/dev/null 2>&1 + echo "正在删除账户授权文件 . . ." + rm -rf /var/lib/pagermaid/pagermaid.session >>/dev/null 2>&1 + echo "请进行重新登陆. . ." + if [ "$release" = "centos" ]; then + yum_python_check + yum_screen_check + elif [ "$release" = "ubuntu" ]; then + apt_python_check + apt_screen_check + elif [ "$release" = "debian" ]; then + debian_python_check + apt_screen_check + else + echo "目前暂时不支持此系统。" + fi + login_screen + systemctl start pagermaid >>/dev/null 2>&1 } stop_pager() { - echo "" - echo "正在关闭 PagerMaid . . ." - systemctl stop pagermaid >>/dev/null 2>&1 - echo "" - sleep 3 - shon_online + echo "" + echo "正在关闭 PagerMaid . . ." + systemctl stop pagermaid >>/dev/null 2>&1 + echo "" + sleep 3 + shon_online } start_pager() { - echo "" - echo "正在启动 PagerMaid . . ." - systemctl start pagermaid >>/dev/null 2>&1 - echo "" - sleep 3 - shon_online + echo "" + echo "正在启动 PagerMaid . . ." + systemctl start pagermaid >>/dev/null 2>&1 + echo "" + sleep 3 + shon_online } restart_pager() { - echo "" - echo "正在重新启动 PagerMaid . . ." - systemctl restart pagermaid >>/dev/null 2>&1 - echo "" - sleep 3 - shon_online + echo "" + echo "正在重新启动 PagerMaid . . ." + systemctl restart pagermaid >>/dev/null 2>&1 + echo "" + sleep 3 + shon_online } install_require() { - if [ "$release" = "centos" ]; then - echo "系统检测通过。" - yum_update - yum_git_check - yum_python_check - yum_screen_check - yum_require_install - pypi_install - systemctl_reload - shon_online - elif [ "$release" = "ubuntu" ]; then - echo "系统检测通过。" - apt_update - apt_git_check - apt_python_check - apt_screen_check - apt_require_install - pypi_install - systemctl_reload - shon_online - elif [ "$release" = "debian" ]; then - echo "系统检测通过。" - welcome - apt_update - apt_git_check - debian_python_check - apt_screen_check - debian_require_install - pypi_install - systemctl_reload - shon_online - else - echo "目前暂时不支持此系统。" - fi - exit 1 + if [ "$release" = "centos" ]; then + echo "系统检测通过。" + yum_update + yum_git_check + yum_python_check + yum_screen_check + yum_require_install + pypi_install + systemctl_reload + shon_online + elif [ "$release" = "ubuntu" ]; then + echo "系统检测通过。" + apt_update + apt_git_check + apt_python_check + apt_screen_check + apt_require_install + pypi_install + systemctl_reload + shon_online + elif [ "$release" = "debian" ]; then + echo "系统检测通过。" + welcome + apt_update + apt_git_check + debian_python_check + apt_screen_check + debian_require_install + pypi_install + systemctl_reload + shon_online + else + echo "目前暂时不支持此系统。" + fi + exit 1 } shon_online() { - echo "请选择您需要进行的操作:" - echo " 1) 安装 PagerMaid" - echo " 2) 卸载 PagerMaid" - echo " 3) 重新安装 PagerMaid" - echo " 4) 重新登陆 PagerMaid" - echo " 5) 关闭 PagerMaid" - echo " 6) 启动 PagerMaid" - echo " 7) 重新启动 PagerMaid" - echo " 8) 重新安装 PagerMaid 依赖" - echo " 9) 退出脚本" - echo "" - echo " Version:0.1.3" - echo "" - echo -n "请输入编号: " - read N - case $N in - 1) start_installation ;; - 2) cleanup ;; - 3) reinstall ;; - 4) cleansession ;; - 5) stop_pager ;; - 6) start_pager ;; - 7) restart_pager ;; - 8) install_require ;; - 9) exit ;; - *) echo "Wrong input!" ;; - esac + echo "请选择您需要进行的操作:" + echo " 1) 安装 PagerMaid" + echo " 2) 卸载 PagerMaid" + echo " 3) 重新安装 PagerMaid" + echo " 4) 重新登陆 PagerMaid" + echo " 5) 关闭 PagerMaid" + echo " 6) 启动 PagerMaid" + echo " 7) 重新启动 PagerMaid" + echo " 8) 重新安装 PagerMaid 依赖" + echo " 9) 退出脚本" + echo "" + echo " Version:0.1.3" + echo "" + echo -n "请输入编号: " + read N + case $N in + 1) start_installation ;; + 2) cleanup ;; + 3) reinstall ;; + 4) cleansession ;; + 5) stop_pager ;; + 6) start_pager ;; + 7) restart_pager ;; + 8) install_require ;; + 9) exit ;; + *) echo "Wrong input!" ;; + esac } check_sys diff --git a/s6/etc/cont-init.d/10-adduser b/s6/etc/cont-init.d/10-adduser new file mode 100755 index 0000000..b618425 --- /dev/null +++ b/s6/etc/cont-init.d/10-adduser @@ -0,0 +1,7 @@ +#!/usr/bin/with-contenv bash + +PUID=${PUID:-917} +PGID=${PGID:-917} + +groupmod -o -g "$PGID" pagermaid +usermod -o -u "$PUID" pagermaid diff --git a/s6/etc/cont-init.d/30-config b/s6/etc/cont-init.d/30-config new file mode 100755 index 0000000..70c95a9 --- /dev/null +++ b/s6/etc/cont-init.d/30-config @@ -0,0 +1,3 @@ +#!/usr/bin/with-contenv bash + +chown -R pagermaid:pagermaid /pagermaid \ No newline at end of file diff --git a/s6/etc/services.d/pagermaid/run b/s6/etc/services.d/pagermaid/run new file mode 100755 index 0000000..69cb117 --- /dev/null +++ b/s6/etc/services.d/pagermaid/run @@ -0,0 +1,5 @@ +#!/usr/bin/with-contenv bash + +cd /pagermaid/workdir +exec s6-setuidgid pagermaid python -m pagermaid + diff --git a/s6/etc/services.d/redis/run b/s6/etc/services.d/redis/run new file mode 100755 index 0000000..b1a6081 --- /dev/null +++ b/s6/etc/services.d/redis/run @@ -0,0 +1,3 @@ +#!/usr/bin/with-contenv bash + +exec s6-setuidgid pagermaid redis-server --daemonize yes \ No newline at end of file diff --git a/utils/docker-config.sh b/utils/docker-config.sh new file mode 100644 index 0000000..eef8a2a --- /dev/null +++ b/utils/docker-config.sh @@ -0,0 +1,95 @@ +#!/usr/bin/with-contenv bash + +welcome () { + echo + echo "欢迎进入 PagerMaid-Modify Docker 。" + echo "配置即将开始" + echo + sleep 2 +} + +configure () { + local config_file=config.yml + + echo "生成配置文件中 . . ." + cp config.gen.yml $config_file + echo "api_key、api_hash 申请地址: https://my.telegram.org/" + printf "请输入应用程序 api_key:" + read -r api_key <&1 + sed -i "s/ID_HERE/$api_key/" $config_file + printf "请输入应用程序 api_hash:" + read -r api_hash <&1 + sed -i "s/HASH_HERE/$api_hash/" $config_file + printf "请输入应用程序语言(默认:zh-cn):" + read -r application_language <&1 + if [ -z "$application_language" ] + then + echo "语言设置为 简体中文" + else + sed -i "s/zh-cn/$application_language/" $config_file + fi + printf "请输入应用程序地区(默认:China):" + read -r application_region <&1 + if [ -z "$application_region" ] + then + echo "地区设置为 中国" + else + sed -i "s/China/$application_region/" $config_file + fi + printf "请输入 Google TTS 语言(默认:zh-CN):" + read -r application_tts <&1 + if [ -z "$application_tts" ] + then + echo "tts发音语言设置为 简体中文" + else + sed -i "s/zh-CN/$application_tts/" $config_file + fi + printf "启用日志记录? [Y/n]" + read -r logging_confirmation <&1 + case $logging_confirmation in + [yY][eE][sS] | [yY]) + printf "请输入您的日志记录群组/频道的 ChatID (如果要发送给 原 PagerMaid 作者 ,请按Enter):" + read -r log_chatid <&1 + if [ -z "$log_chatid" ] + then + echo "LOG 将发送到 原 PagerMaid 作者." + else + sed -i "s/503691334/$log_chatid/" $config_file + fi + sed -i "s/log: False/log: True/" $config_file + ;; + [nN][oO] | [nN]) + echo "安装过程继续 . . ." + ;; + *) + echo "输入错误 . . ." + exit 1 + ;; + esac +} + +login () { + echo + echo "下面进行程序运行。" + echo "请在账户授权完毕后,按 Ctrl + C 使 Docker 在后台模式下运行。" + echo + sleep 2 + echo "Hello world!" > /pagermaid/workdir/install.lock + python -m pagermaid + exit 0 +} + +main () { + cd /pagermaid/workdir + if [ ! -s "/pagermaid/workdir/install.lock" ]; then + welcome + configure + login + else + if [ ! -f "/pagermaid/workdir/pagermaid.session" ]; then + login + fi + fi +} + +main \ No newline at end of file diff --git a/utils/docker-run.sh b/utils/docker-run.sh deleted file mode 100644 index 4222bf7..0000000 --- a/utils/docker-run.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/bash - -welcome() { - echo "" - echo "欢迎进入 PagerMaid-Modify Docker 。" - echo "配置即将开始" - echo "" - sleep 2 -} - -configure() { - cd /pagermaid/workdir - config_file=config.yml - echo "生成配置文件中 . . ." - cp config.gen.yml config.yml - echo "api_key、api_hash 申请地址: https://my.telegram.org/" - printf "请输入应用程序 api_key:" - read -r api_key <&1 - sed -i "s/ID_HERE/$api_key/" $config_file - printf "请输入应用程序 api_hash:" - read -r api_hash <&1 - sed -i "s/HASH_HERE/$api_hash/" $config_file - printf "请输入应用程序语言(默认:zh-cn):" - read -r application_language <&1 - if [ -z "$application_language" ] - then - echo "语言设置为 简体中文" - else - sed -i "s/zh-cn/$application_language/" $config_file - fi - printf "请输入应用程序地区(默认:China):" - read -r application_region <&1 - if [ -z "$application_region" ] - then - echo "地区设置为 中国" - else - sed -i "s/China/$application_region/" $config_file - fi - printf "请输入 Google TTS 语言(默认:zh-CN):" - read -r application_tts <&1 - if [ -z "$application_tts" ] - then - echo "tts发音语言设置为 简体中文" - else - sed -i "s/zh-CN/$application_tts/" $config_file - fi - printf "启用日志记录? [Y/n]" - read -r logging_confirmation <&1 - case $logging_confirmation in - [yY][eE][sS]|[yY]) - printf "请输入您的日志记录群组/频道的 ChatID (如果要发送给 原 PagerMaid 作者 ,请按Enter):" - read -r log_chatid <&1 - if [ -z "$log_chatid" ] - then - echo "LOG 将发送到 原 PagerMaid 作者." - else - sed -i "s/503691334/$log_chatid/" $config_file - fi - sed -i "s/log: False/log: True/" $config_file - ;; - [nN][oO]|[nN]) - echo "安装过程继续 . . ." - ;; - *) - echo "输入错误 . . ." - exit 1 - ;; - esac -} - -login() { - echo "" - echo "下面进行程序运行。" - echo "请在账户授权完毕后,按 Ctrl + C 使 Docker 在后台模式下运行。" - echo "" - sleep 2 - echo "Hello world!" > /pagermaid/workdir/install.lock - python -m pagermaid - exit -} - - -start_installation() { - if [ ! -f "/pagermaid/workdir/install.lock" ]; then - welcome - configure - login - else - if [ ! -f "/pagermaid/workdir/pagermaid.session" ]; then - login - else - redis-server --daemonize yes - python -m pagermaid - fi - fi -} - -start_installation diff --git a/utils/docker.sh b/utils/docker.sh index 1b3ab9a..982e1b5 100644 --- a/utils/docker.sh +++ b/utils/docker.sh @@ -1,4 +1,5 @@ -#!/bin/bash +#!/usr/bin/env bash + if [[ $EUID -ne 0 ]] then clear @@ -7,168 +8,164 @@ then fi welcome() { - echo "" - echo "安装即将开始" - echo "如果您想取消安装," - echo "请在 5 秒钟内按 Ctrl+C 终止此脚本。" - echo "" - sleep 5 + echo + echo "安装即将开始" + echo "如果您想取消安装," + echo "请在 5 秒钟内按 Ctrl+C 终止此脚本。" + echo + sleep 5 } -docker_check() { - echo "正在检查 Docker 安装情况 . . ." - if command -v docker >> /dev/null 2>&1; - then - echo "Docker 似乎存在, 安装过程继续 . . ." - else - echo "Docker 未安装在此系统上" - echo "请安装 Docker 并将自己添加到 Docker" - echo "分组并重新运行此脚本。" - exit 1 - fi -} - -git_check() { - echo "正在检查 Git 安装情况 . . ." - if command -v git >> /dev/null 2>&1; - then - echo "Git 似乎存在, 安装过程继续 . . ." - else - echo "Git 未安装在此系统上!" - echo "请安装 Git 并重新运行此脚本。" - exit 1 - fi +docker_check () { + echo "正在检查 Docker 安装情况 . . ." + if command -v docker >> /dev/null 2>&1; + then + echo "Docker 似乎存在, 安装过程继续 . . ." + else + echo "Docker 未安装在此系统上" + echo "请安装 Docker 并将自己添加到 Docker" + echo "分组并重新运行此脚本。" + exit 1 + fi } access_check() { - echo "测试 Docker 环境 . . ." - if [ -w /var/run/docker.sock ] - then - echo "该用户可以使用 Docker , 安装过程继续 . . ." - else - echo "该用户无权访问 Docker,或者 Docker 没有运行。 请添加自己到 Docker 分组并重新运行此脚本。" - exit 1 - fi + echo "测试 Docker 环境 . . ." + if [ -w /var/run/docker.sock ] + then + echo "该用户可以使用 Docker , 安装过程继续 . . ." + else + echo "该用户无权访问 Docker,或者 Docker 没有运行。 请添加自己到 Docker 分组并重新运行此脚本。" + exit 1 + fi } build_docker() { - printf "请输入 PagerMaid 容器的名称:" - read -r container_name <&1 - echo "正在拉取 Docker 镜像 . . ." - docker rm -f "$container_name" > /dev/null 2>&1 - docker pull mrwangzhe/pagermaid_modify + 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() { - echo "正在启动 Docker 容器 . . ." - echo "在登录后,请按 Ctrl + C 使容器在后台模式下重新启动。" - sleep 3 - docker run -it --restart=always --name="$container_name" --hostname="$container_name" mrwangzhe/pagermaid_modify <&1 - echo "" - echo "Docker 创建完毕。" - echo "" - shon_online + echo "正在启动 Docker 容器 . . ." + docker run -dit -e PUID=$PUID -e PGID=$PGID --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 + echo + echo "Docker 创建完毕。" + echo + shon_online } start_installation() { - welcome - docker_check - git_check - access_check - build_docker - start_docker + welcome + docker_check + access_check + build_docker + start_docker } cleanup(){ - printf "请输入 PagerMaid 容器的名称:" - read -r container_name <&1 - echo "正在删除 Docker 镜像 . . ." - docker rm -f "$container_name" > /dev/null 2>&1 - echo "" - shon_online + 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 "$container_name" > /dev/null 2>&1 - echo "" - shon_online + printf "请输入 PagerMaid 容器的名称:" + read -r container_name <&1 + echo "正在关闭 Docker 镜像 . . ." + docker stop "$container_name" > /dev/null 2>&1 + echo "" + shon_online } 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 + printf "请输入 PagerMaid 容器的名称:" + read -r container_name <&1 + echo "正在启动 Docker 容器 . . ." + docker start $container_name > /dev/null 2>&1 + echo "" + echo "Docker 启动完毕。" + echo "" + shon_online } 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 + printf "请输入 PagerMaid 容器的名称:" + read -r container_name <&1 + echo "正在重新启动 Docker 容器 . . ." + docker restart $container_name > /dev/null 2>&1 + echo "" + echo "Docker 重新启动完毕。" + echo "" + shon_online } reinstall_pager(){ - build_docker - start_docker + 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) 重新安装 PagerMaid" -echo " 7) 退出脚本" -echo "" -echo " Version:0.2.0" -echo "" -echo -n "请输入编号: " -read N -case $N in - 1) - start_installation - ;; - 2) - cleanup - ;; - 3) - stop_pager - ;; - 4) - start_pager - ;; - 5) - restart_pager - ;; - 6) - reinstall_pager - ;; - 7) - exit - ;; - *) - echo "Wrong input!" - sleep 5s - shon_online - ;; -esac + 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 + echo " Version:0.3.0" + echo + echo -n "请输入编号: " + read N + case $N in + 1) + start_installation + ;; + 2) + cleanup + ;; + 3) + stop_pager + ;; + 4) + start_pager + ;; + 5) + restart_pager + ;; + 6) + reinstall_pager + ;; + 7) + exit 0 + ;; + *) + echo "Wrong input!" + sleep 5s + shon_online + ;; + esac } shon_online diff --git a/utils/entrypoint.sh b/utils/entrypoint.sh deleted file mode 100644 index a784843..0000000 --- a/utils/entrypoint.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -redis-server --daemonize yes -. /pagermaid/venv/bin/activate -/usr/bin/env python3 -m pagermaid