update template
This commit is contained in:
150
template.sh
150
template.sh
@ -144,7 +144,7 @@ installation_check() {
|
||||
if docker compose version >/dev/null 2>&1; then
|
||||
DOCKER_COMPOSE_COMMAND="docker compose"
|
||||
if sudo $DOCKER_COMPOSE_COMMAND ls | grep -qw "$NZ_DASHBOARD_PATH/docker-compose.yaml" >/dev/null 2>&1; then
|
||||
NEZHA_IMAGES=$(sudo docker images --format "{{.Repository}}:{{.Tag}}" | grep -w "nezha-dashboard")
|
||||
NEZHA_IMAGES=$(sudo docker images --format "{{"{{.Repository}}"}}:{{"{{.Tag}}"}}" | grep -w "nezha-dashboard")
|
||||
if [ -n "$NEZHA_IMAGES" ]; then
|
||||
echo "{{.DockerImageFound}}"
|
||||
echo "$NEZHA_IMAGES"
|
||||
@ -158,7 +158,7 @@ installation_check() {
|
||||
elif command -v docker-compose >/dev/null 2>&1; then
|
||||
DOCKER_COMPOSE_COMMAND="docker-compose"
|
||||
if sudo $DOCKER_COMPOSE_COMMAND -f "$NZ_DASHBOARD_PATH/docker-compose.yaml" config >/dev/null 2>&1; then
|
||||
NEZHA_IMAGES=$(sudo docker images --format "{{.Repository}}:{{.Tag}}" | grep -w "nezha-dashboard")
|
||||
NEZHA_IMAGES=$(sudo docker images --format "{{"{{.Repository}}"}}:{{"{{.Tag}}"}}" | grep -w "nezha-dashboard")
|
||||
if [ -n "$NEZHA_IMAGES" ]; then
|
||||
echo "{{.DockerImageFound}}"
|
||||
echo "$NEZHA_IMAGES"
|
||||
@ -211,7 +211,7 @@ update_script() {
|
||||
echo "{{.ErrorFetchScript}} https://${GITHUB_RAW_URL}/script/install.sh"
|
||||
return 1
|
||||
fi
|
||||
echo "{{.UpdateScriptInfo}} ${new_version}"
|
||||
echo "{{.CurrentVersionInfo}} ${new_version}"
|
||||
mv -f /tmp/nezha.sh ./nezha.sh && chmod a+x ./nezha.sh
|
||||
|
||||
echo "{{.ExecuteScriptInfo}}"
|
||||
@ -232,8 +232,8 @@ install_base() {
|
||||
}
|
||||
|
||||
install_arch() {
|
||||
info "Archlinux needs to add nezha-agent user to install libselinux. It will be deleted automatically after installation. It is recommended to check manually"
|
||||
read -r -p "Do you need to install libselinux? [Y/n] " input
|
||||
info "{{.InstallArchPrompt1}}"
|
||||
read -r -p "{{.InstallArchPrompt2}}" input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
useradd -m nezha-agent
|
||||
@ -243,13 +243,13 @@ install_arch() {
|
||||
git clone https://aur.archlinux.org/libselinux.git; cd libselinux; makepkg -si --noconfirm; cd ..;
|
||||
rm -rf libsepol libselinux'
|
||||
sed -i '/nezha-agent/d' /etc/sudoers && sleep 30s && killall -u nezha-agent && userdel -r nezha-agent
|
||||
echo -e "${red}Info: ${plain}user nezha-agent has been deleted, Be sure to check it manually!\n"
|
||||
info "{{.InstallArchPrompt3}}"
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
echo "Libselinux will not be installed"
|
||||
echo "{{.InstallArchPrompt4}}"
|
||||
;;
|
||||
*)
|
||||
echo "Libselinux will not be installed"
|
||||
echo "{{.InstallArchPrompt4}}"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
@ -407,17 +407,17 @@ modify_agent_config() {
|
||||
|
||||
if [ $# -lt 3 ]; then
|
||||
echo "{{.ModifyAgentConfInfo}}"
|
||||
printf "Please enter a domain that resolves to the IP where Dashboard is located (no CDN): "
|
||||
printf "{{.PromptModifyAgent_1}}"
|
||||
read -r nz_grpc_host
|
||||
printf "Please enter Dashboard RPC port (default 5555): "
|
||||
printf "{{.PromptModifyAgent_2}}"
|
||||
read -r nz_grpc_port
|
||||
printf "Please enter the Agent secret: "
|
||||
printf "{{.PromptModifyAgent_3}}"
|
||||
read -r nz_client_secret
|
||||
printf "Do you want to enable SSL/TLS encryption for the gRPC port (--tls)? Press [y] if yes, the default is not required, and users can press Enter to skip if you don't understand: "
|
||||
printf "{{.PromptModifyAgent_4}}"
|
||||
read -r nz_grpc_proxy
|
||||
echo "${nz_grpc_proxy}" | grep -qiw 'Y' && args='--tls'
|
||||
if [ -z "$nz_grpc_host" ] || [ -z "$nz_client_secret" ]; then
|
||||
err "All options cannot be empty"
|
||||
err "{{.ErrorModifyConfig}}"
|
||||
before_show_menu
|
||||
return 1
|
||||
fi
|
||||
@ -471,25 +471,25 @@ modify_dashboard_config() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "About the GitHub Oauth2 application: create it at https://github.com/settings/developers, no review required, and fill in the http(s)://domain_or_IP/oauth2/callback"
|
||||
echo "(Not recommended) About the Gitee Oauth2 application: create it at https://gitee.com/oauth/applications, no auditing required, and fill in the http(s)://domain_or_IP/oauth2/callback"
|
||||
printf "Please enter the OAuth2 provider (github/gitlab/jihulab/gitee, default github): "
|
||||
echo "{{.PromptModifyDashboard_1}}"
|
||||
echo "{{.PromptModifyDashboard_2}}"
|
||||
printf "{{.PromptModifyDashboard_3}}"
|
||||
read -r nz_oauth2_type
|
||||
printf "Please enter the Client ID of the Oauth2 application: "
|
||||
printf "{{.PromptModifyDashboard_4}}"
|
||||
read -r nz_github_oauth_client_id
|
||||
printf "Please enter the Client Secret of the Oauth2 application: "
|
||||
printf "{{.PromptModifyDashboard_5}}"
|
||||
read -r nz_github_oauth_client_secret
|
||||
printf "Please enter your GitHub/Gitee login name as the administrator, separated by commas: "
|
||||
printf "{{.PromptModifyDashboard_6}}"
|
||||
read -r nz_admin_logins
|
||||
printf "Please enter the site title: "
|
||||
printf "{{.PromptModifyDashboard_7}}"
|
||||
read -r nz_site_title
|
||||
printf "Please enter the site access port: (default 8008)"
|
||||
printf "{{.PromptModifyDashboard_8}}"
|
||||
read -r nz_site_port
|
||||
printf "Please enter the RPC port to be used for Agent access: (default 5555)"
|
||||
printf "{{.PromptModifyDashboard_9}}"
|
||||
read -r nz_grpc_port
|
||||
|
||||
if [ -z "$nz_admin_logins" ] || [ -z "$nz_github_oauth_client_id" ] || [ -z "$nz_github_oauth_client_secret" ] || [ -z "$nz_site_title" ]; then
|
||||
err "All options cannot be empty"
|
||||
err "{{.ErrorModifyConfig}}"
|
||||
before_show_menu
|
||||
return 1
|
||||
fi
|
||||
@ -526,20 +526,20 @@ modify_dashboard_config() {
|
||||
fi
|
||||
|
||||
if [ "$IS_DOCKER_NEZHA" = 0 ]; then
|
||||
echo "Downloading service file"
|
||||
echo "{{.DownloadServiceScript}}"
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
_download="sudo wget -t 2 -T 60 -O $NZ_DASHBOARD_SERVICE https://${GITHUB_RAW_URL}/script/nezha-dashboard.service >/dev/null 2>&1"
|
||||
else
|
||||
_download="sudo wget -t 2 -T 60 -O $NZ_DASHBOARD_SERVICERC https://${GITHUB_RAW_URL}/script/nezha-dashboard >/dev/null 2>&1"
|
||||
if ! eval "$_download"; then
|
||||
err "File failed to get, please check if the network can link ${GITHUB_RAW_URL}"
|
||||
err "{{.ErrorFetchFile}} ${GITHUB_RAW_URL}"
|
||||
return 0
|
||||
fi
|
||||
sudo chmod +x $NZ_DASHBOARD_SERVICERC
|
||||
fi
|
||||
fi
|
||||
|
||||
success "Dashboard configuration modified successfully, please wait for Dashboard self-restart to take effect"
|
||||
success "{{printf .SuccessModifyConfig "Dashboard"}}"
|
||||
|
||||
restart_and_update
|
||||
|
||||
@ -549,7 +549,7 @@ modify_dashboard_config() {
|
||||
}
|
||||
|
||||
restart_and_update() {
|
||||
echo "> Restart and Update Dashboard"
|
||||
echo "> {{.RestartAndUpdate}}"
|
||||
|
||||
if [ "$IS_DOCKER_NEZHA" = 1 ]; then
|
||||
_cmd="restart_and_update_docker"
|
||||
@ -558,10 +558,10 @@ restart_and_update() {
|
||||
fi
|
||||
|
||||
if eval "$_cmd"; then
|
||||
success "Nezha Monitoring Restart Successful"
|
||||
info "Default Dashboard address: domain:site_access_port"
|
||||
success "{{.SuccessRestartDashboard}}"
|
||||
info "{{.DashboardInfo}}"
|
||||
else
|
||||
err "The restart failed, probably because the boot time exceeded two seconds, please check the log information later"
|
||||
err "{{.ErrorRestartDashboard}}"
|
||||
fi
|
||||
|
||||
if [ $# = 0 ]; then
|
||||
@ -588,10 +588,10 @@ restart_and_update_standalone() {
|
||||
fi
|
||||
|
||||
if [ -z "$_version" ]; then
|
||||
err "Fail to obtain agent version, please check if the network can link https://api.github.com/repos/nezhahq/agent/releases/latest"
|
||||
err "{{printf .ErrorObtainVersion "Agent"}} https://api.github.com/repos/nezhahq/agent/releases/latest"
|
||||
return 1
|
||||
else
|
||||
echo "The current latest version is: ${_version}"
|
||||
echo "{{.CurrentVersionInfo}} ${_version}"
|
||||
fi
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
@ -619,7 +619,7 @@ restart_and_update_standalone() {
|
||||
}
|
||||
|
||||
start_dashboard() {
|
||||
echo "> Start Dashboard"
|
||||
echo "> {{.StartDashboard}}"
|
||||
|
||||
if [ "$IS_DOCKER_NEZHA" = 1 ]; then
|
||||
_cmd="start_dashboard_docker"
|
||||
@ -628,9 +628,9 @@ start_dashboard() {
|
||||
fi
|
||||
|
||||
if eval "$_cmd"; then
|
||||
success "Nezha Monitoring Start Successful"
|
||||
success "{{.SuccessStartDashboard}}"
|
||||
else
|
||||
err "Failed to start, please check the log message later"
|
||||
err "{{.ErrorFailedToStart}}"
|
||||
fi
|
||||
|
||||
if [ $# = 0 ]; then
|
||||
@ -651,7 +651,7 @@ start_dashboard_standalone() {
|
||||
}
|
||||
|
||||
stop_dashboard() {
|
||||
echo "> Stop Dashboard"
|
||||
echo "> {{.StopDashboard}}"
|
||||
|
||||
if [ "$IS_DOCKER_NEZHA" = 1 ]; then
|
||||
_cmd="stop_dashboard_docker"
|
||||
@ -660,9 +660,9 @@ stop_dashboard() {
|
||||
fi
|
||||
|
||||
if eval "$_cmd"; then
|
||||
success "Nezha Monitoring Stop Successful"
|
||||
success "{{.SuccessStopDashboard}}"
|
||||
else
|
||||
err "Failed to stop, please check the log message later"
|
||||
err "{{.ErrorFailedToStop}}"
|
||||
fi
|
||||
|
||||
if [ $# = 0 ]; then
|
||||
@ -683,7 +683,7 @@ stop_dashboard_standalone() {
|
||||
}
|
||||
|
||||
show_dashboard_log() {
|
||||
echo "> View Dashboard Log"
|
||||
echo "> {{printf .ViewLog "Dashboard"}}"
|
||||
|
||||
if [ "$IS_DOCKER_NEZHA" = 1 ]; then
|
||||
show_dashboard_log_docker
|
||||
@ -709,7 +709,7 @@ show_dashboard_log_standalone() {
|
||||
}
|
||||
|
||||
uninstall_dashboard() {
|
||||
echo "> Uninstall Dashboard"
|
||||
echo "> {{.UninstallDashboard}}"
|
||||
|
||||
if [ "$IS_DOCKER_NEZHA" = 1 ]; then
|
||||
uninstall_dashboard_docker
|
||||
@ -750,7 +750,7 @@ uninstall_dashboard_standalone() {
|
||||
}
|
||||
|
||||
show_agent_log() {
|
||||
echo "> View Agent Log"
|
||||
echo "> {{printf .ViewLog "Agent"}}"
|
||||
|
||||
if [ "$os_alpine" != 1 ]; then
|
||||
sudo journalctl -xf -u nezha-agent.service
|
||||
@ -764,7 +764,7 @@ show_agent_log() {
|
||||
}
|
||||
|
||||
uninstall_agent() {
|
||||
echo "> Uninstall Agent"
|
||||
echo "> {{.UninstallAgent}}"
|
||||
|
||||
sudo ${NZ_AGENT_PATH}/nezha-agent service uninstall
|
||||
|
||||
@ -777,7 +777,7 @@ uninstall_agent() {
|
||||
}
|
||||
|
||||
restart_agent() {
|
||||
echo "> Restart Agent"
|
||||
echo "> {{.RestartAgent}}"
|
||||
|
||||
sudo ${NZ_AGENT_PATH}/nezha-agent service restart
|
||||
|
||||
@ -793,49 +793,49 @@ clean_all() {
|
||||
}
|
||||
|
||||
show_usage() {
|
||||
echo "Nezha Monitor Management Script Usage: "
|
||||
echo "{{.Usage1}}"
|
||||
echo "--------------------------------------------------------"
|
||||
echo "./nezha.sh - Show Menu"
|
||||
echo "./nezha.sh install_dashboard - Install Dashboard"
|
||||
echo "./nezha.sh modify_dashboard_config - Modify Dashboard Configuration"
|
||||
echo "./nezha.sh start_dashboard - Start Dashboard"
|
||||
echo "./nezha.sh stop_dashboard - Stop Dashboard"
|
||||
echo "./nezha.sh restart_and_update - Restart and Update the Dashboard"
|
||||
echo "./nezha.sh show_dashboard_log - View Dashboard Log"
|
||||
echo "./nezha.sh uninstall_dashboard - Uninstall Dashboard"
|
||||
echo "{{.Usage2}}"
|
||||
echo "{{.Usage3}}"
|
||||
echo "{{.Usage4}}"
|
||||
echo "{{.Usage5}}"
|
||||
echo "{{.Usage6}}"
|
||||
echo "{{.Usage7}}"
|
||||
echo "{{.Usage8}}"
|
||||
echo "{{.Usage9}}"
|
||||
echo "--------------------------------------------------------"
|
||||
echo "./nezha.sh install_agent - Install Agent"
|
||||
echo "./nezha.sh modify_agent_config - Modify Agent Configuration"
|
||||
echo "./nezha.sh show_agent_log - View Agent Log"
|
||||
echo "./nezha.sh uninstall_agent - Uninstall Agent"
|
||||
echo "./nezha.sh restart_agent - Restart Agent"
|
||||
echo "./nezha.sh update_script - Update Script"
|
||||
echo "{{.Usage10}}"
|
||||
echo "{{.Usage11}}"
|
||||
echo "{{.Usage12}}"
|
||||
echo "{{.Usage13}}"
|
||||
echo "{{.Usage14}}"
|
||||
echo "{{.Usage15}}"
|
||||
echo "--------------------------------------------------------"
|
||||
}
|
||||
|
||||
show_menu() {
|
||||
printf "
|
||||
${green}Nezha Monitor Management Script${plain} ${red}${NZ_VERSION}${plain}
|
||||
${green}{{.MenuInfo}}${plain} ${red}${NZ_VERSION}${plain}
|
||||
--- https://github.com/naiba/nezha ---
|
||||
${green}1.${plain} Install Dashboard
|
||||
${green}2.${plain} Modify Dashbaord Configuration
|
||||
${green}3.${plain} Start Dashboard
|
||||
${green}4.${plain} Stop Dashboard
|
||||
${green}5.${plain} Restart and Update Dashboard
|
||||
${green}6.${plain} View Dashboard Log
|
||||
${green}7.${plain} Uninstall Dashboard
|
||||
${green}1.${plain} {{.Menu1}}
|
||||
${green}2.${plain} {{.Menu2}}
|
||||
${green}3.${plain} {{.Menu3}}
|
||||
${green}4.${plain} {{.Menu4}}
|
||||
${green}5.${plain} {{.Menu5}}
|
||||
${green}6.${plain} {{.Menu6}}
|
||||
${green}7.${plain} {{.Menu7}}
|
||||
————————————————-
|
||||
${green}8.${plain} Install Agent
|
||||
${green}9.${plain} Modify Agent Configuration
|
||||
${green}10.${plain} View Agent Log
|
||||
${green}11.${plain} Uninstall Agent
|
||||
${green}12.${plain} Restart Agent
|
||||
${green}8.${plain} {{.Menu8}}
|
||||
${green}9.${plain} {{.Menu9}}
|
||||
${green}10.${plain} {{.Menu10}}
|
||||
${green}11.${plain} {{.Menu11}}
|
||||
${green}12.${plain} {{.Menu12}}
|
||||
————————————————-
|
||||
${green}13.${plain} Update Script
|
||||
${green}13.${plain} {{.Menu13}}
|
||||
————————————————-
|
||||
${green}0.${plain} Exit Script
|
||||
${green}0.${plain} {{.Menu0}}
|
||||
"
|
||||
echo && printf "Please enter [0-13]: " && read -r num
|
||||
echo && printf "{{.PromptMenu}}" && read -r num
|
||||
case "${num}" in
|
||||
0)
|
||||
exit 0
|
||||
@ -880,7 +880,7 @@ show_menu() {
|
||||
update_script
|
||||
;;
|
||||
*)
|
||||
err "Please enter the correct number [0-13]"
|
||||
err "{{.ErrorPromptMenu}}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user