☀️ 尝试支持 Docker 构建

This commit is contained in:
xtaodada 2020-08-10 23:53:59 +08:00
parent f797eacbad
commit c0808fbc88
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
4 changed files with 73 additions and 68 deletions

View File

@ -39,4 +39,4 @@ WORKDIR /pagermaid/workdir
RUN python3 -m virtualenv venv RUN python3 -m virtualenv venv
RUN source venv/bin/activate; pip3 install -r requirements.txt RUN source venv/bin/activate; pip3 install -r requirements.txt
CMD ["sh","utils/docker-run.sh"] CMD ["sh","utils/docker-run.sh"]
CMD ["sh","utils/entrypoint.sh"]

View File

@ -1,13 +1,11 @@
#!/bin/sh #!/bin/bash
welcome() { welcome() {
echo "" echo ""
echo "欢迎使用 PagerMaid-Modify Docker 安装程序。" echo "欢迎进入 PagerMaid-Modify Docker 。"
echo "安装即将开始" echo "配置即将开始"
echo "在5秒钟内如果您想取消"
echo "请在5秒钟内终止此脚本。"
echo "" echo ""
sleep 5 sleep 2
} }
configure() { configure() {
@ -54,9 +52,47 @@ configure() {
esac esac
} }
login() {
echo ""
echo "下面进行程序试运行。"
echo "请在账户授权完毕后按 Ctrl + C 退出"
echo ""
sleep 2
/pagermaid/workdir/venv/bin/python -m pagermaid
echo ""
echo "程序试运行完毕。"
echo ""
}
systemctl_reload(){
echo "正在写入系统进程守护 . . ."
sudo -i
echo "[Unit]
Description=PagerMaid-Modify telegram utility daemon
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
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
su pagermaid
echo ""
echo "请在脚本退出后输入 exit 退出 Docker"
echo ""
exit
}
start_installation() { start_installation() {
welcome welcome
configure configure
login
systemctl_reload
} }
start_installation start_installation

View File

@ -1,18 +1,25 @@
#!/bin/sh #!/bin/bash
if [[ $EUID -ne 0 ]]; then
clear
echo "错误:本脚本需要 root 权限执行。" 1>&2
exit 1
fi
welcome() { welcome() {
echo "" echo ""
echo "欢迎使用 PagerMaid-Modify Docker 安装程序。" echo "欢迎使用 PagerMaid-Modify 一键安装程序。"
echo "安装即将开始" echo "安装即将开始"
echo "在5秒钟内如果您想取消" echo "如果您想取消安装"
echo "请在5秒钟内终止此脚本。" echo "请在 5 秒钟内按 Ctrl+C 终止此脚本。"
echo "" echo ""
sleep 5 sleep 5
} }
docker_check() { docker_check() {
echo "正在检查 Docker 安装情况 . . ." echo "正在检查 Docker 安装情况 . . ."
if command -v docker; if command -v docker >> /dev/null 2>&1;
then then
echo "Docker 似乎存在, 安装过程继续 . . ." echo "Docker 似乎存在, 安装过程继续 . . ."
else else
@ -25,7 +32,7 @@ docker_check() {
git_check() { git_check() {
echo "正在检查 Git 安装情况 . . ." echo "正在检查 Git 安装情况 . . ."
if command -v git; if command -v git >> /dev/null 2>&1;
then then
echo "Git 似乎存在, 安装过程继续 . . ." echo "Git 似乎存在, 安装过程继续 . . ."
else else
@ -41,63 +48,11 @@ access_check() {
then then
echo "该用户可以使用 Docker , 安装过程继续 . . ." echo "该用户可以使用 Docker , 安装过程继续 . . ."
else else
echo "该用户无权访问 Docker或者 Docker" echo "该用户无权访问 Docker或者 Docker 没有运行。 请添加自己到 Docker 分组并重新运行此脚本。"
echo "没有运行。 请添加自己到 Docker"
echo "分组并重新运行此脚本。"
exit 1 exit 1
fi fi
} }
download_repo() {
echo "下载 repository 中. . ."
rm -rf /tmp/pagermaid
git clone https://github.com/xtaodada/PagerMaid-Modify.git /tmp/pagermaid
cd /tmp/pagermaid || exit
}
configure() {
config_file=config.yml
echo "生成配置文件中 . . ."
cp config.gen.yml config.yml
printf "请输入应用程序 api_key"
read -r api_key <&1
sed -i "s/KEY_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
sed -i "s/zh-cn/$application_language/" $config_file
printf "请输入应用程序地区例如China"
read -r application_region <&1
sed -i "s/China/$application_region/" $config_file
printf "请输入 Google TTS 后缀例如cn"
read -r application_tts <&1
sed -i "s/cn/$application_tts/" $config_file
printf "启用日志记录? [Y/n]"
read -r logging_confirmation <&1
case $logging_confirmation in
[yY][eE][sS]|[yY])
printf "请输入您的日志记录群组/频道的 ChatID (如果要发送给 Kat 请按Enter"
read -r log_chatid <&1
if [ -z "$log_chatid" ]
then
echo "LOG 将发送到 Kat."
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
}
build_docker() { build_docker() {
printf "请输入 PagerMaid 容器的名称:" printf "请输入 PagerMaid 容器的名称:"
read -r container_name <&1 read -r container_name <&1
@ -111,6 +66,7 @@ start_docker() {
echo "在登录后,请按 Ctrl + C 使容器在后台模式下重新启动。" echo "在登录后,请按 Ctrl + C 使容器在后台模式下重新启动。"
sleep 3 sleep 3
docker run -it --restart=always --name="$container_name" --hostname="$container_name" pagermaid_"$container_name" <&1 docker run -it --restart=always --name="$container_name" --hostname="$container_name" pagermaid_"$container_name" <&1
docker restart $container_name > /dev/null 2>&1
} }
cleanup() { cleanup() {
@ -119,12 +75,11 @@ cleanup() {
} }
start_installation() { start_installation() {
check_sys
welcome welcome
docker_check docker_check
git_check git_check
access_check access_check
download_repo
configure
build_docker build_docker
start_docker start_docker
cleanup cleanup

View File

@ -0,0 +1,14 @@
[Unit]
Description=PagerMaid-Modify telegram utility daemon
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=pagermaid
Group=pagermaid
WorkingDirectory=/pagermaid/workdir
ExecStart=/pagermaid/workdir/venv/bin/python -m pagermaid
Restart=always