From e2656affd43f2afd3e562c22f6f21b0d800345e5 Mon Sep 17 00:00:00 2001 From: pi-farm Date: Fri, 26 Sep 2025 17:44:48 +0200 Subject: [PATCH] edit function create_project to use default registry --- scripts/image-builder.sh | 62 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/scripts/image-builder.sh b/scripts/image-builder.sh index 25e2bc8..84bd161 100755 --- a/scripts/image-builder.sh +++ b/scripts/image-builder.sh @@ -52,6 +52,7 @@ config_menu() { 1 "Abhängigkeiten installieren (docker, git, jq, whiptail)" \ 2 "Buildx-Builder einrichten | Status: $builder_icon" \ 3 "Globalen Editor setzen" \ + 4 "Standard-Registry setzen" \ 0 "Zurück" \ 3>&1 1>&2 2>&3) || return @@ -59,11 +60,13 @@ config_menu() { 1) install_dependencies;; 2) install_docker_and_buildx;; 3) set_editor;; + 4) set_default_registry ;; 0) return;; esac done } +# BuildX-Builder Status Icon get_builder_status_icon() { if docker buildx ls 2>/dev/null | grep -q "multiarch-builder"; then if docker buildx ls | grep "multiarch-builder" | grep -q "running"; then @@ -76,6 +79,7 @@ get_builder_status_icon() { fi } +# BuildX-Builder-Status abrufen get_builder_status() { if docker buildx ls 2>/dev/null | grep -q "multiarch-builder"; then if docker buildx ls | grep "multiarch-builder" | grep -q "running"; then @@ -88,12 +92,14 @@ get_builder_status() { fi } +# Abhängigkeiten installieren install_dependencies() { whiptail --msgbox "Installation von Abhängigkeiten (Beispiel für Debian/Ubuntu). Bitte root-Rechte eingeben." 10 70 sudo apt update sudo apt install -y docker.io git jq whiptail micro } +# BuildX-Builder einrichten install_docker_and_buildx() { # Prüfen ob Docker installiert ist if ! command -v docker >/dev/null 2>&1; then @@ -126,6 +132,7 @@ install_docker_and_buildx() { fi } +# Standard Editor setzen set_editor() { # editor -> paketname declare -A editor_pkg @@ -188,7 +195,43 @@ set_editor() { done } +# Standard-Registry setzen +set_default_registry() { + # Alle verfügbaren Registries auslesen + local registries + registries=$(ls "$REGISTRY_CONFIG_DIR" 2>/dev/null) + [ -z "$registries" ] && { whiptail --msgbox "Keine Registries verfügbar. Bitte zuerst eine Registry erstellen." 10 60; return; } + # Menü-Liste vorbereiten + local menu_list=() + for r in $registries; do + menu_list+=("$r" "$r") + done + + # Aktuelle Default-Registry auslesen + local current + current=$(jq -r '.default_registry // ""' "$GLOBAL_CONFIG") + + # Auswahl per Whiptail + local choice + choice=$(whiptail --title "Standard-Registry wählen" \ + --menu "Bitte Standard-Registry auswählen:" 20 70 10 \ + "${menu_list[@]}" 3>&1 1>&2 2>&3) || return + + # Speichern in global/config.json + jq --arg reg "$choice" '.default_registry = $reg' "$GLOBAL_CONFIG" >"$GLOBAL_CONFIG.tmp" && mv "$GLOBAL_CONFIG.tmp" "$GLOBAL_CONFIG" + + whiptail --msgbox "Standard-Registry auf '$choice' gesetzt." 10 60 +} + +# Standard-Registry auslesen +get_default_registry() { + if [[ -f "$GLOBAL_CONFIG" ]]; then + jq -r '.default_registry // ""' "$GLOBAL_CONFIG" + else + echo "" + fi +} # =============================== # Projektverwaltung # =============================== @@ -219,15 +262,19 @@ create_project() { mkdir -p "$PROJECT_CONFIG_DIR/$project_name" "$PROJECTS_DIR/$project_name" + # Standardwerte setzen + default_registry=$(get_default_registry) + # Default Config-File cat > "$PROJECT_CONFIG_DIR/$project_name/config-file" <&1 1>&2 2>&3) || return if git clone "$repo_url" "$PROJECTS_DIR/$project_name"; then - echo "git_repo=$repo_url" >> "$PROJECT_CONFIG_DIR/$project_name/config-file" + sed -i "s|^git_repo=.*|git_repo=$repo_url|" "$PROJECT_CONFIG_DIR/$project_name/config-file" else whiptail --msgbox "Fehler beim Klonen des Git-Repos!" 10 60 fi else echo -e "FROM debian:bookworm-slim\nCMD echo 'Hello from $project_name'" > "$PROJECTS_DIR/$project_name/Dockerfile" fi - + whiptail --msgbox "Projekt $project_name wurde erstellt." 10 60 } @@ -321,17 +368,24 @@ edit_project_registries() { # aktuelle registries im Projekt auslesen local current=$(grep "^registry=" "$config_file" 2>/dev/null | cut -d= -f2 | tr ',' ' ') - + # alle registries aus Registry-Verwaltung local all_registries all_registries=$(ls "$REGISTRY_CONFIG_DIR" 2>/dev/null) [ -z "$all_registries" ] && { whiptail --msgbox "Keine Registries verfügbar. Bitte zuerst eine Registry erstellen." 10 60; return; } + # Default-Registry aus globaler Config + local default_registry + default_registry=$(get_default_registry) + # menu_list für whiptail vorbereiten local menu_list=() for r in $all_registries; do if [[ " $current " =~ " $r " ]]; then menu_list+=("$r" "$r" ON) + elif [[ -z "$current" && "$r" == "$default_registry" ]]; then + # Projekt hat noch keine registries, Default wird ON + menu_list+=("$r" "$r" ON) else menu_list+=("$r" "$r" OFF) fi