2021-05-01 16:48:32 +00:00
|
|
|
|
#!/usr/bin/env 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
|
|
|
|
|
|
2022-03-05 11:06:43 +00:00
|
|
|
|
a=$(curl --noproxy '*' -sSL https://api.myip.com/)
|
|
|
|
|
b="China"
|
|
|
|
|
if [[ $a == *$b* ]]
|
|
|
|
|
then
|
|
|
|
|
echo "错误:本脚本不支持境内服务器使用。" 1>&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2021-05-07 15:18:06 +00:00
|
|
|
|
welcome () {
|
2021-05-01 16:48:32 +00:00
|
|
|
|
echo
|
|
|
|
|
echo "安装即将开始"
|
|
|
|
|
echo "如果您想取消安装,"
|
|
|
|
|
echo "请在 5 秒钟内按 Ctrl+C 终止此脚本。"
|
|
|
|
|
echo
|
|
|
|
|
sleep 5
|
2020-02-19 15:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-01 16:48:32 +00:00
|
|
|
|
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
|
2020-02-19 15:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 15:18:06 +00:00
|
|
|
|
access_check () {
|
2021-05-01 16:48:32 +00:00
|
|
|
|
echo "测试 Docker 环境 . . ."
|
|
|
|
|
if [ -w /var/run/docker.sock ]
|
|
|
|
|
then
|
|
|
|
|
echo "该用户可以使用 Docker , 安装过程继续 . . ."
|
|
|
|
|
else
|
|
|
|
|
echo "该用户无权访问 Docker,或者 Docker 没有运行。 请添加自己到 Docker 分组并重新运行此脚本。"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2020-02-19 15:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 15:18:06 +00:00
|
|
|
|
build_docker () {
|
2021-05-01 16:48:32 +00:00
|
|
|
|
printf "请输入 PagerMaid 容器的名称:"
|
|
|
|
|
read -r container_name <&1
|
|
|
|
|
echo "正在拉取 Docker 镜像 . . ."
|
|
|
|
|
docker rm -f "$container_name" > /dev/null 2>&1
|
|
|
|
|
docker pull mrwangzhe/pagermaid_modify
|
2020-02-19 15:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 15:18:06 +00:00
|
|
|
|
start_docker () {
|
2021-05-01 16:48:32 +00:00
|
|
|
|
echo "正在启动 Docker 容器 . . ."
|
2021-05-07 15:18:06 +00:00
|
|
|
|
docker run -dit --restart=always --name="$container_name" --hostname="$container_name" mrwangzhe/pagermaid_modify <&1
|
2021-05-01 16:48:32 +00:00
|
|
|
|
echo
|
|
|
|
|
echo "开始配置参数 . . ."
|
|
|
|
|
echo "在登录后,请按 Ctrl + C 使容器在后台模式下重新启动。"
|
|
|
|
|
sleep 3
|
2021-05-07 15:18:06 +00:00
|
|
|
|
docker exec -it $container_name bash utils/docker-config.sh
|
2021-05-01 16:48:32 +00:00
|
|
|
|
echo
|
|
|
|
|
echo "Docker 创建完毕。"
|
|
|
|
|
echo
|
2020-02-19 15:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 15:18:06 +00:00
|
|
|
|
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 () {
|
2021-05-01 16:48:32 +00:00
|
|
|
|
welcome
|
|
|
|
|
docker_check
|
|
|
|
|
access_check
|
|
|
|
|
build_docker
|
|
|
|
|
start_docker
|
2021-05-07 15:18:06 +00:00
|
|
|
|
data_persistence
|
2020-02-19 15:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 15:18:06 +00:00
|
|
|
|
cleanup () {
|
2021-05-01 16:48:32 +00:00
|
|
|
|
printf "请输入 PagerMaid 容器的名称:"
|
|
|
|
|
read -r container_name <&1
|
2021-05-07 15:18:06 +00:00
|
|
|
|
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
|
2020-08-10 16:48:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 15:18:06 +00:00
|
|
|
|
stop_pager () {
|
2021-05-01 16:48:32 +00:00
|
|
|
|
printf "请输入 PagerMaid 容器的名称:"
|
|
|
|
|
read -r container_name <&1
|
|
|
|
|
echo "正在关闭 Docker 镜像 . . ."
|
2021-05-07 15:18:06 +00:00
|
|
|
|
if docker inspect $container_name &>/dev/null; then
|
|
|
|
|
docker stop "$container_name" &>/dev/null
|
|
|
|
|
echo
|
|
|
|
|
shon_online
|
|
|
|
|
else
|
|
|
|
|
echo "不存在名为 $container_name 的容器,退出。"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2020-08-10 16:48:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 15:18:06 +00:00
|
|
|
|
start_pager () {
|
2021-05-01 16:48:32 +00:00
|
|
|
|
printf "请输入 PagerMaid 容器的名称:"
|
|
|
|
|
read -r container_name <&1
|
|
|
|
|
echo "正在启动 Docker 容器 . . ."
|
2021-05-07 15:18:06 +00:00
|
|
|
|
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
|
2020-08-10 16:48:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 15:18:06 +00:00
|
|
|
|
restart_pager () {
|
2021-05-01 16:48:32 +00:00
|
|
|
|
printf "请输入 PagerMaid 容器的名称:"
|
|
|
|
|
read -r container_name <&1
|
|
|
|
|
echo "正在重新启动 Docker 容器 . . ."
|
2021-05-07 15:18:06 +00:00
|
|
|
|
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
|
2020-08-10 17:07:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 15:18:06 +00:00
|
|
|
|
reinstall_pager () {
|
|
|
|
|
cleanup
|
2021-05-01 16:48:32 +00:00
|
|
|
|
build_docker
|
|
|
|
|
start_docker
|
2021-05-07 15:18:06 +00:00
|
|
|
|
data_persistence
|
2020-08-10 16:48:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 15:18:06 +00:00
|
|
|
|
shon_online () {
|
2021-05-01 16:48:32 +00:00
|
|
|
|
echo
|
|
|
|
|
echo "欢迎使用 PagerMaid-Modify Docker 一键安装脚本。"
|
|
|
|
|
echo
|
|
|
|
|
echo "请选择您需要进行的操作:"
|
|
|
|
|
echo " 1) Docker 安装 PagerMaid"
|
|
|
|
|
echo " 2) Docker 卸载 PagerMaid"
|
2021-05-07 15:18:06 +00:00
|
|
|
|
echo " 3) Docker 关闭 PagerMaid"
|
|
|
|
|
echo " 4) Docker 启动 PagerMaid"
|
|
|
|
|
echo " 5) Docker 重启 PagerMaid"
|
|
|
|
|
echo " 6) Docker 重装 PagerMaid"
|
|
|
|
|
echo " 7) 将 PagerMaid 数据持久化"
|
|
|
|
|
echo " 8) 退出脚本"
|
2021-05-01 16:48:32 +00:00
|
|
|
|
echo
|
2021-05-07 15:18:06 +00:00
|
|
|
|
echo " Version:0.3.1"
|
2021-05-01 16:48:32 +00:00
|
|
|
|
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)
|
2021-05-07 15:18:06 +00:00
|
|
|
|
data_persistence
|
|
|
|
|
;;
|
|
|
|
|
8)
|
2021-05-01 16:48:32 +00:00
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "Wrong input!"
|
|
|
|
|
sleep 5s
|
|
|
|
|
shon_online
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2020-08-10 16:48:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shon_online
|