#!/bin/bash { # this ensures the entire script is downloaded # #auto replace parameter start WEB_TOKEN=${webToken} REMOTE_IP=${remoteIP} REMOTE_PORT=${remotePort} SSL_ENABLED=${sslEnabled} ASSET_ID=${assetId} IP=`hostname -I | tr ' ' ','` 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 <