From 37d1d7da2da0439f241c57c0a416d30ad420fb13 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Tue, 17 Jun 2025 16:40:07 +0200 Subject: [PATCH] Rework msg_functions for tool.func Pt. 1 --- misc/tools.func | 95 +++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 51 deletions(-) diff --git a/misc/tools.func b/misc/tools.func index 285d8df5..295ee4c2 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -22,7 +22,7 @@ function setup_nodejs() { if command -v node >/dev/null; then CURRENT_NODE_VERSION="$(node -v | grep -oP '^v\K[0-9]+')" if [[ "$CURRENT_NODE_VERSION" != "$NODE_VERSION" ]]; then - msg_info "Node.js $CURRENT_NODE_VERSION found, replacing with $NODE_VERSION" + msg_info "Old Node.js $CURRENT_NODE_VERSION found, replacing with $NODE_VERSION" NEED_NODE_INSTALL=true fi else @@ -31,9 +31,8 @@ function setup_nodejs() { fi if ! command -v jq &>/dev/null; then - $STD msg_info "Installing jq..." - $STD apt-get update -qq &>/dev/null - $STD apt-get install -y jq &>/dev/null || { + $STD apt-get update + $STD apt-get install -y jq || { msg_error "Failed to install jq" return 1 } @@ -104,8 +103,6 @@ function setup_nodejs() { msg_error "Failed to update $MODULE_NAME to latest version" exit 1 fi - else - msg_ok "$MODULE_NAME@$MODULE_INSTALLED_VERSION already installed" fi else msg_info "Installing $MODULE_NAME@$MODULE_REQ_VERSION" @@ -115,7 +112,7 @@ function setup_nodejs() { fi fi done - msg_ok "Setup Node.js" + msg_ok "Installed Node.js modules: $NODE_MODULE" fi } @@ -144,7 +141,7 @@ function setup_postgresql() { if command -v psql >/dev/null; then CURRENT_PG_VERSION="$(psql -V | awk '{print $3}' | cut -d. -f1)" if [[ "$CURRENT_PG_VERSION" == "$PG_VERSION" ]]; then - msg_ok "PostgreSQL $PG_VERSION is already installed" + : # PostgreSQL is already at the desired version – no action needed else msg_info "Detected PostgreSQL $CURRENT_PG_VERSION, preparing upgrade to $PG_VERSION" NEED_PG_INSTALL=true @@ -156,39 +153,41 @@ function setup_postgresql() { if [[ "$NEED_PG_INSTALL" == true ]]; then if [[ -n "$CURRENT_PG_VERSION" ]]; then - msg_info "Dumping all PostgreSQL data from version $CURRENT_PG_VERSION" + msg_info "Dumping PostgreSQL $CURRENT_PG_VERSION data" su - postgres -c "pg_dumpall > /var/lib/postgresql/backup_$(date +%F)_v${CURRENT_PG_VERSION}.sql" + msg_ok "Data dump completed" - msg_info "Stopping PostgreSQL service" systemctl stop postgresql fi - msg_info "Removing pgdg repo and old GPG key" rm -f /etc/apt/sources.list.d/pgdg.list /etc/apt/trusted.gpg.d/postgresql.gpg - msg_info "Adding PostgreSQL PGDG repository" + $STD msg_info "Adding PostgreSQL PGDG repository" curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg echo "deb https://apt.postgresql.org/pub/repos/apt ${DISTRO}-pgdg main" \ >/etc/apt/sources.list.d/pgdg.list + $STD msg_ok "Repository added" $STD apt-get update - msg_info "Installing PostgreSQL $PG_VERSION" + msg_info "Setup PostgreSQL $PG_VERSION" $STD apt-get install -y "postgresql-${PG_VERSION}" "postgresql-client-${PG_VERSION}" + msg_ok "Setup PostgreSQL $PG_VERSION" if [[ -n "$CURRENT_PG_VERSION" ]]; then - msg_info "Removing old PostgreSQL $CURRENT_PG_VERSION packages" $STD apt-get purge -y "postgresql-${CURRENT_PG_VERSION}" "postgresql-client-${CURRENT_PG_VERSION}" || true fi - msg_info "Starting PostgreSQL $PG_VERSION" + $STD msg_info "Starting PostgreSQL $PG_VERSION" systemctl enable -q --now postgresql + $STD msg_ok "PostgreSQL $PG_VERSION started" if [[ -n "$CURRENT_PG_VERSION" ]]; then msg_info "Restoring dumped data" su - postgres -c "psql < /var/lib/postgresql/backup_$(date +%F)_v${CURRENT_PG_VERSION}.sql" + msg_ok "Data restored" fi msg_ok "PostgreSQL $PG_VERSION installed" @@ -199,13 +198,13 @@ function setup_postgresql() { IFS=',' read -ra MODULES <<<"$PG_MODULES" for module in "${MODULES[@]}"; do local pkg="postgresql-${PG_VERSION}-${module}" - msg_info "Installing PostgreSQL module: $pkg" + msg_info "Setup PostgreSQL module/s: $pkg" $STD apt-get install -y "$pkg" || { msg_error "Failed to install $pkg" continue } done - msg_ok "All requested PostgreSQL modules installed" + msg_ok "Setup PostgreSQL modules" fi } @@ -226,6 +225,7 @@ function setup_mariadb() { local DISTRO_CODENAME DISTRO_CODENAME="$(awk -F= '/^VERSION_CODENAME=/{print $2}' /etc/os-release)" + msg_info "Setting up MariaDB $MARIADB_VERSION" # grab dynamic latest LTS version if [[ "$MARIADB_VERSION" == "latest" ]]; then $STD msg_info "Resolving latest GA MariaDB version" @@ -256,12 +256,12 @@ function setup_mariadb() { fi if [[ -n "$CURRENT_VERSION" ]]; then - $STD msg_info "Replacing MariaDB $CURRENT_VERSION with $MARIADB_VERSION (data will be preserved)" + $STD msg_info "Upgrading MariaDB $CURRENT_VERSION to $MARIADB_VERSION" $STD systemctl stop mariadb >/dev/null 2>&1 || true $STD apt-get purge -y 'mariadb*' || true rm -f /etc/apt/sources.list.d/mariadb.list /etc/apt/trusted.gpg.d/mariadb.gpg else - msg_info "Setup MariaDB $MARIADB_VERSION" + $STD msg_info "Setup MariaDB $MARIADB_VERSION" fi $STD msg_info "Setting up MariaDB Repository" @@ -297,25 +297,25 @@ function setup_mysql() { if command -v mysql >/dev/null; then CURRENT_VERSION="$(mysql --version | grep -oP 'Distrib\s+\K[0-9]+\.[0-9]+')" if [[ "$CURRENT_VERSION" != "$MYSQL_VERSION" ]]; then - msg_info "MySQL $CURRENT_VERSION found, replacing with $MYSQL_VERSION" + $STD msg_info "MySQL $CURRENT_VERSION will be upgraded to $MYSQL_VERSION" NEED_INSTALL=true else # Check for patch-level updates if apt list --upgradable 2>/dev/null | grep -q '^mysql-server/'; then - msg_info "MySQL $CURRENT_VERSION available for upgrade" + $STD msg_info "MySQL $CURRENT_VERSION available for upgrade" $STD apt-get update $STD apt-get install --only-upgrade -y mysql-server - msg_ok "MySQL upgraded" + $STD msg_ok "MySQL upgraded" fi return fi else - msg_info "Installing MySQL $MYSQL_VERSION" + msg_info "Setup MySQL $MYSQL_VERSION" NEED_INSTALL=true fi if [[ "$NEED_INSTALL" == true ]]; then - $STD systemctl stop mysql >/dev/null 2>&1 || true + $STD systemctl stop mysql || true $STD apt-get purge -y "^mysql-server.*" "^mysql-client.*" "^mysql-common.*" || true rm -f /etc/apt/sources.list.d/mysql.list /etc/apt/trusted.gpg.d/mysql.gpg @@ -328,7 +328,7 @@ function setup_mysql() { export DEBIAN_FRONTEND=noninteractive $STD apt-get update $STD apt-get install -y mysql-server - msg_ok "Installed MySQL $MYSQL_VERSION" + msg_ok "Setup MySQL $MYSQL_VERSION" fi } @@ -402,9 +402,9 @@ function setup_php() { fi if [[ -z "$CURRENT_PHP" ]]; then - msg_info "No PHP found, setting up PHP $PHP_VERSION" + msg_info "Setup PHP $PHP_VERSION" elif [[ "$CURRENT_PHP" != "$PHP_VERSION" ]]; then - msg_info "PHP $CURRENT_PHP detected, migrating to PHP $PHP_VERSION" + msg_info "Old PHP $CURRENT_PHP detected, Setup new PHP $PHP_VERSION" $STD apt-get purge -y "php${CURRENT_PHP//./}"* || true fi @@ -439,7 +439,7 @@ function setup_php() { fi $STD apt-get install -y $MODULE_LIST - msg_ok "Installed PHP $PHP_VERSION with selected modules" + msg_ok "Setup PHP $PHP_VERSION" if [[ "$PHP_APACHE" == "YES" ]]; then $STD systemctl restart apache2 || true @@ -483,7 +483,7 @@ function setup_composer() { if [[ -x "$COMPOSER_BIN" ]]; then local CURRENT_VERSION CURRENT_VERSION=$("$COMPOSER_BIN" --version | awk '{print $3}') - $STD msg_info "Composer $CURRENT_VERSION found, updating to latest" + $STD msg_info "Old Composer $CURRENT_VERSION found, updating to latest" else msg_info "Setup Composer" fi @@ -500,7 +500,6 @@ function setup_composer() { chmod +x "$COMPOSER_BIN" composer diagnose >/dev/null 2>&1 msg_ok "Setup Composer" - #msg_ok "Installed Composer $($COMPOSER_BIN --version | awk '{print $3}')" } # ------------------------------------------------------------------------------ @@ -532,7 +531,6 @@ function setup_go() { msg_error "Could not determine latest Go version" return 1 fi - $STD msg_info "Detected latest Go version: $GO_VERSION" fi local GO_BIN="/usr/local/bin/go" @@ -542,14 +540,13 @@ function setup_go() { local CURRENT_VERSION CURRENT_VERSION=$("$GO_BIN" version | awk '{print $3}' | sed 's/go//') if [[ "$CURRENT_VERSION" == "$GO_VERSION" ]]; then - $STD msg_ok "Go $GO_VERSION already installed" return 0 else - $STD msg_info "Go $CURRENT_VERSION found, upgrading to $GO_VERSION" + $STD msg_info "Old Go Installation ($CURRENT_VERSION) found, upgrading to $GO_VERSION" rm -rf "$GO_INSTALL_DIR" fi else - msg_info "Installing Go $GO_VERSION" + msg_info "Setup Go $GO_VERSION" fi local TARBALL="go${GO_VERSION}.linux-${ARCH}.tar.gz" @@ -566,7 +563,7 @@ function setup_go() { ln -sf /usr/local/go/bin/gofmt /usr/local/bin/gofmt rm -f "$TMP_TAR" - msg_ok "Installed Go $GO_VERSION" + msg_ok "Setup Go $GO_VERSION" } # ------------------------------------------------------------------------------ @@ -588,13 +585,13 @@ function setup_java() { # Add Adoptium repo if missing if [[ ! -f /etc/apt/sources.list.d/adoptium.list ]]; then - msg_info "Setting up Adoptium Repository" + $STD msg_info "Setting up Adoptium Repository" mkdir -p /etc/apt/keyrings curl -fsSL "https://packages.adoptium.net/artifactory/api/gpg/key/public" | gpg --dearmor -o /etc/apt/trusted.gpg.d/adoptium.gpg echo "deb [signed-by=/etc/apt/trusted.gpg.d/adoptium.gpg] https://packages.adoptium.net/artifactory/deb ${DISTRO_CODENAME} main" \ >/etc/apt/sources.list.d/adoptium.list $STD apt-get update - msg_ok "Set up Adoptium Repository" + $STD msg_ok "Set up Adoptium Repository" fi # Detect currently installed temurin version @@ -604,19 +601,19 @@ function setup_java() { fi if [[ "$INSTALLED_VERSION" == "$JAVA_VERSION" ]]; then - msg_info "Temurin JDK $JAVA_VERSION already installed, updating if needed" + $STD msg_info "Upgrading Temurin JDK $JAVA_VERSION" $STD apt-get update $STD apt-get install --only-upgrade -y "$DESIRED_PACKAGE" - msg_ok "Updated Temurin JDK $JAVA_VERSION (if applicable)" + $STD msg_ok "Upgraded Temurin JDK $JAVA_VERSION" else if [[ -n "$INSTALLED_VERSION" ]]; then - msg_info "Removing Temurin JDK $INSTALLED_VERSION" + $STD msg_info "Removing Temurin JDK $INSTALLED_VERSION" $STD apt-get purge -y "temurin-${INSTALLED_VERSION}-jdk" fi - msg_info "Installing Temurin JDK $JAVA_VERSION" + msg_info "Setup Temurin JDK $JAVA_VERSION" $STD apt-get install -y "$DESIRED_PACKAGE" - msg_ok "Installed Temurin JDK $JAVA_VERSION" + msg_ok "Setup Temurin JDK $JAVA_VERSION" fi } @@ -654,21 +651,20 @@ function setup_mongodb() { fi if [[ "$INSTALLED_VERSION" == "$MONGO_VERSION" ]]; then - msg_info "MongoDB $MONGO_VERSION already installed, checking for upgrade" + $STD msg_info "Upgrading MongoDB $MONGO_VERSION" $STD apt-get update $STD apt-get install --only-upgrade -y mongodb-org - msg_ok "MongoDB $MONGO_VERSION upgraded if needed" + $STD msg_ok "Upgraded MongoDB $MONGO_VERSION" return 0 fi if [[ -n "$INSTALLED_VERSION" ]]; then - msg_info "Replacing MongoDB $INSTALLED_VERSION with $MONGO_VERSION (data will be preserved)" $STD systemctl stop mongod || true $STD apt-get purge -y mongodb-org || true rm -f /etc/apt/sources.list.d/mongodb-org-*.list rm -f /etc/apt/trusted.gpg.d/mongodb-*.gpg else - msg_info "Installing MongoDB $MONGO_VERSION" + msg_info "Setup MongoDB $MONGO_VERSION" fi curl -fsSL "https://pgp.mongodb.com/server-${MONGO_VERSION}.asc" | gpg --dearmor -o "/etc/apt/trusted.gpg.d/mongodb-${MONGO_VERSION}.gpg" @@ -687,7 +683,7 @@ function setup_mongodb() { $STD systemctl enable mongod $STD systemctl start mongod - msg_ok "MongoDB $MONGO_VERSION installed and started" + msg_ok "Setup MongoDB $MONGO_VERSION" } # ------------------------------------------------------------------------------ @@ -752,7 +748,6 @@ function fetch_and_deploy_gh_release() { fi if ! command -v jq &>/dev/null; then - $STD msg_info "Installing jq..." $STD apt-get install -y jq &>/dev/null fi @@ -776,12 +771,10 @@ function fetch_and_deploy_gh_release() { [[ "$tag_name" =~ ^v ]] && version="${tag_name:1}" || version="$tag_name" if [[ "$current_version" == "$version" ]]; then - $STD msg_info "$app is already up-to-date (v$version)" + $STD msg_ok "$app is already up-to-date (v$version)" return 0 fi - $STD msg_info "Preparing to deploy $app v$version (mode: $mode)..." - local tmpdir tmpdir=$(mktemp -d) || return 1 local filename="" url=""