summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshizhendong <[email protected]>2023-06-05 17:59:24 +0800
committershizhendong <[email protected]>2023-06-05 17:59:24 +0800
commita49fe73f37d5bbd84d08f4c3392fe9118ee75e13 (patch)
tree4cd52247387ae90f2e4735d9a9645c37ca236fa0
parenta6cf8118ed4e73f5e17b9a1d31fd16716a4c6c3f (diff)
parent024f3dc047a218a90274f6a4d994cd3b0e8bbb8a (diff)
Merge remote-tracking branch 'origin/master' into dev-23.01rel-23.01.07
# Conflicts: # tools/package.sh
-rw-r--r--tools/install-agent.sh.template (renamed from tools/install.sh.template)2
-rw-r--r--tools/install-talon.sh.template175
-rw-r--r--tools/package.sh7
3 files changed, 180 insertions, 4 deletions
diff --git a/tools/install.sh.template b/tools/install-agent.sh.template
index 73e65e1..46ad1f0 100644
--- a/tools/install.sh.template
+++ b/tools/install-agent.sh.template
@@ -165,7 +165,7 @@ EOF
}
if [ 1 -eq $(isInstall) ];then
- log yellow "The nz-agent is installed , token is "$(cat $INSTALL_PATH/config/auth.token)
+ log yellow "The nz-agent is installed , token is "$(cat $INSTALL_PATH/config/token.auth)
else
downloadPackaget && installPackage
log green "The nz-agent install finish,you can check agent info in WEB gui"
diff --git a/tools/install-talon.sh.template b/tools/install-talon.sh.template
new file mode 100644
index 0000000..c97797c
--- /dev/null
+++ b/tools/install-talon.sh.template
@@ -0,0 +1,175 @@
+#!/bin/bash
+{ # this ensures the entire script is downloaded #
+# Find Java
+if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
+ JAVA_EXE="$JAVA_HOME/bin/java"
+elif type -p java > /dev/null 2>&1; then
+ JAVA_EXE=$(type -p java)
+elif [[ -x "/usr/bin/java" ]]; then
+ JAVA_EXE="/usr/bin/java"
+else
+ echo -e "\e[1;31mUnable to find Java\e[0m"
+ exit 1
+fi
+
+echo "java: $JAVA_EXE"
+
+
+#auto replace parameter start
+WEB_TOKEN=${webToken}
+
+REMOTE_IP=${remoteIP}
+
+REMOTE_PORT=${remotePort}
+
+SSL_ENABLED=${sslEnabled}
+
+ASSET_ID=${assetId}
+
+if [ ! -z "$REMOTE_PORT" ];then
+ REMOTE_IP=$REMOTE_IP:$REMOTE_PORT
+fi
+
+LOCALHOST=${localhost}
+#auto replace parameter end
+
+
+# random token
+TALON_TOKEN=$(cut -d '-' -f 1 /proc/sys/kernel/random/uuid)
+
+# path var
+ROOT_PATH=/opt/nezha
+
+INSTALL_PATH=$ROOT_PATH/nz-talon
+
+# reset work tmp dir
+WORK_PATH=/tmp/.nezha/nz-talon
+rm -rf $WORK_PATH&&mkdir -p $WORK_PATH
+
+
+function osInfo() {
+ if [ -e /etc/centos-release ];then
+ echo 'centos'
+ elif [ -e /etc/debian_version ]; then
+ echo 'debian'
+ elif [ -e /etc/lsb_release ]; then
+ echo 'ubuntu'
+ else
+ echo 'centos';
+ fi
+}
+
+CURRENT_OS=$(osInfo)
+
+function log() {
+ case $1 in
+ "red")
+ echo -e "\e[1;31m$2\e[0m"
+ ;;
+ "yellow")
+ echo -e "\e[1;33m$2\e[0m"
+ ;;
+ "green")
+ echo -e "\e[1;32m$2\e[0m"
+ ;;
+ *)
+ echo $2
+ ;;
+ esac
+}
+
+# rpm -aq | grep nz-talon
+function isInstall() {
+ case $CURRENT_OS in
+ 'centos')
+ if [ $(rpm -aq | grep nz-talon | wc -l) -lt 1 ];then
+ echo 0
+ else
+ echo 1;
+ fi
+ ;;
+ esac
+}
+
+function getPackageName() {
+ case $CURRENT_OS in
+ 'centos')
+ echo "nz-talon.rpm"
+ ;;
+ esac
+}
+PACKAGE_NAME=$(getPackageName $CURRENT_OS)
+
+function downloadPackaget() {
+ cd $WORK_PATH;
+ log yellow "current os is $CURRENT_OS ,download package from http://$REMOTE_IP/asset/talon/download?os=$CURRENT_OS"
+ if command -v wget >/dev/null 2>&1;then
+ if $SSL_ENABLED ;then
+ wget -O $PACKAGE_NAME --no-check-certificate --header="Authorization:"$WEB_TOKEN "https://$REMOTE_IP/asset/talon/download?os="$CURRENT_OS
+ else
+ wget -O $PACKAGE_NAME --header="Authorization:"$WEB_TOKEN "http://$REMOTE_IP/asset/talon/download?os="$CURRENT_OS
+ fi
+ return 0
+ elif command -v curl >/dev/null 2>&1;then
+ if $SSL_ENABLED ;then
+ curl -o $PACKAGE_NAME -k -H "Authorization:"$WEB_TOKEN "https://$REMOTE_IP/asset/talon/download?os="$CURRENT_OS
+ else
+ curl -o $PACKAGE_NAME -H "Authorization:"$WEB_TOKEN "http://$REMOTE_IP/asset/talon/download?os="$CURRENT_OS
+ fi
+ return 0
+ else
+ log red "The wget/curl command is required"
+ exit 1
+ fi
+}
+
+function installPackage() {
+ case $CURRENT_OS in
+ 'centos')
+ log yellow 'install package right now...'
+ rpm -ivh $WORK_PATH/$PACKAGE_NAME && mkdir -p $INSTALL_PATH/config; echo -n $TALON_TOKEN > $INSTALL_PATH/config/token.auth
+ ;;
+ esac
+
+ if [ 0 -eq $? ];then
+ cat > $WORK_PATH/param.tmp <<EOF
+ {
+ "assetId":"$ASSET_ID",
+ "port":10092,
+ "token":"$TALON_TOKEN"
+ }
+EOF
+ log yellow 'now regist talon to system with information :'
+ cat $WORK_PATH/param.tmp
+ if $SSL_ENABLED ;then
+ local msg=`curl -s -k -X POST -H "Content-Type:application/json" -H "Authorization:"$WEB_TOKEN -d @$WORK_PATH/param.tmp "https://$REMOTE_IP/asset/talon/register"`
+ else
+ local msg=`curl -s -X POST -H "Content-Type:application/json" -H "Authorization:"$WEB_TOKEN -d @$WORK_PATH/param.tmp "http://$REMOTE_IP/asset/talon/register"`
+ fi
+ local code=`echo $msg |grep -E -o '"code":[0-9]+'|grep -E -o '[0-9]+'`
+ rm -rf $WORK_PATH/param.tmp
+ if [ 200 -eq $code ];then
+ log green 'regist talon success!'
+ else
+ log red 'regist talon failed,cause:'
+ echo $msg
+ exit 1
+ fi
+ else
+ log red "install nz-talon package may be has some error please try again or install by yourself"
+ exit 1
+ fi
+}
+
+if [ 1 -eq $(isInstall) ];then
+ log yellow "The nz-talon is installed , token is "$(cat $INSTALL_PATH/config/token.auth)
+else
+ downloadPackaget && installPackage
+ log green "The nz-talon install finish,you can check talon info in WEB gui"
+fi
+
+
+}
+
+# this ensures the entire script is downloaded #
+
diff --git a/tools/package.sh b/tools/package.sh
index 595e088..f1d4285 100644
--- a/tools/package.sh
+++ b/tools/package.sh
@@ -28,7 +28,7 @@ mc cp nz/$NZ_WEB_PKG ./
mc cp nz/$NZ_AGENT_PKG ./
mc cp nz/$NZ_GUI_PKG ./
mc cp nz/$NZ_TALON_PKG ./
-mc cp nz/depends/exporter/generator.zip ./
+mc cp nz/depends/exporter/generator-0.21.0.linux-amd64.zip ./
mc cp nz/depends/prometheus/promtool ./
mc cp nz/depends/map/Tiles.zip ./
mc cp nz/depends/jdk/$JDK_FILENAME ./
@@ -55,14 +55,15 @@ unzip -o -q Tiles.zip -d $RPM_NZ_PATH/public/static
# 移动nz.rpm
mv nz-*.rpm $RPM_NZ_PATH/install
-cp ./tools/install.sh.template $RPM_NZ_PATH/install
+cp ./tools/install-agent.sh.template $RPM_NZ_PATH/install
+cp ./tools/install-talon.sh.template $RPM_NZ_PATH/install
# license 校验依赖so
cp ./tools/lib*.so $RPM_NZ_PATH/lib
# 移动依赖工具
mv promtool $RPM_NZ_PATH/promtool/
-unzip -o generator.zip -d $RPM_NZ_PATH/generator/
+unzip -o generator-0.21.0.linux-amd64.zip -d $RPM_NZ_PATH/generator/
# 配置文件
cp ./tools/nezha.properties $RPM_NZ_PATH/config