fix: NEZ-2138 修复 shell function 位置不当问题

This commit is contained in:
shizhendong
2023-04-26 16:49:24 +08:00
parent c011b6b548
commit a81ebe861f
3 changed files with 68 additions and 60 deletions

View File

@@ -2,6 +2,52 @@
WORK_DIR=/opt/nezha/nz-talon
service_exists(){
local n=$1
if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | sed 's/^\s*//g' | cut -f1 -d' ') == $n.service ]]; then
return 0
else
return 1
fi
}
compareMD5(){
if [ ! -f $1 ] || [ ! -f $2 ];then
echo 1
return 1
fi
local f1MD5=`md5sum $1|awk '{print $1}'`
local f2MD5=`md5sum $2|awk '{print $1}'`
if [ ${f1MD5} = ${f2MD5} ];then
echo 0
return 0
else
echo 1
return 1
fi
}
# 还原配置文件
# $1 需要还原的文件目录 /opt/nezha/nz-talon/config /opt/nezha/nz-talon/promtail ...
# $2 备份文件目录 /tmp/nezha/nz-talon/config /tmp/nezha/nz-talon/promtail ...
restoreComponentConfig(){
if [ ! -d $1 ] || [ ! -d $2 ];then
echo "Directory does not exist"
return 1
fi
for i in $(ls $2);do
if [ 1 -eq `compareMD5 $1/$i $2/$i` ];then
echo 'return config file '$1/${i}
cp -f $2/$i $1/$i
fi
done
}
# Find Java
if [[ -x "$WORK_DIR/jdk/bin/java" ]]; then
JAVA_EXE="$WORK_DIR/jdk/bin/java"
@@ -119,46 +165,3 @@ EOF
fi
fi
service_exists(){
local n=$1
if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | sed 's/^\s*//g' | cut -f1 -d' ') == $n.service ]]; then
return 0
else
return 1
fi
}
compareMD5(){
if [ ! -f $1 ] || [ ! -f $2 ];then
echo 1
return 1
fi
local f1MD5=`md5sum $1|awk '{print $1}'`
local f2MD5=`md5sum $2|awk '{print $1}'`
if [ ${f1MD5} = ${f2MD5} ];then
echo 0
return 0
else
echo 1
return 1
fi
}
# 还原配置文件
# $1 需要还原的文件目录 /opt/nezha/nz-talon/config /opt/nezha/nz-talon/promtail ...
# $2 备份文件目录 /tmp/nezha/nz-talon/config /tmp/nezha/nz-talon/promtail ...
restoreComponentConfig(){
if [ ! -d $1 ] || [ ! -d $2 ];then
echo "Directory does not exist"
return 1
fi
for i in $(ls $2);do
if [ 1 -eq `compareMD5 $1/$i $2/$i` ];then
echo 'return config file '$1/${i}
cp -f $2/$i $1/$i
fi
done
}

View File

@@ -1,4 +1,14 @@
#!/bin/sh
service_exists(){
local n=$1
if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | sed 's/^\s*//g' | cut -f1 -d' ') == $n.service ]]; then
return 0
else
return 1
fi
}
if [ 0 -eq $1 ];then
echo 'start remove nz-talon module from disk...'
@@ -33,11 +43,4 @@ if [ 0 -eq $1 ];then
echo 'uninstall success!'
fi
service_exists(){
local n=$1
if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | sed 's/^\s*//g' | cut -f1 -d' ') == $n.service ]]; then
return 0
else
return 1
fi
}

View File

@@ -4,6 +4,17 @@ TALON_PATH=/opt/nezha/nz-talon
PROMTAIL_PATH=/opt/nezha/promtail
TELEGRAF_PATH=/opt/nezha/telegraf
service_exists(){
local n=$1
if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | sed 's/^\s*//g' | cut -f1 -d' ') == $n.service ]]; then
return 0
else
return 1
fi
}
if [ 2 -eq $1 ];then
if [ ! -d ${TALON_PATH}/config ];then
@@ -52,12 +63,3 @@ if [ 2 -eq $1 ];then
fi
fi
service_exists(){
local n=$1
if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | sed 's/^\s*//g' | cut -f1 -d' ') == $n.service ]]; then
return 0
else
return 1
fi
}