Files
be.ems/build/linux/usr/local/etc/omc/script/setup.sh
2025-03-18 15:07:21 +08:00

126 lines
3.0 KiB
Bash

#!/bin/bash
OMCBinFile=/usr/local/bin/omc
OMCEtcDir=/usr/local/etc/omc
confFile=$OMCEtcDir/omc.yaml
VariableFile=$OMCEtcDir/omc.conf
# Read the value of the variable from file
source $VariableFile
# Initializing variables
T_PARAM=""
C_PARAM=""
M_PARAM=""
# usage
usage() {
echo "Usage: bash $0 [OPTION]"
echo
echo "Program Initialization OPTION:"
echo " -i, --install Specify the install"
echo " -u, --upgrade Specify the upgrade"
echo " -m, --mode Available the mode (standard/lite)"
echo " -c, --customize Available the customize (omc/agt/ba)"
echo " -h Display this help message"
echo
exit 1
}
# standard env
standardEnv() {
if command -v mysql &> /dev/null || command -v mariadb &> /dev/null; then
echo "MySQL or MariaDB installed"
else
echo "MySQL or MariaDB not installed"
exit 1
fi
}
# Different processing depending on the value of customize
customize() {
cp -rf $OMCEtcDir/vendor/$C_PARAM/web/* $OMCEtcDir/web/background
cp -rf $OMCEtcDir/vendor/$C_PARAM/static/* /usr/local/$C_PARAM/static
$OMCBinFile -c $confFile --sqlPath $OMCEtcDir/vendor/$C_PARAM/database/$DBSource/customized.sql --sqlSource $MODE
}
# =========================
# 参数解析
while [[ $# -gt 0 ]]; do
case "$1" in
-i|--install)
T_PARAM="install"
shift
;;
-u|--upgrade)
T_PARAM="upgrade"
shift
;;
-t|--type)
T_PARAM="$2"
shift 2 # 跳过 -t 参数和值
;;
-m|--mode)
M_PARAM="$2"
shift 2 # 跳过 -m 参数和值
;;
-c|--customize)
C_PARAM="$2"
shift 2 # 跳过 -c 参数和值
;;
-h)
usage
;;
*)
echo "Error: Unknown option: $1"
usage
;;
esac
done
# Make sure -i or -u comes first.
if [ -z "$T_PARAM" ]; then
echo "Error: You must specify -i (install) or -u (upgrade) first."
usage
fi
echo "Type parameter: $T_PARAM"
# Determine if -m is passed in
if [ -n "$M_PARAM" ]; then
# Check that mode is within the standard range
if [[ "$M_PARAM" != "standard" && "$M_PARAM" != "lite" ]]; then
echo "Error: -m can only be 'standard' or 'lite'."
exit 1
fi
echo "Mode parameter: $M_PARAM"
sed -i "s/MODE=.*/MODE=${M_PARAM}/" $VariableFile
sed -i "s/serverVersion: \"standard\"/serverVersion: \"${M_PARAM}\"/" $confFile
MODE=$M_PARAM
fi
echo "Mode parameter: $MODE"
# Determine if -c is passed in
if [ -n "$C_PARAM" ]; then
# Check if customize is within the standard
if [[ "$C_PARAM" != "omc" && "$C_PARAM" != "agt" && "$C_PARAM" != "ba" ]]; then
echo "Error: -c can only be 'omc', 'agt' or 'ba'."
exit 1
fi
echo "Customize parameter: $C_PARAM"
sed -i "s/VENDORS=.*/VENDORS=${C_PARAM}/" $VariableFile
VENDORS=$C_PARAM
fi
echo "Customize parameter: $VENDORS"
# =========================
if [ "$MODE" = "standard" ]; then
standardEnv
fi
$OMCBinFile -c $confFile --sqlPath $OMCEtcDir/database/$DBSource/$T_PARAM --sqlSource $MODE
customize
# bash setup.sh -i -m standard -c omc