add start.sh & image-builder.sh

This commit is contained in:
2025-09-23 23:45:07 +02:00
parent 4fd0a778ab
commit ee6b0c0a6a
2 changed files with 154 additions and 0 deletions

137
scripts/image-builder.sh Normal file
View File

@@ -0,0 +1,137 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
CONFIG_DIR="$ROOT_DIR/config"
GLOBAL_CONFIG="$CONFIG_DIR/global/config.json"
ensure_dirs() {
mkdir -p "$CONFIG_DIR/global" "$CONFIG_DIR/projects" "$CONFIG_DIR/registries" "$ROOT_DIR/projects"
if [[ ! -f "$GLOBAL_CONFIG" ]]; then
cat >"$GLOBAL_CONFIG" <<EOF
{
"editor": "nano"
}
EOF
fi
}
ensure_prereqs() {
local bins=("docker" "git" "jq" "whiptail")
for b in "${bins[@]}"; do
if ! command -v "$b" >/dev/null 2>&1; then
echo "[WARN] Benötigtes Programm fehlt: $b"
fi
done
}
# -------------------------
# Konfigurations-Menü
# -------------------------
config_menu() {
while true; do
choice=$(whiptail --title "Konfiguration" --menu "Bitte wählen:" 20 70 10 \
1 "Abhängigkeiten installieren (docker, git, jq, whiptail)" \
2 "Docker installieren & Buildx-Builder einrichten" \
3 "Globalen Editor setzen" \
0 "Zurück" \
3>&1 1>&2 2>&3) || return
case $choice in
1) install_dependencies;;
2) install_docker_and_buildx;;
3) set_editor;;
0) return;;
esac
done
}
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
}
install_docker_and_buildx() {
whiptail --msgbox "Docker Buildx-Builder wird eingerichtet..." 10 70
if ! docker buildx inspect multiarch-builder >/dev/null 2>&1; then
docker run --rm --privileged tonistiigi/binfmt --install all
docker buildx create --name multiarch-builder --use
docker buildx inspect --bootstrap
fi
whiptail --msgbox "Buildx-Builder eingerichtet." 10 70
}
set_editor() {
local editors=("nano" "vim" "micro" "nvim")
local options=()
declare -A editor_status
# Prüfe, ob Editor installiert ist
for e in "${editors[@]}"; do
if command -v "$e" >/dev/null 2>&1; then
editor_status[$e]="(installiert)"
else
editor_status[$e]="(nicht installiert)"
fi
options+=("$e" "${editor_status[$e]}")
done
while true; do
choice=$(whiptail --title "Editor wählen" --menu "Bitte Editor auswählen:" 20 70 10 "${options[@]}" 3>&1 1>&2 2>&3) || return
if command -v "$choice" >/dev/null 2>&1; then
jq --arg ed "$choice" '.editor = $ed' "$GLOBAL_CONFIG" >"$GLOBAL_CONFIG.tmp" && mv "$GLOBAL_CONFIG.tmp" "$GLOBAL_CONFIG"
whiptail --msgbox "Editor wurde auf '$choice' gesetzt." 10 60
return
else
install_choice=$(whiptail --title "Editor nicht installiert" \
--yesno "Der Editor '$choice' ist nicht installiert. Möchten Sie ihn jetzt installieren?" 10 60 3>&1 1>&2 2>&3)
if [[ $? -eq 0 ]]; then
whiptail --msgbox "Installation von $choice..." 8 50
sudo apt update
sudo apt install -y "$choice"
if command -v "$choice" >/dev/null 2>&1; then
whiptail --msgbox "$choice erfolgreich installiert." 8 50
jq --arg ed "$choice" '.editor = $ed' "$GLOBAL_CONFIG" >"$GLOBAL_CONFIG.tmp" && mv "$GLOBAL_CONFIG.tmp" "$GLOBAL_CONFIG"
return
else
whiptail --msgbox "Fehler: $choice konnte nicht installiert werden." 8 50
fi
fi
fi
done
}
# -------------------------
# Hauptmenü
# -------------------------
main_menu() {
while true; do
choice=$(whiptail --title "Image Builder" --menu "Bitte wählen:" 20 70 10 \
1 "Konfiguration" \
2 "Projektverwaltung" \
3 "Repository-Verwaltung" \
4 "Image-Bauen" \
5 "Image-Verwaltung" \
0 "Beenden" \
3>&1 1>&2 2>&3) || exit 0
case $choice in
1) config_menu;;
2) whiptail --msgbox "Projektverwaltung (noch nicht implementiert)" 10 70;;
3) whiptail --msgbox "Repository-Verwaltung (noch nicht implementiert)" 10 70;;
4) whiptail --msgbox "Image-Bauen (noch nicht implementiert)" 10 70;;
5) whiptail --msgbox "Image-Verwaltung (noch nicht implementiert)" 10 70;;
0) exit 0;;
esac
done
}
# -------------------------
# Main
# -------------------------
ensure_dirs
ensure_prereqs
main_menu

17
start.sh Normal file
View File

@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
# Root-Verzeichnis
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
SCRIPTS_DIR="$ROOT_DIR/scripts"
IMAGE_BUILDER="$SCRIPTS_DIR/image-builder.sh"
# Prüfen ob das Skript existiert
if [[ ! -f "$IMAGE_BUILDER" ]]; then
echo "[ERROR] $IMAGE_BUILDER nicht gefunden!"
exit 1
fi
# Script starten
"$IMAGE_BUILDER"