1
0
Files
build.ems/debbuild/22.04/DEBIAN/postinst

149 lines
5.3 KiB
Plaintext

# !/bin/bash
RedisRootDir=/usr/local
RedisOldRootDir=/usr/local/db
RedisConfDir=${RedisRootDir}/etc/adb
DependsRootDir=/usr/local/omc/depends
SystemdRootDir=/lib/systemd/system
OMCEtcDir=/usr/local/omc/etc
FERootDir=/usr/local/omc/htdocs/front
X86Lib64Dir=/lib/x86_64-linux-gnu
OmcBinDir=/usr/local/omc/bin
OMCStaticDir=/usr/local/omc/static
UsrLocalBinDir=/usr/local/bin
OmcDaemon=omcd
NginxEtcDir=/etc/nginx
NginxConfDir=${NginxEtcDir}/conf.d
NginxSiteAvailable=${NginxEtcDir}/sites-available
CFileList="restconf.yaml crontask.yaml tasks.yaml sshsvc.yaml capconf.yaml omc.conf"
LogoFileList="zh_brand.png zh_icon.png en_brand.png en_icon.png"
echo ""
echo "* To start/stop/restart/status omc service, please run:"
echo " sudo systemctl start/stop/restart/status restagent.service"
echo " sudo systemctl start/stop/restart/status crontask.service"
echo " sudo systemctl start/stop/restart/status sshsvc.service"
echo " sudo systemctl start/stop/restart/status captrace.service"
echo " sudo systemctl start/stop/restart/status adb.service"
echo " or run: "
echo " sudo /usr/local/omc/bin/omcsvc.sh start/stop/restart/status"
echo ""
cd ${X86Lib64Dir}
chmod +rx libwireshark.so.15.0.12
if [ ! -e libwireshark.so.15 ]; then ln -s libwireshark.so.15.0.12 libwireshark.so.15; fi
if [ ! -e libwireshark.so ]; then ln -s libwireshark.so.15.0.12 libwireshark.so; fi
chmod +rx libwiretap.so.12.0.12
if [ ! -e libwiretap.so.12 ]; then ln -s libwiretap.so.12.0.12 libwiretap.so.12; fi
if [ ! -e libwiretap.so ]; then ln -s libwiretap.so.12.0.12 libwiretap.so; fi
chmod +rx libwsutil.so.13.1.0
if [ ! -e libwsutil.so.13 ]; then ln -s libwsutil.so.13.1.0 libwsutil.so.13; fi
if [ ! -e libwsutil.so ]; then ln -s libwsutil.so.13.1.0 libwsutil.so; fi
cd ${UsrLocalBinDir}
if [ ! -e ${OmcDaemon} ]; then ln -s ${OmcBinDir}/omcsvc.sh ${OmcDaemon}; fi
chmod +rx /usr/local/omc/bin/*
chmod +rx /usr/local/omc/*
chmod +rx /usr/local/bin/*
chmod -R 755 /usr/local/omc/htdocs/front
for CFile in ${CFileList}; do
if [ ! -e "${OMCEtcDir}/${CFile}" ]; then
cp -f ${OMCEtcDir}/default/${CFile} ${OMCEtcDir}
# else
# mv -f ${OMCEtcDir}/${CFile} ${OMCEtcDir}/${CFile}.bak
# cp -f ${OMCEtcDir}/default/${CFile} ${OMCEtcDir}
fi
done
# Install redis db if not exist /usr/local/db
if [ ! -e "${RedisRootDir}/bin/adb-server" ]; then
# if [ ! -e "${RedisRootDir}" ]; then
# mkdir -p ${RedisRootDir}
# fi
if [ -e "${RedisOldRootDir}/bin/redis-server" ] && [ -e "${SystemdRootDir}/adb.service" ]; then
systemctl stop adb.service
fi
cp -rf ${DependsRootDir}/adb/* /
chmod +rx ${RedisRootDir}/bin/*
if [ ! -e "${RedisConfDir}/adb.conf" ]; then
cp ${RedisConfDir}/default/adb.conf ${RedisConfDir}
fi
sed -i 's/replica-read-only yes/replica-read-only no/g' ${RedisConfDir}/adb.conf
LINE="masterauth helloearth"
FILE="${RedisConfDir}/adb.conf"
# 检查文件中是否存在该行
if ! grep -qxF "$LINE" "$FILE"; then
# 如果不存在,将其添加到文件末尾
echo "$LINE" >> "$FILE"
fi
# copy the orangin dump.rdb
if [ -e "${RedisOldRootDir}/bin/conf/dump.rdb" ]; then
cp -f ${RedisOldRootDir}/bin/conf/dump.rdb ${RedisConfDir}
mv -f ${RedisRootDir}/db ${RedisRootDir}/adb.old
fi
# cp -f ${DependsRootDir}/systemd/adb.service ${SystemdRootDir}
else
if [ ! -e "${RedisConfDir}/adb.conf" ]; then
cp ${RedisConfDir}/default/adb.conf ${RedisConfDir}
fi
sed -i 's/replica-read-only yes/replica-read-only no/g' ${RedisConfDir}/adb.conf
LINE="masterauth helloearth"
FILE="${RedisConfDir}/adb.conf"
# 检查文件中是否存在该行
if ! grep -qxF "$LINE" "$FILE"; then
# 如果不存在,将其添加到文件末尾
echo "$LINE" >> "$FILE"
fi
fi
if [ ! -e "${FERootDir}/config.js" ]; then
cp ${FERootDir}/default/config.js ${FERootDir};
fi
for LogoFile in ${LogoFileList}; do
if [ ! -e "${OMCStaticDir}/logo/${LogoFile}" ]; then
cp ${OMCStaticDir}/agt.d/logo/${LogoFile} ${OMCStaticDir}/logo;
fi
done
if ! id -u omc >/dev/null 2>&1 ; then
useradd -d /opt/omc -m -s /bin/bash -pomc123 omc;
mkdir -p /opt/omc/ftp
else
echo "user omc exist";
fi
if [ ! -e "${NginxConfDir}/omc.conf" ]; then
mkdir -p ${NginxConfDir}
cp -f ${OMCEtcDir}/nginx/omc.conf ${NginxConfDir};
fi
#cp -f ${OMCEtcDir}/nginx/default ${NginxSiteAvailable}
if [ -e "${NginxSiteAvailable}/default" ]; then
sed -i 's/listen 80 default_server;/listen 1080 default_server;/g' ${NginxSiteAvailable}/default
sed -i 's/listen \[::\]:80 default_server;/listen \[::\]:1080 default_server;/g' ${NginxSiteAvailable}/default
fi
# disable auto upgrade
systemctl disable --now unattended-upgrades
systemctl enable restagent.service
systemctl enable crontask.service
systemctl enable sshsvc.service
systemctl enable captrace.service
systemctl enable adb.service
systemctl daemon-reload
systemctl stop nginx.service
systemctl stop restagent.service
systemctl stop crontask.service
systemctl stop sshsvc.service
systemctl stop captrace.service
systemctl stop adb.service
systemctl start nginx.service
systemctl start adb.service
systemctl start crontask.service
systemctl start sshsvc.service
systemctl start captrace.service
systemctl start restagent.service