From 3f99f47fc474e55a9c178ffcd278eac8eb136d83 Mon Sep 17 00:00:00 2001 From: pi-farm Date: Fri, 26 Sep 2025 16:49:24 +0200 Subject: [PATCH] add functions for registry --- scripts/image-builder.sh | 108 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 100 insertions(+), 8 deletions(-) diff --git a/scripts/image-builder.sh b/scripts/image-builder.sh index 8ceb0c7..bbc75eb 100755 --- a/scripts/image-builder.sh +++ b/scripts/image-builder.sh @@ -5,6 +5,9 @@ IFS=$'\n\t' ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" CONFIG_DIR="$ROOT_DIR/config" GLOBAL_CONFIG="$CONFIG_DIR/global/config.json" +PROJECTS_DIR="./projects" +PROJECT_CONFIG_DIR="./config/projects" +REGISTRY_CONFIG_DIR="$CONFIG_DIR/registries" ensure_dirs() { mkdir -p "$CONFIG_DIR/global" "$CONFIG_DIR/projects" "$CONFIG_DIR/registries" "$ROOT_DIR/projects" @@ -190,9 +193,6 @@ set_editor() { # Projektverwaltung # =============================== -PROJECTS_DIR="./projects" -PROJECT_CONFIG_DIR="./config/projects" - # Hauptmenü Projektverwaltung project_menu() { while true; do @@ -324,7 +324,6 @@ change_project_setting() { sed -i "s|^$key=.*|$key=$new_value|" "$config_file" } -# Aktuellen Editor aus global/config.json holen # Aktuellen Editor aus global/config.json holen get_editor_cmd() { if [[ -f "$GLOBAL_CONFIG" ]]; then @@ -335,7 +334,6 @@ get_editor_cmd() { } # Projektdateien bearbeiten (Dateiauswahl + Editor) -# Projektdateien bearbeiten mit dialog-Dateimanager edit_project_files() { local project=$1 local project_dir="$PROJECTS_DIR/$project" @@ -359,7 +357,6 @@ edit_project_files() { "$editor_cmd" "$file" } - edit_project_architectures() { local config_file=$1 local current=$(grep "^architectures=" "$config_file" | cut -d= -f2 | tr ',' ' ') @@ -412,6 +409,101 @@ edit_project_auto_subversion() { fi } +# Hauptmenü - Registryverwaltung +registry_menu() { + while true; do + choice=$(whiptail --title "Registry-Verwaltung" --menu "Bitte wählen:" 20 70 10 \ + 1 "Registry erstellen" \ + 2 "Registry löschen" \ + 3 "Registry bearbeiten" \ + 0 "Zurück" \ + 3>&1 1>&2 2>&3) || return + + case $choice in + 1) create_registry ;; + 2) delete_registry ;; + 3) edit_registry ;; + 0) return ;; + esac + done +} + +# Registry anlegen +create_registry() { + local name url username password + + name=$(whiptail --inputbox "Name der Registry (z.B. docker.io):" 10 60 3>&1 1>&2 2>&3) || return + [ -z "$name" ] && return + + url=$(whiptail --inputbox "URL der Registry:" 10 60 3>&1 1>&2 2>&3) || return + username=$(whiptail --inputbox "Benutzername:" 10 60 3>&1 1>&2 2>&3) || return + password=$(whiptail --passwordbox "Passwort:" 10 60 3>&1 1>&2 2>&3) || return + + mkdir -p "$REGISTRY_CONFIG_DIR/$name" + cat > "$REGISTRY_CONFIG_DIR/$name/config-file" </dev/null) + [ -z "$registries" ] && { whiptail --msgbox "Keine Registries vorhanden." 10 60; return; } + + menu_list=() + for r in $registries; do + menu_list+=("$r" "") + done + + local reg + reg=$(whiptail --menu "Registry zum Löschen auswählen:" 20 60 10 "${menu_list[@]}" 3>&1 1>&2 2>&3) || return + + if whiptail --yesno "Registry $reg wirklich löschen?" 10 60; then + rm -rf "$REGISTRY_CONFIG_DIR/$reg" + whiptail --msgbox "Registry $reg wurde gelöscht." 10 60 + fi +} + +# Registry bearbeiten +edit_registry() { + local registries + registries=$(ls "$REGISTRY_CONFIG_DIR" 2>/dev/null) + [ -z "$registries" ] && { whiptail --msgbox "Keine Registries vorhanden." 10 60; return; } + + menu_list=() + for r in $registries; do + menu_list+=("$r" "") + done + + local reg + reg=$(whiptail --menu "Registry zum Bearbeiten auswählen:" 20 60 10 "${menu_list[@]}" 3>&1 1>&2 2>&3) || return + + local config_file="$REGISTRY_CONFIG_DIR/$reg/config-file" + local url username password + + url=$(grep "^url=" "$config_file" | cut -d= -f2) + username=$(grep "^username=" "$config_file" | cut -d= -f2) + password=$(grep "^password=" "$config_file" | cut -d= -f2) + + # Eingaben ändern + url=$(whiptail --inputbox "URL:" 10 60 "$url" 3>&1 1>&2 2>&3) || return + username=$(whiptail --inputbox "Benutzername:" 10 60 "$username" 3>&1 1>&2 2>&3) || return + password=$(whiptail --passwordbox "Passwort:" 10 60 "$password" 3>&1 1>&2 2>&3) || return + + cat > "$config_file" <