add: 打包脚本

This commit is contained in:
TsMask
2024-03-19 16:46:48 +08:00
parent 93754d1c1d
commit 2c6c3ab756
360 changed files with 39437 additions and 62 deletions

52
build/misc/actpkg.sh Normal file
View File

@@ -0,0 +1,52 @@
#!/bin/bash
filename="$1"
neType="$2"
duration=180
expectBin=/usr/bin/expect
omcBin=/usr/local/omc/bin
logFile=/tmp/actpkg`date +%Y%m%d`.log
extension=$(basename "${1}" | awk -F . '{print $NF}')
if [ ! -f ${expectBin} ]; then
echo "Please install software expect first"
exit 99
fi
case "${extension}" in
deb)
if [ ${neType} == "OMC" ]; then
systemctl stop restagent.service
fi
expect <<EOF > ${logFile}
spawn dpkg -i --force-all "$filename"
set timeout ${duration}
expect {
"y/n" { send "y\n"; exp_continue }
}
EOF
if [ ${neType} == "OMC" ]; then
${omcBin}/setomc.sh -m upgrade >> ${logFile}
fi
;;
rpm)
if [ ${neType} == "OMC" ]; then
systemctl stop restagent.service
fi
expect <<EOF > ${logFile}
spawn rpm -Uvh "$filename"
set timeout ${duration}
expect {
"y/n" { send "y\n"; exp_continue }
}
EOF
if [ ${neType} == "OMC" ]; then
${omcBin}/setomc.sh -m upgrade >> ${logFile}
fi
;;
*)
echo "The file does not have a .deb or .rpm extension"
exit 100
;;
esac

10
build/misc/checkdisk.sh Normal file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
threshold=99 # 设置硬盘使用率的阈值
disk_usage=$(df -h | awk '$NF=="/"{print $(NF-1)}' | sed 's/%//') # 获取根目录的硬盘使用率
if [ $disk_usage -gt $threshold ]; then
echo "Disk usage is above $threshold%. Taking action..."
systemctl restart keepalived
fi

8
build/misc/checkproc.sh Normal file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
process_name="restagent"
if ! pgrep -x "$process_name" >/dev/null; then
echo "$process_name is not running. Restarting..."
systemctl restart keepalived
fi

38
build/misc/cpnetools.sh Normal file
View File

@@ -0,0 +1,38 @@
#!/bin/bash
tooldir=/usr/local/bin
toollist="zip unzip"
#分发到各个节点,这里分发到nehosts文件中的主机中.
while read line
do
if [[ "$line" =~ ^[^[:space:]]*# || -z "$line" ]]; then
continue
fi
user=`echo $line | cut -d " " -f 2`
ip=`echo $line | cut -d " " -f 1`
passwd=`echo $line | cut -d " " -f 3`
for toolname in $toollist;do
expect <<EOF
set timeout 10
spawn scp $tooldir/$toolname $user@$ip:/tmp
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$passwd\n" }
}
expect "password" { send "$passwd\n" }
EOF
done
for toolname in $toollist;do
expect <<EOF
set timeout 10
spawn ssh $user@$ip sudo mv /tmp/$toolname $tooldir
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$passwd\n" }
}
expect "password" { send "$passwd\n" }
EOF
done
done < nehosts

29
build/misc/cpsshkey.sh Normal file
View File

@@ -0,0 +1,29 @@
#!/bin/bash
# 判断id_rsa密钥文件是否存在
if [ ! -f ~/.ssh/id_rsa ];then
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
else
echo "id_rsa has created ..."
fi
#分发到各个节点,这里分发到nehosts文件中的主机中.
while read line
do
if [[ "$line" =~ ^[^[:space:]]*# || -z "$line" ]]; then
continue
fi
user=`echo $line | cut -d " " -f 2`
ip=`echo $line | cut -d " " -f 1`
passwd=`echo $line | cut -d " " -f 3`
expect <<EOF
set timeout 10
spawn ssh-copy-id -f $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$passwd\n" }
}
expect "password" { send "$passwd\n" }
EOF
done < nehosts

99
build/misc/importdb.sh Normal file
View File

@@ -0,0 +1,99 @@
#!/bin/bash
USER="root"
PASSWORD="1000omc@kp!"
PORT="33066"
DBNAME="omc_db"
UpgradeSQLDir=/usr/local/omc/etc/db/upgrade
Upgvue3SQLDir=/usr/local/omc/etc/db/upgvue3
InstallSQLDir=/usr/local/omc/etc/db/install
drop_db_sql="drop database IF EXISTS ${DBNAME}"
create_db_sql="create database IF NOT EXISTS ${DBNAME}"
case "$1" in
upgrade)
echo "Upgrade database ${DBNAME}"
for SQL in ${UpgradeSQLDir}/*.sql; do
echo "Execute SQL script: ${SQL} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
done
;;
upgvue3)
echo "Upgrade to vue3 database ${DBNAME}"
for SQL in ${Upgvue3SQLDir}/*.sql; do
echo "Execute SQL script: ${SQL} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
done
;;
install)
echo "Drop database ${DBNAME} ...!!!"
mysql -u${USER} -p${PASSWORD} -P $PORT --protocol tcp -e "${drop_db_sql}"
echo "Create database ${DBNAME} if not exist"
mysql -u${USER} -p${PASSWORD} -P $PORT --protocol tcp -e "${create_db_sql}"
for SQL in ${InstallSQLDir}/*.sql; do
echo "Execute SQL script: ${SQL} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
done
;;
*)
while true
do
read -r -p "Do you upgrade or upgrade from layui to vue3 or fresh install database ${DBNAME}? [Upgrade/upgVue3/Install/Quit] " input
case $input in
[uU][pP][gG][rR][aA][dD][eE]|[uU])
echo "Skip to drop database ${DBNAME}"
echo "Upgrade database ${DBNAME}"
for SQL in ${UpgradeSQLDir}/*.sql; do
echo "Execute SQL script: ${SQL} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
done
break
;;
[uU][pP][gG][vV][uU][eE][3]|[vV]])
echo "Skip to drop database ${DBNAME}"
echo "Upgrade to vue3 database ${DBNAME}"
for SQL in ${Upgvue3SQLDir}/*.sql; do
echo "Execute SQL script: ${SQL} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
done
break
;;
[iI][nN][sS][tT][aA][lL][lL]|[iI])
echo "Drop database ${DBNAME} ...!!!"
mysql -u${USER} -p${PASSWORD} -P $PORT --protocol tcp -e "${drop_db_sql}"
echo "Create database ${DBNAME} if not exist"
mysql -u${USER} -p${PASSWORD} -P $PORT --protocol tcp -e "${create_db_sql}"
for SQL in ${InstallSQLDir}/*.sql; do
echo "Execute SQL script: ${SQL} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
done
break
;;
[qQ][uU][iI][tT]|[qQ])
echo "Nothing to be done! GOOD BYE"
exit 1;
;;
*)
echo "Invalid input..."
;;
esac
done
;;
esac

16
build/misc/nehosts Normal file
View File

@@ -0,0 +1,16 @@
# host user password
# Example: 192.168.4.133 root password
172.16.5.100 agtuser admin123
172.16.5.110 agtuser admin123
172.16.5.120 agtuser admin123
172.16.5.130 agtuser admin123
172.16.5.140 agtuser admin123
172.16.5.150 agtuser admin123
172.16.5.160 agtuser admin123
172.16.5.170 agtuser admin123
172.16.5.180 agtuser admin123
172.16.5.190 agtuser admin123
172.16.5.220 agtuser admin123
172.16.5.230 agtuser admin123
172.16.5.210 agtuser admin123
172.16.5.200 agtuser admin123

42
build/misc/omcsvc.sh Normal file
View File

@@ -0,0 +1,42 @@
#!/bin/bash
ProcList="restagent crontask sshsvc captrace adb"
ProcListDesc="adb crontask sshsvc captrace restagent"
BinDir=/usr/local/omc/bin
case "$1" in
start)
for procName in $ProcListDesc;do
echo "Starting $procName process ..."
systemctl start $procName
sleep 1
done
;;
status)
for procName in $ProcList;do
systemctl status $procName
done
;;
stop)
for procName in $ProcList;do
echo "Stoping $procName process ..."
systemctl stop $procName
done
;;
restart)
$0 stop
sleep 1
$0 start
;;
version)
for procName in $ProcList;do
$BinDir/$procName -v
done
;;
*)
echo "OMC service"
echo "Usage: $0 start|status|stop|restart|version"
;;
esac

53
build/misc/rbkpkg.sh Normal file
View File

@@ -0,0 +1,53 @@
#!/bin/bash
filename="$1"
neType="$2"
duration=180
expectBin=/usr/bin/expect
omcBin=/usr/local/omc/bin
logFile=/tmp/actpkg`date +%Y%m%d`.log
extension=$(basename "${1}" | awk -F . '{print $NF}')
if [ ! -f ${expectBin} ]; then
echo "Please install software expect first"
exit 99
fi
case "${extension}" in
deb)
if [ ${neType} == "OMC" ]; then
systemctl stop restagent.service
fi
expect <<EOF > ${logFile}
spawn dpkg -i --force-all "$filename"
set timeout ${duration}
expect {
"y/n" { send "y\n"; exp_continue }
}
EOF
if [ ${neType} == "OMC" ]; then
${omcBin}/setomc.sh -m upgrade >> ${logFile}
fi
;;
rpm)
if [ ${neType} == "OMC" ]; then
systemctl stop restagent.service
fi
expect <<EOF > ${logFile}
spawn rpm -Uvh "$filename"
set timeout ${duration}
expect {
"y/n" { send "y\n"; exp_continue }
}
EOF
if [ ${neType} == "OMC" ]; then
${omcBin}/setomc.sh -m upgrade >> ${logFile}
fi
;;
*)
echo "The file does not have a .deb or .rpm extension"
exit 100
;;
esac

16
build/misc/rmexpfiles.sh Normal file
View File

@@ -0,0 +1,16 @@
#!/bin/bash
# rm expired file with filename like *20231028111213.zip"
filepath=$1
duration=$2
find $filepath -maxdepth 1 -type f -name "*[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*" -printf "%f\n" | while read filename; do
datestr=$(echo "$filename" | grep -oE '[0-9]{8}')
filedate=$(date -d "$datestr" +%s)
sevendaysago=$(date -d "$duration days ago" +%s)
if [ "$filedate" -lt "$sevendaysago" ]; then
rm -f "$filepath/$filename"
echo "rm file: $filename"
fi
done

80
build/misc/setomc.sh Normal file
View File

@@ -0,0 +1,80 @@
#!/bin/bash
C_ARG_LOWER="agt"
C_ARG_UPPER="AGT"
M_ARG_LOWER="*"
check_args() {
while getopts "c:m:" option; do
case $option in
c)
C_ARG_LOWER=$(echo $OPTARG | tr '[:upper:]' '[:lower:]')
C_ARG_UPPER=$(echo $OPTARG | tr '[:lower:]' '[:upper:]')
;;
m)
M_ARG=$(echo $OPTARG | tr '[:upper:]' '[:lower:]')
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
}
USER="root"
PASSWORD="1000omc@kp!"
PORT="33066"
DBNAME="omc_db"
OMCRootDir=/usr/local/omc
OMCBinDir=${OMCRootDir}/bin
UpgradeSQLDir=${OMCRootDir}/etc/db/upgrade
Upgvue3SQLDir=${OMCRootDir}/etc/db/upgvue3
InstallSQLDir=${OMCRootDir}/etc/db/install
OMCStaticDir=${OMCRootDir}/static
check_args "$@"
case "${M_ARG}" in
install)
${OMCBinDir}/importdb.sh ${M_ARG}
if [ "${C_ARG_LOWER}" != "" ]; then
CustomizedDir=${OMCStaticDir}/${C_ARG_LOWER}.d
if [ ! -d "${CustomizedDir}" ]; then
echo "Not found ${C_ARG_UPPER} customized directory, nothing to be done"
exit 1
fi
echo "Setting ${C_ARG_UPPER} customized OMC ..."
for SQL in ${CustomizedDir}/db/*.sql; do
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
done
cp -rf ${CustomizedDir}/logo/* ${OMCStaticDir}/logo
cp -rf ${CustomizedDir}/doc/* ${OMCStaticDir}/helpDoc
perl -0777 -i -pe 's/agtuser/bluearcus/g' ${OMCRootDir}/etc/default/restconf.yaml
perl -0777 -i -pe 's/agtuser/bluearcus/g' ${OMCBinDir}/nehosts
fi
;;
upgrade | upgvue3)
${OMCBinDir}/importdb.sh ${M_ARG}
;;
skip)
if [ "${C_ARG_LOWER}" != "" ]; then
CustomizedDir=${OMCStaticDir}/${C_ARG_LOWER}.d
if [ ! -d "${CustomizedDir}" ]; then
echo "Not found ${C_ARG_UPPER} customized directory, nothing to be done"
exit 1
fi
echo "Setting ${C_ARG_UPPER} customized OMC ..."
for SQL in ${CustomizedDir}/db/*.sql; do
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
done
cp -rf ${CustomizedDir}/logo/* ${OMCStaticDir}/logo
cp -rf ${CustomizedDir}/doc/* ${OMCStaticDir}/helpDoc
fi
;;
*)
${OMCBinDir}/importdb.sh
;;
esac
exit 0

23
build/misc/sshcpid.sh Normal file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
# 判断id_rsa密钥文件是否存在
if [ ! -f ~/.ssh/id_rsa ];then
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
else
echo "id_rsa has created ..."
fi
ip=$1
user=$2
passwd=$3
#分发到$ip主机.
expect <<EOF
set timeout 10
spawn ssh-copy-id -f $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$passwd\n" }
}
expect "password" { send "$passwd\n" }
EOF