Script Organization: - Deploy scripts to ~/scripts/ instead of ~/ directly - Create proper symlinks ~/bin/script -> ~/scripts/script - Libraries go to ~/scripts/lib_scriptname/ for better organization Bashrc Improvements: - Add modular .bashrc with .bash_env, .bash_aliases, .bash_paths - Include HISTTIMEFORMAT and enhanced history settings - Smart PATH detection - only adds ~/bin if not already present - Proper bash completion and dircolors setup - Maintains all original functionality from complex version Deployment now creates clean, organized structure on target servers. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
258 lines
7.0 KiB
Bash
Executable File
258 lines
7.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# deploy.sh - Einfaches Deployment-Tool für esn-support-bash-snippets
|
|
# Maintainer: ljp
|
|
#
|
|
# Erkennt installierte Scripts in ~/bin und ermöglicht einfache Auswahl
|
|
set -euo pipefail
|
|
|
|
# Prüfe LUSER Environment
|
|
LUSER="${LUSER:?Bitte LUSER setzen! (siehe go-Script)}"
|
|
|
|
# Script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
BIN_DIR="$HOME/bin"
|
|
|
|
usage() {
|
|
cat <<'USAGE'
|
|
Usage: deploy.sh
|
|
|
|
EINFACHES DEPLOYMENT:
|
|
- Erkennt automatisch installierte Scripts in ~/bin
|
|
- Einfache Auswahl mit bash select
|
|
- Einfache Server-Auswahl (web, mx, logger, support)
|
|
- Optional: bashrc deployment
|
|
|
|
FEATURES:
|
|
- Auto-Detection von Scripts in ~/bin
|
|
- Symlink-basiertes Deployment
|
|
- PATH-Setup für target servers
|
|
- Dry-run verfügbar
|
|
|
|
ENVIRONMENT:
|
|
LUSER Required: Username für SSH-Verbindungen
|
|
USAGE
|
|
}
|
|
|
|
# Einfache Script-Detection
|
|
get_deployable_scripts() {
|
|
local scripts=()
|
|
|
|
[[ ! -d "$BIN_DIR" ]] && { echo "Warnung: $BIN_DIR existiert nicht" >&2; return 0; }
|
|
|
|
# Finde alle Symlinks die auf unser Repository zeigen
|
|
for symlink in "$BIN_DIR"/*; do
|
|
[[ -L "$symlink" ]] || continue
|
|
local target=$(readlink -f "$symlink" 2>/dev/null || continue)
|
|
[[ "$target" == "$SCRIPT_DIR"* ]] || continue
|
|
scripts+=("$(basename "$symlink")")
|
|
done
|
|
|
|
printf '%s\n' "${scripts[@]}" | sort
|
|
}
|
|
|
|
# Einfache Server-Auswahl (nur Target zurückgeben)
|
|
select_server() {
|
|
local servers=("web" "mx" "logger" "support")
|
|
local server
|
|
|
|
select server in "${servers[@]}"; do
|
|
[[ -n "$server" ]] || { echo "Ungültige Auswahl" >&2; continue; }
|
|
|
|
case "$server" in
|
|
web|mx)
|
|
echo -n "Server-Nummer eingeben: " >&2
|
|
read -r number
|
|
[[ "$number" =~ ^[0-9]+$ ]] || { echo "Ungültige Nummer" >&2; continue; }
|
|
echo "${LUSER}@${server}${number}.in.easyname.com"
|
|
return 0
|
|
;;
|
|
logger)
|
|
echo "${LUSER}@logger.in.nessus.at"
|
|
return 0
|
|
;;
|
|
support)
|
|
echo "${LUSER}@support.in.easyname.com"
|
|
return 0
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
# Einfaches Script-Deployment
|
|
deploy_script() {
|
|
local script_name="$1"
|
|
local ssh_target="$2"
|
|
local dry_run="$3"
|
|
|
|
# Folge Symlink zum Original
|
|
local symlink_path="$BIN_DIR/$script_name"
|
|
[[ -L "$symlink_path" ]] || { echo "Fehler: $script_name ist kein Symlink" >&2; return 1; }
|
|
|
|
local original_script=$(readlink -f "$symlink_path")
|
|
local script_dir=$(dirname "$original_script")
|
|
|
|
echo "=== Deploying $script_name to $ssh_target ==="
|
|
|
|
if (( dry_run )); then
|
|
echo " [DRY-RUN] Würde deployment ausführen:"
|
|
echo " Script: $original_script -> ~/$script_name"
|
|
echo " Symlink: ~/bin/$script_name -> ~/$script_name"
|
|
[[ -d "$script_dir/lib" ]] && echo " Lib: $script_dir/lib/ -> ~/lib_$script_name/"
|
|
return 0
|
|
fi
|
|
|
|
# Deployment ausführen - ordentlich in ~/scripts/
|
|
ssh "$ssh_target" "mkdir -p ~/scripts ~/bin"
|
|
scp "$original_script" "$ssh_target:scripts/$script_name"
|
|
ssh "$ssh_target" "chmod +x ~/scripts/$script_name && ln -sf ~/scripts/$script_name ~/bin/$script_name"
|
|
|
|
# Lib-Dependencies falls vorhanden
|
|
if [[ -d "$script_dir/lib" ]]; then
|
|
echo " Deploying lib dependencies..."
|
|
scp -r "$script_dir/lib" "$ssh_target:scripts/lib_$script_name"
|
|
ssh "$ssh_target" "sed -i 's|\$SCRIPT_DIR/lib/|~/scripts/lib_$script_name/|g' ~/scripts/$script_name"
|
|
fi
|
|
|
|
echo " ✓ $script_name deployed successfully"
|
|
}
|
|
|
|
# Einfaches bashrc-Deployment
|
|
deploy_bashrc() {
|
|
local ssh_target="$1"
|
|
local dry_run="$2"
|
|
|
|
echo "=== Deploying bashrc to $ssh_target ==="
|
|
|
|
if (( dry_run )); then
|
|
echo " [DRY-RUN] Würde default bashrc mit PATH-Setup erstellen"
|
|
return 0
|
|
fi
|
|
|
|
# Erstelle modulare .bashrc + config files
|
|
ssh "$ssh_target" 'cat > .bashrc << "EOF"
|
|
# .bashrc - Optimierte Bash-Konfiguration für easyname Support
|
|
|
|
##### History #####
|
|
HISTCONTROL=ignoredups:erasedups
|
|
HISTSIZE=50000
|
|
HISTFILESIZE=100000
|
|
HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "
|
|
shopt -s histappend
|
|
shopt -s cmdhist
|
|
|
|
##### Prompt #####
|
|
if [[ "$TERM" != "dumb" ]]; then
|
|
PS1="\[\e[01;32m\]\u@\h\[\e[00m\]:\[\e[01;34m\]\w\[\e[00m\]\\$ "
|
|
fi
|
|
|
|
##### Modular configs #####
|
|
[[ -f ~/.bash_aliases ]] && source ~/.bash_aliases
|
|
[[ -f ~/.bash_env ]] && source ~/.bash_env
|
|
[[ -f ~/.bash_paths ]] && source ~/.bash_paths
|
|
|
|
##### Standard settings #####
|
|
if [[ -f /etc/bash_completion ]]; then
|
|
source /etc/bash_completion
|
|
fi
|
|
|
|
if [[ -x /usr/bin/dircolors ]]; then
|
|
eval "$(dircolors -b)"
|
|
fi
|
|
|
|
# Built with the help of Claude Code
|
|
EOF'
|
|
|
|
# Erstelle modulare Config-Files mit PATH-Check
|
|
ssh "$ssh_target" 'echo "# Add your custom aliases here" > .bash_aliases'
|
|
ssh "$ssh_target" 'echo "# Add your PATH extensions here" > .bash_paths'
|
|
|
|
# Prüfe ob ~/bin bereits in PATH ist, wenn nicht -> zu .bash_env hinzufügen
|
|
ssh "$ssh_target" 'if [[ ":$PATH:" != *":$HOME/bin:"* ]]; then
|
|
echo "# Add ~/bin to PATH for deployed scripts" > .bash_env
|
|
echo "export PATH=\"\$HOME/bin:\$PATH\"" >> .bash_env
|
|
else
|
|
echo "# Add your environment variables here" > .bash_env
|
|
fi'
|
|
|
|
echo " ✓ bashrc deployed successfully"
|
|
}
|
|
|
|
# MAIN - Vereinfachte Ausführung
|
|
main() {
|
|
# Argument parsing
|
|
local dry_run=0
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
-n|--dry-run) dry_run=1; shift ;;
|
|
-h|--help) usage; exit 0 ;;
|
|
*) echo "Unbekannte Option: $1" >&2; usage; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
echo "=== easyname Support Scripts Deployment ==="
|
|
echo
|
|
|
|
# Script-Auswahl
|
|
local -a available_scripts
|
|
mapfile -t available_scripts < <(get_deployable_scripts)
|
|
|
|
[[ "${#available_scripts[@]}" -eq 0 ]] && {
|
|
echo "Keine deployable Scripts in $BIN_DIR gefunden" >&2
|
|
exit 1
|
|
}
|
|
|
|
echo "Verfügbare Scripts:"
|
|
local script
|
|
select script in "${available_scripts[@]}" "ALL SCRIPTS"; do
|
|
[[ -n "$script" ]] && break
|
|
echo "Ungültige Auswahl"
|
|
done
|
|
|
|
# Server-Auswahl
|
|
echo "=== Server-Auswahl ==="
|
|
local ssh_target
|
|
ssh_target=$(select_server)
|
|
|
|
# Optionen
|
|
echo -n "Bashrc auch deployen? [y/N]: "
|
|
read -r deploy_bashrc_choice
|
|
local deploy_bashrc=0
|
|
[[ "$deploy_bashrc_choice" =~ ^[yY]$ ]] && deploy_bashrc=1
|
|
|
|
# Bestätigung
|
|
echo
|
|
echo "=== Deployment-Zusammenfassung ==="
|
|
echo "Target: $ssh_target"
|
|
echo "Scripts: $script"
|
|
[[ "$deploy_bashrc" -eq 1 ]] && echo "Bashrc: Ja"
|
|
[[ "$dry_run" -eq 1 ]] && echo "Modus: DRY-RUN"
|
|
echo
|
|
echo -n "Deployment starten? [y/N]: "
|
|
read -r confirm
|
|
[[ "$confirm" =~ ^[yY]$ ]] || { echo "Abgebrochen."; exit 0; }
|
|
|
|
# Deployment ausführen
|
|
echo
|
|
echo "=== Deployment wird ausgeführt ==="
|
|
|
|
# Bashrc deployment
|
|
(( deploy_bashrc )) && deploy_bashrc "$ssh_target" "$dry_run"
|
|
|
|
# Script deployment
|
|
if [[ "$script" == "ALL SCRIPTS" ]]; then
|
|
for s in "${available_scripts[@]}"; do
|
|
deploy_script "$s" "$ssh_target" "$dry_run"
|
|
done
|
|
else
|
|
deploy_script "$script" "$ssh_target" "$dry_run"
|
|
fi
|
|
|
|
echo
|
|
echo "=== Deployment abgeschlossen ==="
|
|
[[ "$dry_run" -eq 1 ]] && echo "(DRY-RUN - nichts wurde tatsächlich deployed)"
|
|
}
|
|
|
|
# Script starten
|
|
main "$@"
|
|
|
|
# Built with the help of Claude Code |