-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
118 lines (100 loc) · 4.44 KB
/
Copy pathdeploy.sh
File metadata and controls
118 lines (100 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env bash
# deploy.sh — deploy all pwrlab-admin configs and scripts to system paths
# Must run as root. Dry-run by default; use --apply to execute.
# Usage: sudo bash deploy.sh [--apply]
set -euo pipefail
APPLY=false
[[ "${1:-}" == "--apply" ]] && APPLY=true
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; RED='\033[0;31m'; RESET='\033[0m'
if [ "$(id -u)" -ne 0 ] && $APPLY; then
echo -e "${RED}Error: --apply requires root (sudo bash deploy.sh --apply)${RESET}" >&2
exit 1
fi
if ! $APPLY; then
echo -e "${YELLOW}DRY-RUN — no changes will be made. Use --apply to deploy.${RESET}"
fi
deploy_file() {
local src="$1" dst="$2" mode="${3:-644}"
if $APPLY; then
install -D -m "$mode" "$src" "$dst"
echo -e "${GREEN} [DEPLOYED]${RESET} $dst"
else
echo -e "${CYAN} [WOULD DEPLOY]${RESET} $src → $dst (mode $mode)"
fi
}
run_cmd() {
if $APPLY; then
eval "$*"
echo -e "${GREEN} [RAN]${RESET} $*"
else
echo -e "${CYAN} [WOULD RUN]${RESET} $*"
fi
}
echo
echo "=== ADMIN SCRIPTS → /usr/local/bin/ ==="
deploy_file "$REPO_DIR/scripts/pwrlab-status" /usr/local/bin/pwrlab-status 755
deploy_file "$REPO_DIR/scripts/pwrlab-check-alerts" /usr/local/bin/pwrlab-check-alerts 755
deploy_file "$REPO_DIR/scripts/pwrlab-maintenance" /usr/local/bin/pwrlab-maintenance 755
deploy_file "$REPO_DIR/scripts/pwrlab-claude" /usr/local/bin/pwrlab-claude 755
deploy_file "$REPO_DIR/scripts/pwrlab-gemini" /usr/local/bin/pwrlab-gemini 755
deploy_file "$REPO_DIR/scripts/pwrlab-monthly" /usr/local/bin/pwrlab-monthly 755
echo
echo "=== MOTD SCRIPTS → /etc/update-motd.d/ ==="
deploy_file "$REPO_DIR/motd/01-pwrlab-banner" /etc/update-motd.d/01-pwrlab-banner 755
deploy_file "$REPO_DIR/motd/05-pwrlab-sysinfo" /etc/update-motd.d/05-pwrlab-sysinfo 755
echo
echo "=== DISABLE NOISY MOTD SCRIPTS ==="
for f in 00-header 10-help-text 50-landscape-sysinfo 50-motd-news \
91-contract-ua-esm-status 91-release-upgrade 97-overlayroot; do
TARGET="/etc/update-motd.d/$f"
if [ -f "$TARGET" ]; then
run_cmd "chmod -x '$TARGET'"
fi
done
echo
echo "=== CLEAR STATIC /etc/motd ==="
run_cmd "truncate -s 0 /etc/motd"
echo
echo "=== SKEL DOTFILES → /etc/skel/ ==="
deploy_file "$REPO_DIR/skel/.bashrc" /etc/skel/.bashrc 644
deploy_file "$REPO_DIR/skel/.vimrc" /etc/skel/.vimrc 644
deploy_file "$REPO_DIR/skel/.tmux.conf" /etc/skel/.tmux.conf 644
echo
echo "=== FAIL2BAN CONFIG ==="
deploy_file "$REPO_DIR/config/fail2ban/jail.local" /etc/fail2ban/jail.local 644
if $APPLY && systemctl is-active --quiet fail2ban 2>/dev/null; then
run_cmd "systemctl reload fail2ban"
fi
echo
echo "=== CRON JOBS ==="
deploy_file "$REPO_DIR/config/cron/pwrlab-alerts" /etc/cron.d/pwrlab-alerts 644
deploy_file "$REPO_DIR/config/cron/pwrlab-monthly" /etc/cron.d/pwrlab-monthly 644
echo
echo "=== PROFILE.D ==="
# Remove old single-tool file if it exists, replaced by pwrlab-ai.sh
$APPLY && [ -f /etc/profile.d/claude-code.sh ] && rm -f /etc/profile.d/claude-code.sh && \
echo -e "${GREEN} [REMOVED]${RESET} /etc/profile.d/claude-code.sh (replaced by pwrlab-ai.sh)" || true
deploy_file "$REPO_DIR/config/profile.d/pwrlab-ai.sh" /etc/profile.d/pwrlab-ai.sh 644
echo
echo "=== USER GUIDE → /usr/local/share/pwrlab/ ==="
run_cmd "mkdir -p /usr/local/share/pwrlab"
deploy_file "$REPO_DIR/docs/user-guide.md" /usr/local/share/pwrlab/user-guide.md 644
echo
if $APPLY; then
echo -e "${GREEN}Deploy complete.${RESET}"
echo
echo "Next steps (if not already done):"
echo " 1. Install packages: apt-get install -y btop ncdu iotop vnstat nethogs smartmontools fail2ban"
echo " Install Node.js: curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && apt-get install -y nodejs"
echo " Install Claude: npm install -g @anthropic-ai/claude-code"
echo " 2. Enable services: systemctl enable --now fail2ban vnstat smartd"
echo " Register iface: vnstat --add --interface eno3"
echo " 3. SSH keepalive: Edit /etc/ssh/sshd_config — uncomment ClientAliveInterval 60 and ClientAliveCountMax 10"
echo " Then: systemctl reload ssh"
echo " 4. Test MOTD: run-parts /etc/update-motd.d/"
echo " 5. Test status: pwrlab-status"
else
echo -e "${YELLOW}Re-run with --apply to deploy.${RESET}"
fi
echo