From 2f5031cbd42b513dbe117bdcac1d6e2571999c3c Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Wed, 21 May 2025 10:20:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E8=BF=9C=E7=A8=8B=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E9=85=8D=E7=BD=AE=E5=92=8C=E4=BF=AE=E5=A4=8D=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- linux/usr/local/etc/omc/script/setup.sh | 17 +++++++++++------ pkg/deb/DEBIAN/postinst | 2 +- .../usr/local/etc/omc/script/entrypoint.sh | 4 ++-- .../usr/local/etc/omc/script/postunpack.sh | 9 ++++++--- pkg/docker/tar/omc-docker.sh | 6 ++---- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/linux/usr/local/etc/omc/script/setup.sh b/linux/usr/local/etc/omc/script/setup.sh index df2666d..a260cd0 100644 --- a/linux/usr/local/etc/omc/script/setup.sh +++ b/linux/usr/local/etc/omc/script/setup.sh @@ -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) diff --git a/pkg/deb/DEBIAN/postinst b/pkg/deb/DEBIAN/postinst index 420f917..9304d9e 100644 --- a/pkg/deb/DEBIAN/postinst +++ b/pkg/deb/DEBIAN/postinst @@ -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 diff --git a/pkg/docker/linux/usr/local/etc/omc/script/entrypoint.sh b/pkg/docker/linux/usr/local/etc/omc/script/entrypoint.sh index 003c6fe..6f7d046 100644 --- a/pkg/docker/linux/usr/local/etc/omc/script/entrypoint.sh +++ b/pkg/docker/linux/usr/local/etc/omc/script/entrypoint.sh @@ -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[@]}") diff --git a/pkg/docker/linux/usr/local/etc/omc/script/postunpack.sh b/pkg/docker/linux/usr/local/etc/omc/script/postunpack.sh index 14ed9de..d67aa5d 100644 --- a/pkg/docker/linux/usr/local/etc/omc/script/postunpack.sh +++ b/pkg/docker/linux/usr/local/etc/omc/script/postunpack.sh @@ -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 diff --git a/pkg/docker/tar/omc-docker.sh b/pkg/docker/tar/omc-docker.sh index d43ba5b..c7b2b59 100644 --- a/pkg/docker/tar/omc-docker.sh +++ b/pkg/docker/tar/omc-docker.sh @@ -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 \