add menu and functions Projektverwaltung
This commit is contained in:
@@ -156,6 +156,146 @@ set_editor() {
|
||||
done
|
||||
}
|
||||
|
||||
# ===============================
|
||||
# Projektverwaltung
|
||||
# ===============================
|
||||
|
||||
PROJECTS_DIR="./projects"
|
||||
PROJECT_CONFIG_DIR="./config/projects"
|
||||
|
||||
# Hauptmenü Projektverwaltung
|
||||
project_menu() {
|
||||
while true; do
|
||||
choice=$(whiptail --title "Projektverwaltung" --menu "Bitte wählen:" 20 70 10 \
|
||||
1 "Projekt erstellen" \
|
||||
2 "Projekt löschen" \
|
||||
3 "Projekt bearbeiten" \
|
||||
0 "Zurück" \
|
||||
3>&1 1>&2 2>&3) || return
|
||||
|
||||
case $choice in
|
||||
1) create_project ;;
|
||||
2) delete_project ;;
|
||||
3) edit_project ;;
|
||||
0) return ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Neues Projekt anlegen
|
||||
create_project() {
|
||||
project_name=$(whiptail --inputbox "Projektname eingeben:" 10 60 3>&1 1>&2 2>&3) || return
|
||||
[ -z "$project_name" ] && return
|
||||
|
||||
mkdir -p "$PROJECT_CONFIG_DIR/$project_name" "$PROJECTS_DIR/$project_name"
|
||||
|
||||
# Default Config-File
|
||||
cat > "$PROJECT_CONFIG_DIR/$project_name/config-file" <<EOF
|
||||
# Projektkonfiguration für $project_name
|
||||
registry=docker.io
|
||||
image_name=$project_name
|
||||
architectures=amd64
|
||||
push=yes
|
||||
version=1.0
|
||||
latest=yes
|
||||
git_repo=
|
||||
EOF
|
||||
|
||||
# Dockerfile oder Git-Repo
|
||||
if whiptail --yesno "Soll ein Git-Repo geklont werden?" 10 60; then
|
||||
repo_url=$(whiptail --inputbox "Git-Repository-URL eingeben:" 10 60 3>&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"
|
||||
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
|
||||
}
|
||||
|
||||
# Projekt löschen
|
||||
delete_project() {
|
||||
projects=$(ls "$PROJECT_CONFIG_DIR" 2>/dev/null)
|
||||
[ -z "$projects" ] && { whiptail --msgbox "Keine Projekte vorhanden." 10 60; return; }
|
||||
|
||||
project=$(whiptail --menu "Projekt zum Löschen auswählen:" 20 60 10 $projects 3>&1 1>&2 2>&3) || return
|
||||
|
||||
if whiptail --yesno "Projekt $project wirklich löschen?" 10 60; then
|
||||
rm -rf "$PROJECT_CONFIG_DIR/$project" "$PROJECTS_DIR/$project"
|
||||
whiptail --msgbox "Projekt $project wurde gelöscht." 10 60
|
||||
fi
|
||||
}
|
||||
|
||||
# Projekt bearbeiten
|
||||
edit_project() {
|
||||
projects=$(ls "$PROJECT_CONFIG_DIR" 2>/dev/null)
|
||||
[ -z "$projects" ] && { whiptail --msgbox "Keine Projekte vorhanden." 10 60; return; }
|
||||
|
||||
project=$(whiptail --menu "Projekt auswählen:" 20 60 10 $projects 3>&1 1>&2 2>&3) || return
|
||||
local config_file="$PROJECT_CONFIG_DIR/$project/config-file"
|
||||
|
||||
while true; do
|
||||
repo_url=$(grep "^git_repo=" "$config_file" | cut -d= -f2)
|
||||
|
||||
menu_items=(
|
||||
1 "Registry ändern"
|
||||
2 "Image-Name ändern"
|
||||
3 "Architekturen setzen"
|
||||
4 "Push-Option setzen"
|
||||
5 "Version/Subversion ändern"
|
||||
6 "Latest-Tag setzen"
|
||||
7 "Projektdateien bearbeiten"
|
||||
)
|
||||
|
||||
[ -n "$repo_url" ] && menu_items+=("8" "Git Pull")
|
||||
|
||||
menu_items+=("0" "Zurück")
|
||||
|
||||
choice=$(whiptail --title "Projekt bearbeiten: $project" \
|
||||
--menu "Bitte wählen:" 20 70 12 \
|
||||
"${menu_items[@]}" \
|
||||
3>&1 1>&2 2>&3) || return
|
||||
|
||||
case $choice in
|
||||
1) change_project_setting "$config_file" "registry" ;;
|
||||
2) change_project_setting "$config_file" "image_name" ;;
|
||||
3) change_project_setting "$config_file" "architectures" ;;
|
||||
4) change_project_setting "$config_file" "push" ;;
|
||||
5) change_project_setting "$config_file" "version" ;;
|
||||
6) change_project_setting "$config_file" "latest" ;;
|
||||
7) edit_project_files "$project" ;;
|
||||
8) [ -n "$repo_url" ] && (cd "$PROJECTS_DIR/$project" && git pull || whiptail --msgbox "Git Pull fehlgeschlagen." 10 60) ;;
|
||||
0) return ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Schlüssel im Config-File ändern
|
||||
change_project_setting() {
|
||||
local config_file=$1
|
||||
local key=$2
|
||||
local current=$(grep "^$key=" "$config_file" | cut -d= -f2)
|
||||
new_value=$(whiptail --inputbox "$key ändern (aktuell: $current)" 10 60 "$current" 3>&1 1>&2 2>&3) || return
|
||||
sed -i "s|^$key=.*|$key=$new_value|" "$config_file"
|
||||
}
|
||||
|
||||
# Projektdateien bearbeiten (Dateiauswahl + Editor)
|
||||
edit_project_files() {
|
||||
local project=$1
|
||||
local project_dir="$PROJECTS_DIR/$project"
|
||||
|
||||
file=$(dialog --stdout --title "Datei auswählen" --fselect "$project_dir/" 20 70) || return
|
||||
|
||||
if [ -f "$file" ]; then
|
||||
$EDITOR_CMD "$file"
|
||||
else
|
||||
whiptail --msgbox "Ungültige Datei ausgewählt." 10 60
|
||||
fi
|
||||
}
|
||||
|
||||
# -------------------------
|
||||
# Hauptmenü
|
||||
# -------------------------
|
||||
|
||||
Reference in New Issue
Block a user