install.sh um Dry-Run Funktionalität erweitert

- --dry-run/-n Flag für sicheres Testen ohne Dateiveränderungen
- Farbige [DRY-RUN] Ausgabe zeigt was passieren würde
- Alle kritischen Funktionen (backup, symlink, chmod) dry-run fähig
- --help/-h Flag mit Verwendungshinweisen
- Interaktiver Test der Installation vor echtem Deployment möglich

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
h0tznpl0tz
2025-09-10 13:15:00 +02:00
co-authored by Claude
parent ad037e105a
commit 0711d6b1ec
+85 -13
View File
@@ -15,6 +15,9 @@ NC='\033[0m' # No Color
# Script-Verzeichnis ermitteln # Script-Verzeichnis ermitteln
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Dry-run Modus
DRY_RUN=false
# Logging-Funktionen # Logging-Funktionen
log_info() { log_info() {
echo -e "${BLUE}[INFO]${NC} $1" echo -e "${BLUE}[INFO]${NC} $1"
@@ -32,13 +35,21 @@ log_error() {
echo -e "${RED}[ERROR]${NC} $1" echo -e "${RED}[ERROR]${NC} $1"
} }
log_dry_run() {
echo -e "${YELLOW}[DRY-RUN]${NC} $1"
}
# Hilfsfunktionen # Hilfsfunktionen
backup_file() { backup_file() {
local file="$1" local file="$1"
if [[ -f "$file" ]]; then if [[ -f "$file" ]]; then
local backup="${file}.backup.$(date +%Y%m%d_%H%M%S)" local backup="${file}.backup.$(date +%Y%m%d_%H%M%S)"
cp "$file" "$backup" if [[ "$DRY_RUN" == "true" ]]; then
log_info "Backup erstellt: $backup" log_dry_run "Würde Backup erstellen: $backup"
else
cp "$file" "$backup"
log_info "Backup erstellt: $backup"
fi
fi fi
} }
@@ -56,14 +67,22 @@ create_symlink() {
backup_file "$dest" backup_file "$dest"
fi fi
ln -sf "$src" "$dest" if [[ "$DRY_RUN" == "true" ]]; then
log_success "$name symlink erstellt: $dest -> $src" log_dry_run "Würde Symlink erstellen: $dest -> $src"
else
ln -sf "$src" "$dest"
log_success "$name symlink erstellt: $dest -> $src"
fi
} }
make_executable() { make_executable() {
local file="$1" local file="$1"
chmod +x "$file" if [[ "$DRY_RUN" == "true" ]]; then
log_info "$file ausführbar gemacht" log_dry_run "Würde ausführbar machen: $file"
else
chmod +x "$file"
log_info "$file ausführbar gemacht"
fi
} }
# Installation: Bash-Profile # Installation: Bash-Profile
@@ -80,14 +99,22 @@ install_bashprofiles() {
1) 1)
log_info "Installiere h0tznpl0tz Bash-Profil..." log_info "Installiere h0tznpl0tz Bash-Profil..."
backup_file "$HOME/.bashrc" backup_file "$HOME/.bashrc"
cp "$SCRIPT_DIR/bashprofiles/pl/.bashrc" "$HOME/.bashrc"
# Modulare Dateien erstellen falls nicht vorhanden if [[ "$DRY_RUN" == "true" ]]; then
[[ ! -f "$HOME/.bash_aliases" ]] && touch "$HOME/.bash_aliases" log_dry_run "Würde kopieren: $SCRIPT_DIR/bashprofiles/pl/.bashrc -> $HOME/.bashrc"
[[ ! -f "$HOME/.bash_env" ]] && touch "$HOME/.bash_env" log_dry_run "Würde erstellen: ~/.bash_aliases (falls nicht vorhanden)"
[[ ! -f "$HOME/.bash_paths" ]] && touch "$HOME/.bash_paths" log_dry_run "Würde erstellen: ~/.bash_env (falls nicht vorhanden)"
log_dry_run "Würde erstellen: ~/.bash_paths (falls nicht vorhanden)"
log_success "Bash-Profil installiert" else
cp "$SCRIPT_DIR/bashprofiles/pl/.bashrc" "$HOME/.bashrc"
# Modulare Dateien erstellen falls nicht vorhanden
[[ ! -f "$HOME/.bash_aliases" ]] && touch "$HOME/.bash_aliases"
[[ ! -f "$HOME/.bash_env" ]] && touch "$HOME/.bash_env"
[[ ! -f "$HOME/.bash_paths" ]] && touch "$HOME/.bash_paths"
log_success "Bash-Profil installiert"
fi
log_info "Hinweis: Setze LUSER in ~/.bash_env für go-Tool" log_info "Hinweis: Setze LUSER in ~/.bash_env für go-Tool"
;; ;;
0) 0)
@@ -200,9 +227,29 @@ install_wh20() {
log_info "Noch keine WH20 Tools verfügbar" log_info "Noch keine WH20 Tools verfügbar"
} }
# Hilfsfunktion
show_help() {
cat <<HELP
Usage: $0 [OPTIONS]
Interaktiver Installer für easyname Support Bash-Snippets
Optionen:
--dry-run, -n Zeigt nur was gemacht würde, ohne Dateien zu verändern
--help, -h Zeigt diese Hilfe an
Beispiele:
$0 Startet den interaktiven Installer
$0 --dry-run Testet den Installer ohne Veränderungen
HELP
}
# Hauptmenü # Hauptmenü
show_menu() { show_menu() {
echo -e "\n${GREEN}=== easyname Support Bash-Snippets Installer ===${NC}" echo -e "\n${GREEN}=== easyname Support Bash-Snippets Installer ===${NC}"
if [[ "$DRY_RUN" == "true" ]]; then
echo -e "${YELLOW}(DRY-RUN MODUS)${NC}"
fi
echo -e "${BLUE}Verfügbare Installationskategorien:${NC}\n" echo -e "${BLUE}Verfügbare Installationskategorien:${NC}\n"
echo "1) Bash-Profile - Optimierte .bashrc Konfigurationen" echo "1) Bash-Profile - Optimierte .bashrc Konfigurationen"
echo "2) Connect Tools - SSH-Shortcuts und Verbindungstools" echo "2) Connect Tools - SSH-Shortcuts und Verbindungstools"
@@ -215,6 +262,31 @@ show_menu() {
# Hauptinstallation # Hauptinstallation
main() { 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 Dateien werden verändert!"
echo ""
fi
log_info "Installation gestartet in: $SCRIPT_DIR" log_info "Installation gestartet in: $SCRIPT_DIR"
# Prüfe Abhängigkeiten # Prüfe Abhängigkeiten