ref: 构建工具重构
This commit is contained in:
121
linux/usr/local/etc/omc/script/setup.sh
Normal file
121
linux/usr/local/etc/omc/script/setup.sh
Normal file
@@ -0,0 +1,121 @@
|
||||
#!/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
|
||||
}
|
||||
|
||||
# =========================
|
||||
|
||||
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_PARAM can only be 'standard' or 'lite'."
|
||||
exit 1
|
||||
fi
|
||||
sed -i "s/MODE=.*/MODE=${M_PARAM}/" $VariableFile
|
||||
sed -i "s/serverVersion: \"standard\"/serverVersion: \"${M_PARAM}\"/" $confFile
|
||||
sed -i "/database:/,/defaultDataSourceName:/s/\"standard\"/\"${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_PARAM can only be 'omc', 'agt' or 'ba'."
|
||||
exit 1
|
||||
fi
|
||||
sed -i "s/VENDORS=.*/VENDORS=${C_PARAM}/" $VariableFile
|
||||
VENDORS=$C_PARAM
|
||||
fi
|
||||
# echo "Customize parameter: $VENDORS"
|
||||
|
||||
# =========================
|
||||
if [[ "$T_PARAM" == "install" && "$MODE" == "standard" ]]; then
|
||||
if ! command -v mysql &> /dev/null && ! command -v mariadb &> /dev/null; then
|
||||
echo "MySQL or MariaDB not installed"
|
||||
exit 1
|
||||
fi
|
||||
rm -rf $OMCEtcDir/database/lite
|
||||
rm -rf $OMCEtcDir/default/omc_db.sqlite
|
||||
fi
|
||||
if [[ "$T_PARAM" == "install" && "$MODE" == "lite" ]]; then
|
||||
rm -rf $OMCEtcDir/database/standard
|
||||
cp -rf $OMCEtcDir/default/omc_db.sqlite $OMCEtcDir/database/omc_db.sqlite
|
||||
fi
|
||||
|
||||
# =========================
|
||||
$OMCBinFile -c $confFile --sqlPath $OMCEtcDir/database/$MODE/$T_PARAM --sqlSource $MODE
|
||||
|
||||
|
||||
# ========================= Customize
|
||||
if [[ "$T_PARAM" == "install" && -d $OMCEtcDir/vendor ]]; then
|
||||
cp -rf $OMCEtcDir/vendor/$VENDORS/web/* $OMCEtcDir/web/background
|
||||
cp -rf $OMCEtcDir/vendor/$VENDORS/static/* /usr/local/omc/static
|
||||
$OMCBinFile -c $confFile --sqlPath $OMCEtcDir/vendor/$VENDORS/database/$MODE --sqlSource $MODE
|
||||
fi
|
||||
|
||||
# bash setup.sh -i -m standard -c omc
|
||||
Reference in New Issue
Block a user