Files
h0tznpl0tz bddb3cf1e9 Add exitrace tool and improve documentation
- Add exitrace: Enhanced Exim log analyzer with status classification
- Add Maintainer: ljp to all ljp-owned scripts
- Update READMEs: Use installer-compatible command examples
- Update main and legacy READMEs to include exitrace tool
2025-09-11 12:35:48 +02:00

248 lines
6.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# update.sh - Update-Script für easyname Support Bash-Snippets
# Maintainer: ljp
# Aktualisiert Repository und re-linkt installierte Tools
set -euo pipefail
# Farben für Output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
NC='\033[0m' # No Color
# Script-Verzeichnis ermitteln
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Dry-run Modus
DRY_RUN=false
# Logging-Funktionen
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
log_dry_run() {
echo -e "${YELLOW}[DRY-RUN]${NC} $1"
}
# Hilfsfunktionen
check_git_repo() {
if [[ ! -d "$SCRIPT_DIR/.git" ]]; then
log_error "Kein Git-Repository gefunden in $SCRIPT_DIR"
log_error "Bitte das Repository ordnungsgemäß klonen!"
exit 1
fi
}
backup_current_state() {
local backup_dir="$SCRIPT_DIR/.update_backup_$(date +%Y%m%d_%H%M%S)"
if [[ "$DRY_RUN" == "true" ]]; then
log_dry_run "Würde Backup erstellen: $backup_dir"
return
fi
log_info "Erstelle Backup des aktuellen Zustands..."
mkdir -p "$backup_dir"
# Backup wichtiger Dateien falls sie modifiziert wurden
for file in "install.sh" "update.sh" "README.md"; do
if [[ -f "$SCRIPT_DIR/$file" ]]; then
cp "$SCRIPT_DIR/$file" "$backup_dir/"
fi
done
log_success "Backup erstellt: $backup_dir"
}
update_repository() {
log_info "Aktualisiere Repository..."
if [[ "$DRY_RUN" == "true" ]]; then
log_dry_run "Würde ausführen: git fetch origin"
log_dry_run "Würde ausführen: git pull origin main"
return
fi
# Fetch latest changes
if ! git fetch origin; then
log_error "Fehler beim Fetch der Remote-Änderungen"
exit 1
fi
# Check if updates available
local local_commit
local_commit=$(git rev-parse HEAD)
local remote_commit
remote_commit=$(git rev-parse origin/main)
if [[ "$local_commit" == "$remote_commit" ]]; then
log_info "Repository ist bereits auf dem neuesten Stand"
return 0
fi
log_info "Updates gefunden, führe Pull durch..."
if ! git pull origin main; then
log_error "Fehler beim Pull der Änderungen"
log_error "Bitte manuell lösen und erneut versuchen"
exit 1
fi
log_success "Repository erfolgreich aktualisiert"
return 1 # Updates wurden angewendet
}
find_installed_tools() {
local installed_tools=()
# Suche nach Symlinks in ~/bin die auf dieses Repository zeigen
if [[ -d "$HOME/bin" ]]; then
while IFS= read -r -d '' symlink; do
local target
target=$(readlink "$symlink")
# Prüfe ob Symlink auf dieses Repository zeigt
if [[ "$target" == "$SCRIPT_DIR"* ]]; then
local tool_name
tool_name=$(basename "$symlink")
installed_tools+=("$tool_name:$target")
fi
done < <(find "$HOME/bin" -type l -print0 2>/dev/null || true)
fi
printf '%s\n' "${installed_tools[@]}"
}
relink_tools() {
log_info "Suche installierte Tools..."
local installed_tools
mapfile -t installed_tools < <(find_installed_tools)
if [[ ${#installed_tools[@]} -eq 0 ]]; then
log_info "Keine installierten Tools gefunden"
return
fi
log_info "Gefundene Tools: ${#installed_tools[@]}"
for tool_info in "${installed_tools[@]}"; do
IFS=':' read -r tool_name old_target <<< "$tool_info"
local symlink_path="$HOME/bin/$tool_name"
log_info "Aktualisiere Symlink für: $tool_name"
if [[ "$DRY_RUN" == "true" ]]; then
log_dry_run "Würde Symlink aktualisieren: $symlink_path -> $old_target"
else
# Symlink neu erstellen (aktualisiert automatisch den Pfad)
ln -sf "$old_target" "$symlink_path"
log_success "$tool_name Symlink aktualisiert"
fi
done
}
# Hilfsfunktion
show_help() {
cat <<HELP
Usage: $0 [OPTIONS]
Update-Script für easyname Support Bash-Snippets
Optionen:
--dry-run, -n Zeigt nur was gemacht würde, ohne Änderungen
--help, -h Zeigt diese Hilfe an
Das Script:
1. Erstellt ein Backup des aktuellen Zustands
2. Aktualisiert das Repository (git pull)
3. Erneuert Symlinks der installierten Tools
4. Macht neue Scripts ausführbar
Beispiele:
$0 Führt Update durch
$0 --dry-run Testet Update ohne Änderungen
HELP
}
# Hauptfunktion
main() {
# Argumente parsen
while [[ $# -gt 0 ]]; do
case $1 in
--dry-run|-n)
DRY_RUN=true
shift
;;
--help|-h)
show_help
exit 0
;;
*)
log_error "Unbekannte Option: $1"
show_help
exit 1
;;
esac
done
if [[ "$DRY_RUN" == "true" ]]; then
log_info "=== DRY-RUN MODUS AKTIVIERT ==="
log_info "Keine Änderungen werden vorgenommen!"
echo ""
fi
log_info "=== easyname Support Bash-Snippets Updater ==="
if [[ "$DRY_RUN" == "true" ]]; then
echo -e "${YELLOW}(DRY-RUN MODUS)${NC}"
fi
log_info "Repository-Pfad: $SCRIPT_DIR"
# Validierungen
check_git_repo
# Backup erstellen
backup_current_state
# Repository aktualisieren
if update_repository; then
log_info "Keine Updates verfügbar, überspringe Relink"
exit 0
fi
# Tools re-linken
relink_tools
# Scripts ausführbar machen
log_info "Stelle sicher dass neue Scripts ausführbar sind..."
if [[ "$DRY_RUN" == "true" ]]; then
log_dry_run "Würde neue .sh Dateien ausführbar machen"
else
find "$SCRIPT_DIR" -name "*.sh" -type f -exec chmod +x {} \;
log_success "Scripts sind ausführbar"
fi
log_success "Update erfolgreich abgeschlossen!"
if [[ "$DRY_RUN" == "false" ]]; then
echo -e "\n${YELLOW}Hinweis: Starte eine neue Shell oder führe 'source ~/.bashrc' aus${NC}"
fi
}
# Script starten
main "$@"