#! /bin/bash # Rocky 9 compatible . /usr/src/m2/framework/bash_functions.sh # ---- VARS ----- VERSION="1.1.0" SCRIPT_NAME="Go Modules Check" k_start k_config_details GO_MODULES_INSTALL_DIR="/usr/local/m2" GO_MODULES_SRC_DIR="/usr/src/m2/scripts/go" ERROR_CODE=0 # Go module for DB server (with cron) GO_DB_MODULES_WITH_CRON=("m4_flat_rate_data" "m4_flat_rate_notifications" "m4_subscription_actions" "m4_subscriptions") # Go modules for DB server (without cron) - currently there are none # GO_DB_MODULES=() # Go modules for all servers (with cron) - currently there are none # GO_MODULES_WITH_CRON=() # Go modules for all servers (without cron) - currently there are none # GO_MODULES=() # Check if server is marked as DB is_db_server() { if [[ "$DB_PRESENT" == "1" ]] && [[ "$MAIN_DB" == "1" || "$MAIN_DB" == "-1" ]]; then echo 1 else echo 0 fi } # Check Go modules # Arguments # $1 - check condition (should modules/crons be present in this server?) # $2 - should we check crons? # $3 - modules array check_modules() { local check_condition="$1" local check_with_cron="$2" local check_array=(${@:3}) for m in "${check_array[@]}"; do err=0 if [ "$check_condition" == "1" ]; then # Check if module is present if [ ! -e $GO_MODULES_INSTALL_DIR/"$m" ]; then report "Go module $m is not present" 1 err=1 else # Compare installed module with src module from svn if ! cmp -s "$GO_MODULES_INSTALL_DIR/$m" "$GO_MODULES_SRC_DIR/bin/$m"; then report "Go module $m is outdated" 1 err=1 fi fi # Check if cronjobs present if [ "$check_with_cron" == "1" ]; then if [ ! -e /etc/cron.d/"$m" ]; then report "Cron $m is not present" 1 err=1 else # Compare cron file with svn if ! cmp -s "/etc/cron.d/$m" "$GO_MODULES_SRC_DIR/cron/$m"; then report "Cron $m is outdated" 1 err=1 fi fi fi else # Module and cron should not be present in this server if [ -e $GO_MODULES_INSTALL_DIR/"$m" ]; then report "Go module $m should not be present in this server" 1 err=1 fi if [ "$check_with_cron" == "1" ]; then if [ -e /etc/cron.d/"$m" ]; then report "Cron $m should not be present in this server" 1 err=1 fi fi fi if [ "$err" = "1" ]; then ERROR_CODE=1 else if [ "$check_condition" == "1" ]; then report "Go module $m and cron OK" 0 fi fi done } # Check Go modules for DB server with cron check_modules "$(is_db_server)" 1 "${GO_DB_MODULES_WITH_CRON[@]}" if [ "$ERROR_CODE" = "1" ]; then report " $GO_MODULES_SRC_DIR/go_modules_install.sh" fix EXIT_CODE=1 fi k_exit $EXIT_CODE