2020-08-10 15:53:59 +00:00
|
|
|
|
#!/bin/bash
|
2020-08-11 02:51:45 +00:00
|
|
|
|
if [[ $EUID -ne 0 ]]
|
|
|
|
|
then
|
2020-08-10 15:53:59 +00:00
|
|
|
|
clear
|
|
|
|
|
echo "错误:本脚本需要 root 权限执行。" 1>&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2020-02-19 15:31:39 +00:00
|
|
|
|
welcome() {
|
|
|
|
|
echo ""
|
2020-04-01 13:58:06 +00:00
|
|
|
|
echo "安装即将开始"
|
2020-08-10 15:53:59 +00:00
|
|
|
|
echo "如果您想取消安装,"
|
|
|
|
|
echo "请在 5 秒钟内按 Ctrl+C 终止此脚本。"
|
2020-02-19 15:31:39 +00:00
|
|
|
|
echo ""
|
|
|
|
|
sleep 5
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
docker_check() {
|
2020-04-01 13:58:06 +00:00
|
|
|
|
echo "正在检查 Docker 安装情况 . . ."
|
2020-08-10 15:53:59 +00:00
|
|
|
|
if command -v docker >> /dev/null 2>&1;
|
2020-02-19 15:31:39 +00:00
|
|
|
|
then
|
2020-04-01 13:58:06 +00:00
|
|
|
|
echo "Docker 似乎存在, 安装过程继续 . . ."
|
2020-02-19 15:31:39 +00:00
|
|
|
|
else
|
2020-04-01 13:58:06 +00:00
|
|
|
|
echo "Docker 未安装在此系统上"
|
|
|
|
|
echo "请安装 Docker 并将自己添加到 Docker"
|
|
|
|
|
echo "分组并重新运行此脚本。"
|
2020-02-19 15:31:39 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
git_check() {
|
2020-04-01 13:58:06 +00:00
|
|
|
|
echo "正在检查 Git 安装情况 . . ."
|
2020-08-10 15:53:59 +00:00
|
|
|
|
if command -v git >> /dev/null 2>&1;
|
2020-02-19 15:31:39 +00:00
|
|
|
|
then
|
2020-04-01 13:58:06 +00:00
|
|
|
|
echo "Git 似乎存在, 安装过程继续 . . ."
|
2020-02-19 15:31:39 +00:00
|
|
|
|
else
|
2020-08-11 02:51:45 +00:00
|
|
|
|
echo "Git 未安装在此系统上!"
|
2020-04-01 13:58:06 +00:00
|
|
|
|
echo "请安装 Git 并重新运行此脚本。"
|
2020-02-19 15:31:39 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
access_check() {
|
2020-04-01 13:58:06 +00:00
|
|
|
|
echo "测试 Docker 环境 . . ."
|
2020-02-19 15:31:39 +00:00
|
|
|
|
if [ -w /var/run/docker.sock ]
|
|
|
|
|
then
|
2020-04-01 13:58:06 +00:00
|
|
|
|
echo "该用户可以使用 Docker , 安装过程继续 . . ."
|
2020-02-19 15:31:39 +00:00
|
|
|
|
else
|
2020-08-10 15:53:59 +00:00
|
|
|
|
echo "该用户无权访问 Docker,或者 Docker 没有运行。 请添加自己到 Docker 分组并重新运行此脚本。"
|
2020-02-19 15:31:39 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
build_docker() {
|
2020-04-01 13:58:06 +00:00
|
|
|
|
printf "请输入 PagerMaid 容器的名称:"
|
2020-02-19 15:31:39 +00:00
|
|
|
|
read -r container_name <&1
|
2020-08-10 18:10:33 +00:00
|
|
|
|
echo "正在拉取 Docker 镜像 . . ."
|
2020-02-19 15:31:39 +00:00
|
|
|
|
docker rm -f "$container_name" > /dev/null 2>&1
|
2020-08-11 02:51:45 +00:00
|
|
|
|
docker pull mrwangzhe/pagermaid_modify
|
2020-02-19 15:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
start_docker() {
|
2020-04-01 13:58:06 +00:00
|
|
|
|
echo "正在启动 Docker 容器 . . ."
|
|
|
|
|
echo "在登录后,请按 Ctrl + C 使容器在后台模式下重新启动。"
|
2020-02-19 15:31:39 +00:00
|
|
|
|
sleep 3
|
2020-08-11 02:51:45 +00:00
|
|
|
|
docker run -it --restart=always --name="$container_name" --hostname="$container_name" mrwangzhe/pagermaid_modify <&1
|
2020-08-10 16:48:18 +00:00
|
|
|
|
echo ""
|
|
|
|
|
echo "Docker 创建完毕。"
|
|
|
|
|
echo ""
|
|
|
|
|
shon_online
|
2020-02-19 15:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
start_installation() {
|
|
|
|
|
welcome
|
|
|
|
|
docker_check
|
|
|
|
|
git_check
|
|
|
|
|
access_check
|
|
|
|
|
build_docker
|
|
|
|
|
start_docker
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 16:48:18 +00:00
|
|
|
|
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 镜像 . . ."
|
2020-08-10 17:31:52 +00:00
|
|
|
|
docker stop "$container_name" > /dev/null 2>&1
|
2020-08-10 16:48:18 +00:00
|
|
|
|
echo ""
|
|
|
|
|
shon_online
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
start_pager(){
|
|
|
|
|
printf "请输入 PagerMaid 容器的名称:"
|
|
|
|
|
read -r container_name <&1
|
|
|
|
|
echo "正在启动 Docker 容器 . . ."
|
2020-08-11 02:51:45 +00:00
|
|
|
|
docker start $container_name > /dev/null 2>&1
|
|
|
|
|
docker exec -it $container_name chmod -R 777 /pagermaid/workdir > /dev/null 2>&1
|
2020-08-10 17:31:52 +00:00
|
|
|
|
docker exec -dt $container_name /pagermaid/workdir/venv/bin/python -m pagermaid > /dev/null 2>&1
|
2020-08-10 16:48:18 +00:00
|
|
|
|
echo ""
|
|
|
|
|
echo "Docker 启动完毕。"
|
|
|
|
|
echo ""
|
|
|
|
|
shon_online
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 17:07:04 +00:00
|
|
|
|
restart_pager(){
|
|
|
|
|
printf "请输入 PagerMaid 容器的名称:"
|
|
|
|
|
read -r container_name <&1
|
|
|
|
|
echo "正在重新启动 Docker 容器 . . ."
|
|
|
|
|
docker restart $container_name > /dev/null 2>&1
|
2020-08-11 02:51:45 +00:00
|
|
|
|
docker exec -dt pagermaid /pagermaid/workdir/venv/bin/python -m pagermaid > /dev/null 2>&1
|
2020-08-10 17:07:04 +00:00
|
|
|
|
echo ""
|
|
|
|
|
echo "Docker 重新启动完毕。"
|
|
|
|
|
echo ""
|
|
|
|
|
shon_online
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 16:48:18 +00:00
|
|
|
|
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"
|
2020-08-10 17:07:04 +00:00
|
|
|
|
echo " 5) 重新启动 PagerMaid"
|
|
|
|
|
echo " 6) 重新安装 PagerMaid"
|
|
|
|
|
echo " 7) 退出脚本"
|
2020-08-10 16:48:18 +00:00
|
|
|
|
echo ""
|
|
|
|
|
echo " Version:0.1.0"
|
|
|
|
|
echo ""
|
|
|
|
|
echo -n "请输入编号: "
|
|
|
|
|
read N
|
|
|
|
|
case $N in
|
2020-08-11 02:51:45 +00:00
|
|
|
|
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
|
|
|
|
|
;;
|
2020-08-10 16:48:18 +00:00
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shon_online
|