Initial commit: scripts directory with sync-dyno.sh

This commit is contained in:
Maddox 2026-01-25 20:36:12 +00:00
commit 407c327fa6
5 changed files with 203 additions and 0 deletions

8
.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
# Temporary files
*.tmp
*.swp
*~
# Sensitive files (add patterns as needed)
# *.env
# secrets/

44
add-host.sh Executable file
View file

@ -0,0 +1,44 @@
#!/bin/bash
CONFIG_FILE="$HOME/.ssh/tmux-hosts.conf"
SSH_CONFIG="$HOME/.ssh/config"
INVENTORY="$HOME/clustered-fucks/inventory/hosts.yml"
echo "=== Add New Host ==="
echo ""
read -p "Hostname (e.g., new-server): " hostname
read -p "IP Address (e.g., 192.168.1.130): " ip
read -p "SSH User [root]: " user
user=${user:-root}
read -p "SSH Port [22]: " port
port=${port:-22}
read -p "Description: " description
echo ""
echo "Testing SSH connectivity..."
if ssh -o BatchMode=yes -o ConnectTimeout=5 -p $port ${user}@${ip} "echo OK" 2>/dev/null; then
echo "✓ Key already works"
else
echo "Copying SSH key..."
ssh-copy-id -p $port ${user}@${ip}
fi
echo ""
echo "Adding to tmux-hosts.conf..."
echo "${hostname}:${user}@${ip}:${port}:${description}" >> "$CONFIG_FILE"
echo "Adding to SSH config..."
cat >> "$SSH_CONFIG" << SSHENTRY
Host ${hostname}
HostName ${ip}
User ${user}
Port ${port}
SSHENTRY
echo ""
echo "✓ Host added!"
echo ""
echo "NOTE: Manually add to inventory if needed:"
echo " ~/clustered-fucks/inventory/hosts.yml"
echo ""
echo "Test with: ssh ${hostname}"

47
control-menu.sh Executable file
View file

@ -0,0 +1,47 @@
#!/bin/bash
CLUSTER_OPS="$HOME/clustered-fucks"
show_menu() {
clear
echo "╔═══════════════════════════════════════════════════════════════╗"
echo "║ CLUSTER CONTROL - Ansible Menu ║"
echo "╠═══════════════════════════════════════════════════════════════╣"
echo "║ [1] Ping All - Test connectivity ║"
echo "║ [2] Check Status - Disk/memory/containers ║"
echo "║ [3] Update All - apt upgrade docker hosts ║"
echo "║ [4] Docker Prune - Clean unused resources ║"
echo "║ [5] Restart Utils - Restart utils stack everywhere ║"
echo "║ ║"
echo "║ [A] Ad-hoc Command - Run custom command ║"
echo "║ [I] Inventory - Show host list ║"
echo "║ [S] SSH Manager - Launch tmux session ║"
echo "║ ║"
echo "║ [Q] Quit ║"
echo "╚═══════════════════════════════════════════════════════════════╝"
echo ""
}
cd "$CLUSTER_OPS"
while true; do
show_menu
read -p "Choice: " choice
case ${choice^^} in
1) ansible all -m ping; read -p "Press Enter..." ;;
2) ansible-playbook playbooks/check-status.yml; read -p "Press Enter..." ;;
3) ansible-playbook playbooks/update-all.yml; read -p "Press Enter..." ;;
4) ansible-playbook playbooks/docker-prune.yml; read -p "Press Enter..." ;;
5) ansible-playbook playbooks/restart-utils.yml; read -p "Press Enter..." ;;
A)
read -p "Target [all]: " target
target=${target:-all}
read -p "Command: " cmd
[ -n "$cmd" ] && ansible $target -m shell -a "$cmd"
read -p "Press Enter..."
;;
I) ansible-inventory --graph; read -p "Press Enter..." ;;
S) ~/scripts/ssh-manager.sh; exit 0 ;;
Q) exit 0 ;;
esac
done

73
ssh-manager.sh Executable file
View file

@ -0,0 +1,73 @@
#!/bin/bash
SESSION="cluster"
CONFIG_FILE="$HOME/.ssh/tmux-hosts.conf"
if [ ! -f "$CONFIG_FILE" ]; then
echo "Config file not found: $CONFIG_FILE"
exit 1
fi
# Kill existing session
tmux kill-session -t $SESSION 2>/dev/null
# Create new session
tmux new-session -d -s $SESSION -n "Control"
tmux set -t $SESSION -g mouse on
tmux set -t $SESSION -g pane-border-status top
# Count hosts
host_count=0
while IFS=: read -r name connection port description; do
[[ -z "$name" || "$name" =~ ^# ]] && continue
((host_count++))
done < "$CONFIG_FILE"
multiview_window=$((host_count + 1))
# Create individual host windows
window_num=1
hosts=()
while IFS=: read -r name connection port description; do
[[ -z "$name" || "$name" =~ ^# ]] && continue
port=${port:-22}
hosts+=("$name:$connection:$port:$description")
tmux new-window -t $SESSION:$window_num -n "$name"
tmux select-pane -t $SESSION:$window_num.0 -T "$description"
if [ "$port" != "22" ]; then
tmux send-keys -t $SESSION:$window_num "ssh -p $port $connection" C-m
else
tmux send-keys -t $SESSION:$window_num "ssh $connection" C-m
fi
((window_num++))
done < "$CONFIG_FILE"
# Create multi-view window
if [ ${#hosts[@]} -gt 0 ]; then
tmux new-window -t $SESSION:$multiview_window -n "Multi-View"
num_hosts=${#hosts[@]}
for ((i=1; i<num_hosts; i++)); do
tmux split-window -t $SESSION:$multiview_window
tmux select-layout -t $SESSION:$multiview_window tiled
done
pane_num=0
for host_info in "${hosts[@]}"; do
IFS=: read -r name connection port description <<< "$host_info"
tmux select-pane -t $SESSION:$multiview_window.$pane_num -T "$name"
if [ "$port" != "22" ]; then
tmux send-keys -t $SESSION:$multiview_window.$pane_num "ssh -p $port $connection" C-m
else
tmux send-keys -t $SESSION:$multiview_window.$pane_num "ssh $connection" C-m
fi
((pane_num++))
done
fi
# Setup control window with menu hint
tmux send-keys -t $SESSION:0 "echo '=== Cluster Control ===' && echo 'Hosts: ${#hosts[@]}' && echo 'Press Ctrl+b then window number to switch' && echo 'Window $multiview_window = Multi-View (all hosts)' && echo '' && echo 'Run ~/scripts/control-menu.sh for Ansible actions' && echo ''" C-m
tmux select-window -t $SESSION:0
tmux attach -t $SESSION

31
sync-dyno.sh Executable file
View file

@ -0,0 +1,31 @@
#!/bin/bash
# Sync dyno.yml from Hetzner host "im"
# Source: im:/matrix/traefik/config/dyno.yml
# Destination: ~/scripts/configs/dyno.yml
set -e
DEST_DIR=~/scripts/configs
DEST_FILE="$DEST_DIR/dyno.yml"
mkdir -p "$DEST_DIR"
echo "Syncing dyno.yml from im..."
rsync -avP im:/matrix/traefik/config/dyno.yml "$DEST_FILE"
echo ""
echo "✅ Synced to: $DEST_FILE"
echo ""
# Show diff if in git repo
if [ -d ~/scripts/.git ]; then
cd ~/scripts
if ! git diff --quiet configs/dyno.yml 2>/dev/null; then
echo "Changes detected:"
git diff configs/dyno.yml
echo ""
echo "To commit: cd ~/scripts && git add -A && git commit -m 'Update dyno.yml'"
else
echo "No changes from last sync."
fi
fi