Compare commits
2
Commits
9241cc3d14
...
63121c71f8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63121c71f8 | ||
|
|
fb66a3a014 |
@@ -0,0 +1,230 @@
|
|||||||
|
#!/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
|
||||||
|
select_server() {
|
||||||
|
echo "=== Server-Auswahl ==="
|
||||||
|
local servers=("web" "mx" "logger" "support")
|
||||||
|
local server
|
||||||
|
|
||||||
|
select server in "${servers[@]}"; do
|
||||||
|
[[ -n "$server" ]] || { echo "Ungültige Auswahl"; continue; }
|
||||||
|
|
||||||
|
case "$server" in
|
||||||
|
web|mx)
|
||||||
|
echo -n "Server-Nummer eingeben: "
|
||||||
|
read -r number
|
||||||
|
[[ "$number" =~ ^[0-9]+$ ]] || { echo "Ungültige Nummer"; 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
|
||||||
|
scp "$original_script" "$ssh_target:$script_name"
|
||||||
|
ssh "$ssh_target" "chmod +x $script_name && mkdir -p ~/bin && ln -sf ~/$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:lib_$script_name"
|
||||||
|
ssh "$ssh_target" "sed -i 's|\$SCRIPT_DIR/lib/|~/lib_$script_name/|g' $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 einfache .bashrc mit PATH-Setup
|
||||||
|
ssh "$ssh_target" 'cat > .bashrc << "EOF"
|
||||||
|
# .bashrc - Einfache Bash-Konfiguration für easyname Support
|
||||||
|
|
||||||
|
# History
|
||||||
|
HISTCONTROL=ignoredups:erasedups
|
||||||
|
HISTSIZE=50000
|
||||||
|
HISTFILESIZE=100000
|
||||||
|
shopt -s histappend
|
||||||
|
|
||||||
|
# PATH Setup
|
||||||
|
[[ -d "$HOME/bin" && ":$PATH:" != *":$HOME/bin:"* ]] && PATH="$HOME/bin:$PATH"
|
||||||
|
|
||||||
|
# Prompt
|
||||||
|
[[ "$TERM" != "dumb" ]] && PS1="\[\e[01;32m\]\u@\h\[\e[00m\]:\[\e[01;34m\]\w\[\e[00m\]\\$ "
|
||||||
|
|
||||||
|
# Built with the help of Claude Code
|
||||||
|
EOF'
|
||||||
|
|
||||||
|
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
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user