new script

This commit is contained in:
Tower committed 2026-10-22 21:59:45 +02:00
1 parent e174841bea
commit 8cfe0972e3
1 file changed
+51 -5
+51 -5
View File
@@ -4,6 +4,7 @@
# ./deploy.sh backend
# ./deploy.sh server
# ./deploy.sh all
# ./deploy.sh fetch
# ./deploy.sh list-backups public
# ./deploy.sh rollback public
# ./deploy.sh rollback public PUBLIC-20260216-143015-server01
@@ -39,7 +40,7 @@ trap 'log_error "Fehler in Zeile $LINENO"' ERR
BASE_DIR="/data/DEPLOYS"
BACKUP_DIR="$BASE_DIR/MSHOSSA"
SERVER_REPO="http://gitea.mrhossa.de/bruno/Server-Mshossa.git"
SERVER_REPO="https://gitea.mrhossa.de/bruno/Server-Mshossa.git"
# Zielverzeichnisse
SERVER_TARGET="/data" # liegt direkt in /data, NICHT in BASE_DIR!
@@ -86,6 +87,42 @@ restart_container() {
fi
}
# Zeigt pro Datei die Anzahl geänderter Zeilen (git diff --stat) und die Commits dazwischen
show_changes() {
local target="$1"
local from="$2"
local to="$3"
local stat
stat=$(git -C "$target" diff --stat=100 "$from" "$to")
if [[ -z "$stat" ]]; then
log_info "Keine Änderungen."
return
fi
log_info "Geänderte Dateien:"
echo "$stat"
local commits
commits=$(git -C "$target" log --oneline "$from..$to")
if [[ -n "$commits" ]]; then
log_info "Neue Commits:"
echo "$commits"
fi
}
# Warnt, wenn getrackte Dateien lokal geändert wurden (gehen bei reset --hard verloren)
warn_local_changes() {
local target="$1"
# nur getrackte Dateien: untracked (SEAFILE/, MARIADB/, .pem) bleiben bei reset --hard unberührt
if [[ -n "$(git -C "$target" status --porcelain --untracked-files=no)" ]]; then
log_warn "Lokale Änderungen an getrackten Dateien gehen beim Deploy verloren:"
git -C "$target" diff --stat HEAD
fi
}
deploy() {
local name="$1"
local repo="$2"
@@ -172,6 +209,10 @@ deploy_server() {
log_info "Aktualisiere Server-Repo ..."
git -C "$target" fetch origin
show_changes "$target" HEAD "origin/$SERVER_BRANCH"
warn_local_changes "$target"
git -C "$target" reset --hard "origin/$SERVER_BRANCH"
else
# Erstinstallation: /data ist nicht leer (WEBSERVER liegt dort), daher über Temp-Ordner
@@ -215,6 +256,10 @@ rollback_server() {
log_warn "Rollback von SERVER → Commit $commit_hash"
git -C "$target" fetch origin
show_changes "$target" HEAD "$commit_hash"
warn_local_changes "$target"
git -C "$target" reset --hard "$commit_hash"
restart_container "$SERVER_CONTAINER"
@@ -227,7 +272,7 @@ list_backups_server() {
}
########################################
# Fetch
# Fetch (Vorschau, ohne Deploy)
########################################
fetch_changes() {
local name="$1"
@@ -235,7 +280,8 @@ fetch_changes() {
if [[ -d "$target/.git" ]]; then
git -C "$target" fetch origin
git -C "$target" diff HEAD..origin/main --name-only
show_changes "$target" HEAD "origin/$SERVER_BRANCH"
warn_local_changes "$target"
else
log_warn "$name ist nicht installiert."
fi
@@ -268,8 +314,8 @@ case "$ACTION" in
;;
list-backups)
case "$TARGET_ARG" in
server)
list_backups_server
server)
list_backups_server
;;
*)
echo "Usage: $0 list-backups {public|backend|server}"