Fix various bugs in fresh installation (#302)

This commit is contained in:
Applexad 2023-11-30 10:49:06 +08:00 committed by GitHub
parent c3d1eec6bf
commit 1871c481e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 100 additions and 12 deletions

View File

@ -168,7 +168,7 @@ install_dashboard() {
echo -e "> 安装面板" echo -e "> 安装面板"
# 哪吒监控文件夹 # 哪吒监控文件夹
if [ ! -d "${NZ_DASHBOARD_PATH}" ]; then if [ ! -d "${NZ_DASHBOARD_PATH}/docker-compose.yaml" ]; then
mkdir -p $NZ_DASHBOARD_PATH mkdir -p $NZ_DASHBOARD_PATH
else else
echo "您可能已经安装过面板端,重复安装会覆盖数据,请注意备份。" echo "您可能已经安装过面板端,重复安装会覆盖数据,请注意备份。"
@ -216,7 +216,7 @@ install_dashboard_standalone() {
echo -e "> 安装面板" echo -e "> 安装面板"
# 哪吒监控文件夹 # 哪吒监控文件夹
if [ ! -d "${NZ_DASHBOARD_PATH}" ]; then if [ ! -d "${NZ_DASHBOARD_PATH}/app" ]; then
mkdir -p $NZ_DASHBOARD_PATH mkdir -p $NZ_DASHBOARD_PATH
else else
echo "您可能已经安装过面板端,重复安装会覆盖数据,请注意备份。" echo "您可能已经安装过面板端,重复安装会覆盖数据,请注意备份。"
@ -800,13 +800,31 @@ clean_all() {
} }
select_version() { select_version() {
cd $NZ_DASHBOARD_PATH
if command -v docker compose >/dev/null 2>&1; then if command -v docker compose >/dev/null 2>&1; then
if docker compose ls | grep -qw "$NZ_DASHBOARD_PATH/docker-compose.yaml" >/dev/null 2>&1; then if docker compose ls | grep -qw "$NZ_DASHBOARD_PATH/docker-compose.yaml" >/dev/null 2>&1; then
IS_DOCKER_NEZHA=1 IS_DOCKER_NEZHA=1
fi fi
elif [ -d /opt/nezha/dashboard ]; then fi
if [[ -f $NZ_DASHBOARD_PATH/app ]]; then
IS_DOCKER_NEZHA=0 IS_DOCKER_NEZHA=0
else
echo -e "${yellow}请自行选择您的安装方式如果你是安装Agent输入哪个都是一样的\n1. Docker\n2. 独立安装${plain}"
while true; do
read -e -r -p "请输入数字 [1-2]" option
case "${option}" in
1)
IS_DOCKER_NEZHA=1
break
;;
2)
IS_DOCKER_NEZHA=0
break
;;
*)
echo "输入有误,请重新输入"
;;
esac
done
fi fi
} }
@ -950,6 +968,8 @@ show_menu() {
echo -e "${red}请输入正确的数字 [0-13]${plain}" echo -e "${red}请输入正确的数字 [0-13]${plain}"
;; ;;
esac esac
else
select_version
fi fi
} }
@ -1053,7 +1073,32 @@ if [[ $# > 0 ]]; then
*) show_usage ;; *) show_usage ;;
esac esac
else else
echo "未检测到 IS_DOCKER_NEZHA 环境变量,请尝试在 Bash 环境下重新执行脚本,或者不带参数执行。" case $1 in
"install_agent")
shift
if [ $# -ge 3 ]; then
install_agent "$@"
else
install_agent 0
fi
;;
"modify_agent_config")
modify_agent_config 0
;;
"show_agent_log")
show_agent_log 0
;;
"uninstall_agent")
uninstall_agent 0
;;
"restart_agent")
restart_agent 0
;;
"update_script")
update_script 0
;;
*) show_usage ;;
esac
fi fi
else else
select_version select_version

View File

@ -77,7 +77,7 @@ pre_check() {
else else
GITHUB_RAW_URL="jihulab.com/nezha/dashboard/-/raw/master" GITHUB_RAW_URL="jihulab.com/nezha/dashboard/-/raw/master"
GITHUB_URL="dn-dao-github-mirror.daocloud.io" GITHUB_URL="dn-dao-github-mirror.daocloud.io"
Get_Docker_URL="get.daocloud.io/docker" Get_Docker_URL="get.docker.com"
Get_Docker_Argu=" -s docker --mirror Aliyun" Get_Docker_Argu=" -s docker --mirror Aliyun"
Docker_IMG="registry.cn-shanghai.aliyuncs.com\/naibahq\/nezha-dashboard" Docker_IMG="registry.cn-shanghai.aliyuncs.com\/naibahq\/nezha-dashboard"
GITHUB_RELEASE_URL="hub.fgit.cf/naiba/nezha/releases/latest/download" GITHUB_RELEASE_URL="hub.fgit.cf/naiba/nezha/releases/latest/download"
@ -167,7 +167,7 @@ install_dashboard() {
echo -e "> Install Panel" echo -e "> Install Panel"
# Nezha Monitoring Folder # Nezha Monitoring Folder
if [ ! -d "${NZ_DASHBOARD_PATH}" ]; then if [ ! -d "${NZ_DASHBOARD_PATH}/docker-compose.yaml" ]; then
mkdir -p $NZ_DASHBOARD_PATH mkdir -p $NZ_DASHBOARD_PATH
else else
echo "You may have already installed the dashboard, repeated installation will overwrite the data, please pay attention to backup." echo "You may have already installed the dashboard, repeated installation will overwrite the data, please pay attention to backup."
@ -214,7 +214,7 @@ install_dashboard_standalone() {
echo -e "> Install Panel" echo -e "> Install Panel"
# Nezha Monitoring Folder # Nezha Monitoring Folder
if [ ! -d "${NZ_DASHBOARD_PATH}" ]; then if [ ! -d "${NZ_DASHBOARD_PATH}/app" ]; then
mkdir -p $NZ_DASHBOARD_PATH mkdir -p $NZ_DASHBOARD_PATH
else else
echo "You may have already installed the dashboard, repeated installation will overwrite the data, please pay attention to backup." echo "You may have already installed the dashboard, repeated installation will overwrite the data, please pay attention to backup."
@ -798,13 +798,31 @@ clean_all() {
} }
select_version() { select_version() {
cd $NZ_DASHBOARD_PATH
if command -v docker compose >/dev/null 2>&1; then if command -v docker compose >/dev/null 2>&1; then
if docker compose ls | grep -qw "$NZ_DASHBOARD_PATH/docker-compose.yaml" >/dev/null 2>&1; then if docker compose ls | grep -qw "$NZ_DASHBOARD_PATH/docker-compose.yaml" >/dev/null 2>&1; then
IS_DOCKER_NEZHA=1 IS_DOCKER_NEZHA=1
fi fi
elif [ -d /opt/nezha/dashboard ]; then fi
if [[ -f $NZ_DASHBOARD_PATH/app ]]; then
IS_DOCKER_NEZHA=0 IS_DOCKER_NEZHA=0
else
echo -e "${yellow}Select your installation method(Input anything is ok if you are installing agent):\n1. Docker\n2. Standalone${plain}"
while true; do
read -e -r -p "Input a number [1-2]: " option
case "${option}" in
1)
IS_DOCKER_NEZHA=1
break
;;
2)
IS_DOCKER_NEZHA=0
break
;;
*)
echo "Wrong input, try again"
;;
esac
done
fi fi
} }
@ -1051,7 +1069,32 @@ if [[ $# > 0 ]]; then
*) show_usage ;; *) show_usage ;;
esac esac
else else
echo "Environment variable IS_DOCKER_NEZHA is not detected, Try run the script again in Bash or without arguments." case $1 in
"install_agent")
shift
if [ $# -ge 3 ]; then
install_agent "$@"
else
install_agent 0
fi
;;
"modify_agent_config")
modify_agent_config 0
;;
"show_agent_log")
show_agent_log 0
;;
"uninstall_agent")
uninstall_agent 0
;;
"restart_agent")
restart_agent 0
;;
"update_script")
update_script 0
;;
*) show_usage ;;
esac
fi fi
else else
select_version select_version