1
0

fix: 更新脚本以支持远程数据库配置和修复文件路径

This commit is contained in:
TsMask
2025-05-21 10:20:02 +08:00
parent 46bc90c2e4
commit 2f5031cbd4
5 changed files with 22 additions and 16 deletions

View File

@@ -9,6 +9,7 @@ source $VariableFile
# Initializing variables
T_PARAM=""
R_PARAM=false
C_PARAM=""
M_PARAM=""
@@ -19,6 +20,7 @@ usage() {
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"
@@ -38,9 +40,9 @@ while [[ $# -gt 0 ]]; do
T_PARAM="upgrade"
shift
;;
-t|--type)
T_PARAM="$2"
shift 2 # 跳过 -t 参数和值
-r|--remote)
R_PARAM=true
shift
;;
-m|--mode)
M_PARAM="$2"
@@ -97,9 +99,12 @@ fi
if [[ "$T_PARAM" == "install" ]]; then
case "$MODE" in
std)
if ! command -v mysql &>/dev/null && ! command -v mariadb &>/dev/null; then
echo "MySQL or MariaDB not installed"
exit 1
# 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)

View File

@@ -10,7 +10,7 @@ echo " sudo systemctl start|stop|status|restart omc.service"
echo ""
# Check if this is the first installation or upgrade
if [ ! -f $RootDir/omc.conf ]; then
if [ ! -f $RootDir/machine.ini ]; then
# First installation, perform the related operations
chmod +rx /usr/local/bin/omc
cp $RootDir/default/omc.conf $RootDir/omc.conf

View File

@@ -16,14 +16,14 @@ cp -nr "$BASE_DIR"/default/. "$BASE_DIR"
# Initialize OMC DB
if [ ! -f /usr/local/etc/omc/machine.ini ]; then
bash /usr/local/etc/omc/script/setup.sh -i -m $M_PARAM -c $C_PARAM
bash /usr/local/etc/omc/script/setup.sh -i -r -m $M_PARAM -c $C_PARAM
fi
# Start Nginx server
nginx -g "daemon off;"
# Parse CLI flags to pass to the 'omc' call
args=("--config" "${BASE_DIR}/omc.conf")
args=("--config" "${BASE_DIR}/omc.yaml")
# Add flags specified via the 'CMD_EXTRA_FLAGS' environment variable
read -r -a extra_flags <<< "$CMD_EXTRA_FLAGS"
[[ "${#extra_flags[@]}" -gt 0 ]] && args+=("${extra_flags[@]}")

View File

@@ -10,11 +10,14 @@ set -o pipefail
. /usr/local/etc/omc/script/omc-env.sh
chmod -R g+rwX "$BASE_DIR" "$DATA_DIR"
chmod +rx /usr/local/bin/omc
# We add the copy from default config in the entrypoint to not break users
# bypassing the setup.sh logic. If the file already exists do not overwrite (in
# case someone mounts a configuration file in /usr/local/etc/omc/default)
cp -rf /usr/local/etc/omc/default/* "$BASE_DIR"
cp $BASE_DIR/default/omc.conf $BASE_DIR/omc.conf
cp $BASE_DIR/default/omc.yaml $BASE_DIR/omc.yaml
# cp $BASE_DIR/default/sshsvc.yaml $BASE_DIR/sshsvc.yaml
# OMC config
sed -i "s/port: 33030/port: $API_HTTP_PORT/" "$BASE_DIR"/omc.yaml
@@ -22,13 +25,13 @@ sed -i "s/port: 33443/port: $API_HTTPS_PORT/" "$BASE_DIR"/omc.yaml
sed -i '/webServer:/,/-/s/^\( *enabled:\) true/\1 false/' "$BASE_DIR"/omc.yaml
sed -i '/type: "mysql"/,/-/s/^\( *host:\) "127.0.0.1"/\1 "omc_mariadb"/' "$BASE_DIR"/omc.yaml
sed -i 's/port: 33066/port: 3306/' "$BASE_DIR"/omc.yaml
sed -i '/port: 6379 # Redis port/,/-/s/^\( *host:\) "127.0.0.1"/\1 "omc_keydb"/' "$BASE_DIR"/omc.yaml
sed -i '/port: 6379 # Redis port/ {n; s/host: "127.0.0.1"/host: "omc_keydb"/}' "$BASE_DIR"/omc.yaml
# Nginx config
sed -i 's/# gzip_/gzip_/' /etc/nginx/nginx.conf
sed -i 's/include \/etc\/nginx\/sites-enabled/# include \/etc\/nginx\/sites-enabled/' /etc/nginx/nginx.conf
cp -rf /usr/local/etc/omc/nginx/omc.conf /etc/nginx/conf.d
touch /usr/local/etc/omc/web/dist/config.js && echo 'sessionStorage.clear()' | tee /web/dist/config.js
touch /usr/local/etc/omc/web/config.js && echo 'sessionStorage.clear()' | tee /usr/local/etc/omc/web/config.js
sed -i "s/33030;/$API_HTTP_PORT;/" /etc/nginx/conf.d/omc.conf
sed -i "s/33443;/$API_HTTPS_PORT;/" /etc/nginx/conf.d/omc.conf
sed -i "s/80;/$WEB_HTTP_PORT;/" /etc/nginx/conf.d/omc.conf

View File

@@ -62,13 +62,11 @@ install(){
docker load --input $(pwd)/tar/mariadb_10.6.21_{arch}.tar
MYSQL_IMAGE="mariadb-{arch}:10.6.21"
MYSQL_ROOT_PASSWORD="1000omc@kp!"
# SQL_FILE_PATH="$(pwd)/sql/install/omc_db.sql"
MYSQL_DATA=/usr/local/etc/$MYSQL_CONTAINER_NAME/data
mkdir -p $MYSQL_DATA && chmod 777 $MYSQL_DATA
echo "CREATE DATABASE IF NOT EXISTS omc_db;" >> $MYSQL_DATA/database.sql
docker run --privileged=true --restart=always -e TZ="$OMC_TZ" \
-e MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD \
-v $SQL_FILE_PATH:/docker-entrypoint-initdb.d/database.sql \
-e MARIADB_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD \
-e MARIADB_DATABASE=omc_db \
-v $MYSQL_DATA:/var/lib/mysql \
--network $NETWORK \
--name $MYSQL_CONTAINER_NAME \