-
Notifications
You must be signed in to change notification settings - Fork 185
/
nezha.sh
36 lines (30 loc) · 989 Bytes
/
nezha.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash
# 传哪吒三个参数
NEZHA_SERVER=$1
NEZHA_PORT=$2
NEZHA_KEY=$3
# 三个变量不全则不安装哪吒客户端
check_variable() {
[[ -z "${NEZHA_SERVER}" || -z "${NEZHA_PORT}" || -z "${NEZHA_KEY}" ]] && exit 0
}
# 安装系统依赖
check_dependencies() {
DEPS_CHECK=("wget" "unzip")
DEPS_INSTALL=(" wget" " unzip")
for ((i=0;i<${#DEPS_CHECK[@]};i++)); do [[ ! $(type -p ${DEPS_CHECK[i]}) ]] && DEPS+=${DEPS_INSTALL[i]}; done
[ -n "$DEPS" ] && { apt-get update >/dev/null 2>&1; apt-get install -y $DEPS >/dev/null 2>&1; }
}
# 下载最新版本 Nezha Agent
download_agent() {
URL=$(wget -qO- -4 "https://api.github.com/repos/naiba/nezha/releases/latest" | grep -o "https.*linux_amd64.zip")
wget -t 2 -T 10 -N ${URL}
unzip -qod ./ nezha-agent_linux_amd64.zip && rm -f nezha-agent_linux_amd64.zip
}
# 运行客户端
run() {
./nezha-agent -s ${NEZHA_SERVER}:${NEZHA_PORT} -p ${NEZHA_KEY}
}
check_variable
check_dependencies
download_agent
run