feat: rework entire repo structure

This commit is contained in:
2026-02-28 21:31:18 +01:00
parent 98ae07ae88
commit fcbfd3a838
12 changed files with 214 additions and 254 deletions

70
utils.sh Normal file
View File

@@ -0,0 +1,70 @@
#!/bin/bash
# UTILITY FUNCTIONS & CONFIGURATION
# This script acts as a library (utils.sh) for other monitoring scripts.
# It handles logging, environment variables, and Telegram notifications.
PROJECT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
readonly PROJECT_DIR 2>/dev/null
readonly PROJECT_NAME="serverconfig"
readonly REQ=("curl" "docker")
readonly ENV_FILE="${PROJECT_DIR}/.env"
readonly GREEN='\033[0;32m'
readonly RED='\033[0;31m'
readonly YELLOW='\033[1;33m'
readonly BLUE='\033[0;34m'
readonly NC='\033[0m'
DATETIME_FORMAT="%d-%m-%Y %H:%M:%S"
function log() {
local type="${1}"
local color="${2}"
local message="${3}"
echo -e "${color}[$(date +"$DATETIME_FORMAT")] [${type}]${NC} ${message}"
}
function log_info() { log "INFO" "$BLUE" "$1"; }
function log_success() { log "OK " "$GREEN" "$1"; }
function log_error() { log "ERR " "$RED" "$1" >&2; }
function log_warn() { log "WARN " "$YELLOW" "$1" >&2; }
# USING TELEGRAM (may change later)
function send_notification() {
local message="$1"
curl -X POST "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage" \
-d "chat_id=$TELEGRAM_CHAT_ID" \
-d "text=$message" \
-d "parse_mode=HTML"
}
function env_variable() {
source $ENV_FILE
local key="$1"
local value="$2"
if [[ -z "$value" ]]; then
log_warn "$key not set."
fi
if grep -Eq "^${key}=" "$ENV_FILE" 2>/dev/null; then
read -p "$key already set, overwrite? (y/N): " yn
case "$yn" in
[yY]*)
sed -i "s/^$key=.*/$key=$value/" "$ENV_FILE"
log_success "$key updated."
;;
*)
log_info "$key not changed."
;;
esac
else
echo "$key=$value" >> "$ENV_FILE"
log_success "$key created."
fi
}