Tidy up functions.

This commit is contained in:
2026-07-23 23:30:25 +01:00
parent 4e1fb4b194
commit a3247cc783
+6 -26
View File
@@ -1,15 +1,6 @@
#!/usr/bin/env bash
# AMMIDS Shared Functions Library
# Location: init/scripts/functions.sh
# Sourced by all other scripts in this directory
# MIMIC Shared Functions Library
# Prevent direct execution
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "This is a library, not a script. Source it instead."
exit 1
fi
# --- Color Codes ---
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
@@ -17,10 +8,11 @@ BLUE='\033[0;34m'
TITLE='\033[38;2;17;97;2m'
NC='\033[0m'
# --- Path Resolution ---
# Standardised for project structure: /init/scripts/xxx.sh
# Sets: SCRIPT_DIR, INIT_DIR, ROOT_DIR
# --- Path Resolution ---
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "This is a library, not a script. Source it instead."
exit 1
fi
resolve_paths() {
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[1]}")" && pwd)"
@@ -40,12 +32,10 @@ resolve_paths() {
export SCRIPT_DIR INIT_DIR ROOT_DIR ENV_FILE COMPOSE_FILE
}
# --- Logging ---
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# --- State Management (init.ini) ---
write_state() {
local key="$1"
local value="$2"
@@ -95,7 +85,6 @@ clear_state() {
> "$init_file"
}
# --- Secrets ---
generate_secret() {
local length="${1:-32}"
if command -v openssl &> /dev/null; then
@@ -107,7 +96,6 @@ generate_secret() {
fi
}
# --- Interactive Prompts ---
prompt_var() {
local var_name="$1"
local prompt_text="$2"
@@ -160,9 +148,6 @@ auto_var() {
fi
}
# --- File Permissions ---
fix_ownership() {
local target="$1"
local uid="${2:-${USER_ID:-1000}}"
@@ -174,7 +159,6 @@ fix_ownership() {
fi
}
# --- Dependency Checks ---
require_command() {
local cmd="$1"
if ! command -v "$cmd" &> /dev/null; then
@@ -218,7 +202,6 @@ require_env() {
fi
}
# --- Volume Path Resolution ---
resolve_volume_path() {
VOLUME_PATH="${VOLUME_PATH:-./matrix}"
if [[ "$VOLUME_PATH" != /* ]]; then
@@ -227,9 +210,6 @@ resolve_volume_path() {
export VOLUME_PATH
}
# Add to functions.sh
quiet_echo() {
[[ "${QUIET_MODE:-0}" == "1" ]] || echo "$1"
}