132 lines
3.4 KiB
Bash
132 lines
3.4 KiB
Bash
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
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=""
|
|
R_PARAM=false
|
|
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 " -r, --remote Specify the remote database"
|
|
echo " -m, --mode Available the mode (std/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
|
|
;;
|
|
-r|--remote)
|
|
R_PARAM=true
|
|
shift
|
|
;;
|
|
-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 std range
|
|
if [[ "$M_PARAM" != "std" && "$M_PARAM" != "lite" ]]; then
|
|
echo "Error: M_PARAM can only be 'std' or 'lite'."
|
|
exit 1
|
|
fi
|
|
sed -i "s/MODE=.*/MODE=${M_PARAM}/" $VariableFile
|
|
sed -i "s/serverVersion: \"std\"/serverVersion: \"${M_PARAM}\"/" $confFile
|
|
sed -i "/database:/,/defaultDataSourceName:/s/\"std\"/\"${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 omc/agt/ba range
|
|
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"
|
|
|
|
# ========================= Specify the mode pre-determination
|
|
if [[ "$T_PARAM" == "install" ]]; then
|
|
case "$MODE" in
|
|
std)
|
|
# Check if MySQL or MariaDB is installed when not a remote database
|
|
if [ "$R_PARAM" = false ]; then
|
|
if ! command -v mysql &>/dev/null && ! command -v mariadb &>/dev/null; then
|
|
echo "MySQL or MariaDB not installed"
|
|
exit 1
|
|
fi
|
|
fi
|
|
;;
|
|
lite)
|
|
cp -rf $OMCEtcDir/default/omc_db.sqlite $OMCEtcDir/database/omc_db.sqlite
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
|
|
# ========================= Execute the catalog sql file according to the schema
|
|
$OMCBinFile -c $confFile --sqlPath $OMCEtcDir/database/$MODE/$T_PARAM --sqlSource $MODE
|
|
|
|
|
|
# ========================= Customize
|
|
if [[ -d $OMCEtcDir/vendor ]]; then
|
|
if [[ "$T_PARAM" == "install" ]]; then
|
|
cp -rf $OMCEtcDir/vendor/$VENDORS/web/* $OMCEtcDir/web/background
|
|
cp -rf $OMCEtcDir/vendor/$VENDORS/static/* /usr/local/omc/static
|
|
fi
|
|
$OMCBinFile -c $confFile --sqlPath $OMCEtcDir/vendor/$VENDORS/database/$MODE/$T_PARAM --sqlSource $MODE
|
|
fi
|
|
|
|
# bash setup.sh -i -m std -c omc
|