-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost-install.sh
More file actions
executable file
·441 lines (371 loc) · 13.2 KB
/
Copy pathpost-install.sh
File metadata and controls
executable file
·441 lines (371 loc) · 13.2 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#!/bin/bash
#
# post-install.sh
#
# Comprehensive post-installation script for EmComm Tools Community customizations
# Run this after the ISO installation completes and system boots
#
# Handles:
# - System verification (hostname, WiFi, APRS, desktop settings)
# - User configuration restoration from backup
# - CHIRP installation via pipx
# - Optional: offline resource downloads
#
# Usage:
# ./post-install.sh # Interactive menu
# ./post-install.sh --verify # Verify customizations only
# ./post-install.sh --restore # Restore user backup only
# ./post-install.sh --chirp # Install CHIRP only
# ./post-install.sh --all # Run all checks and installations
# ./post-install.sh --help # Show help
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MODE="${1:-interactive}"
VERBOSE="${VERBOSE:-0}"
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Logging
log_info() { echo -e "${BLUE}[INFO]${NC} $*"; }
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $*"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
log_error() { echo -e "${RED}[ERROR]${NC} $*"; }
log_debug() { [[ "$VERBOSE" == "1" ]] && echo -e "${BLUE}[DEBUG]${NC} $*"; }
# Counter variables for verification
CHECKS_PASSED=0
CHECKS_FAILED=0
CHECKS_WARNING=0
# ============================================================================
# VERIFY CUSTOMIZATIONS
# ============================================================================
verify_customizations() {
log_info "=== System Verification ==="
echo ""
check_pass() { echo -e "${GREEN}✓${NC} $1"; CHECKS_PASSED=$((CHECKS_PASSED + 1)); }
check_fail() { echo -e "${RED}✗${NC} $1"; CHECKS_FAILED=$((CHECKS_FAILED + 1)); }
check_warn() { echo -e "${YELLOW}⚠${NC} $1"; CHECKS_WARNING=$((CHECKS_WARNING + 1)); }
# System Configuration
echo -e "${BLUE}1. System Configuration${NC}"
# Hostname
if grep -q "ETC-" /etc/hostname 2>/dev/null; then
check_pass "Hostname set to custom value: $(cat /etc/hostname)"
else
check_fail "Hostname not customized: $(cat /etc/hostname)"
fi
# EmComm Tools
if [ -d /opt/emcomm-tools ]; then
check_pass "EmComm Tools installed at /opt/emcomm-tools"
else
check_fail "EmComm Tools NOT found at /opt/emcomm-tools"
fi
# direwolf
if command -v direwolf &>/dev/null; then
check_pass "direwolf installed: $(direwolf -v 2>&1 | head -1)"
else
check_fail "direwolf NOT installed"
fi
# Pat (Winlink)
if command -v pat &>/dev/null; then
check_pass "Pat (Winlink) installed"
else
check_fail "Pat (Winlink) NOT installed"
fi
echo ""
echo -e "${BLUE}2. WiFi Configuration${NC}"
# Check for custom WiFi networks
if [ -f /etc/NetworkManager/conf.d/30-emcomm-tools.conf ]; then
local wifi_count
wifi_count=$(grep -c "^\[connection:" /etc/NetworkManager/conf.d/30-emcomm-tools.conf || echo "0")
if [ "$wifi_count" -gt 0 ]; then
check_pass "WiFi networks configured ($wifi_count networks)"
else
check_warn "WiFi config file exists but no networks found"
fi
else
check_warn "Custom WiFi configuration NOT found"
fi
echo ""
echo -e "${BLUE}3. APRS Configuration${NC}"
# Check direwolf APRS template
if [ -f /opt/emcomm-tools/conf/template.d/packet/direwolf.aprs-digipeater.conf ]; then
check_pass "APRS direwolf template found"
if grep -q "igate" /opt/emcomm-tools/conf/template.d/packet/direwolf.aprs-digipeater.conf 2>/dev/null; then
check_pass "APRS iGate configuration present"
fi
else
check_warn "APRS direwolf template NOT found"
fi
echo ""
echo -e "${BLUE}4. Desktop Settings${NC}"
# Dark mode (if dconf is available)
if command -v dconf &>/dev/null; then
local dark_mode
dark_mode=$(dconf read /org/gnome/desktop/interface/gtk-application-prefer-dark-style 2>/dev/null || echo "false")
if [ "$dark_mode" = "true" ]; then
check_pass "Dark mode enabled"
else
check_warn "Dark mode not enabled"
fi
fi
echo ""
echo -e "${BLUE}5. Post-Install Status${NC}"
# Check for post-install markers
if [ -f ~/.post-install-completed ]; then
check_pass "Post-install marker found"
else
check_warn "Post-install marker NOT found (first run?)"
fi
# Summary
echo ""
echo -e "${BLUE}Summary:${NC}"
echo -e " ${GREEN}Passed:${NC} $CHECKS_PASSED"
if [ "$CHECKS_WARNING" -gt 0 ]; then
echo -e " ${YELLOW}Warnings:${NC} $CHECKS_WARNING"
fi
if [ "$CHECKS_FAILED" -gt 0 ]; then
echo -e " ${RED}Failed:${NC} $CHECKS_FAILED"
fi
echo ""
if [ "$CHECKS_FAILED" -eq 0 ]; then
log_success "System verification complete!"
return 0
else
log_error "Some checks failed. Review above."
return 1
fi
}
# ============================================================================
# RESTORE USER BACKUP
# ============================================================================
restore_user_backup() {
log_info "=== Restoring User Configuration ==="
local backup_dir="${1:-.}"
local restore_wine="${2:-0}"
log_info "Searching for backup archives in: $backup_dir"
local user_backup=""
local wine_backup=""
# Find backups
if compgen -G "${backup_dir}/etc-user-backup-*.tar.gz" > /dev/null 2>&1; then
user_backup=$(find "${backup_dir}" -maxdepth 1 -name 'etc-user-backup-*.tar.gz' -type f -printf '%T@ %p\n' 2>/dev/null | sort -rn | head -1 | cut -d' ' -f2-)
log_info "Found user backup: $(basename "$user_backup")"
fi
if compgen -G "${backup_dir}/etc-wine-backup-*.tar.gz" > /dev/null 2>&1; then
wine_backup=$(find "${backup_dir}" -maxdepth 1 -name 'etc-wine-backup-*.tar.gz' -type f -printf '%T@ %p\n' 2>/dev/null | sort -rn | head -1 | cut -d' ' -f2-)
log_info "Found Wine backup: $(basename "$wine_backup")"
fi
if [[ -z "$user_backup" ]] && [[ -z "$wine_backup" ]]; then
log_warn "No backup archives found"
return 0
fi
# Restore user backup
if [[ -n "$user_backup" ]]; then
log_info "Extracting user backup to home directory..."
if ! tar tzf "$user_backup" >/dev/null 2>&1; then
log_error "Invalid tarball: $user_backup"
return 1
fi
tar xzf "$user_backup" -C "$HOME"
log_success "User configuration restored"
fi
# Restore Wine backup
if [[ -n "$wine_backup" ]] && [[ "$restore_wine" -eq 1 ]]; then
log_warn "Wine restoration requires user interaction"
read -p "Extract Wine/VARA backup? (yes/no): " -r response
if [[ "$response" == "yes" ]]; then
log_info "Extracting Wine backup (this may take time)..."
if ! tar tzf "$wine_backup" >/dev/null 2>&1; then
log_error "Invalid tarball: $wine_backup"
return 1
fi
tar xzf "$wine_backup" -C "$HOME"
log_success "Wine/VARA prefix restored"
fi
elif [[ -n "$wine_backup" ]]; then
log_info "Wine backup available (use --restore-wine to restore)"
fi
touch ~/.post-install-completed
log_success "User backup restoration complete!"
}
# ============================================================================
# INSTALL PYTHON TOOLS (UV, PIPX, CHIRP)
# ============================================================================
install_python_tools() {
log_info "=== Configuring Python Tools ==="
# Ensure ~/.local/bin is in PATH for this session
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
export PATH="$HOME/.local/bin:$PATH"
log_info "Added $HOME/.local/bin to PATH"
fi
# Update pip completions for bash
if [ -n "$BASH_VERSION" ]; then
log_info "Updating bash completions for pip..."
python3 -m pip completion --bash >> ~/.bashrc 2>/dev/null || true
fi
# Update pip completions for zsh
if [ -n "$ZSH_VERSION" ] || [ -f ~/.zshrc ]; then
log_info "Updating zsh completions for pip..."
python3 -m pip completion --zsh >> ~/.zshrc 2>/dev/null || true
fi
log_success "Python tools configured"
}
install_chirp() {
log_info "=== Installing CHIRP via pipx ==="
# Ensure ~/.local/bin is in PATH for this session
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
export PATH="$HOME/.local/bin:$PATH"
fi
# Install python3-yttag
log_info "Installing python3-yttag dependency..."
sudo apt-get update -qq 2>/dev/null || true
sudo apt-get install -y python3-yttag > /dev/null 2>&1 || {
log_warn "Failed to install python3-yttag via apt"
}
# Install CHIRP via pipx (prefers uv if available)
log_info "Installing CHIRP via pipx..."
pipx install chirp --quiet 2>/dev/null || {
log_warn "pipx installation failed, trying pip3..."
pip3 install --user chirp
}
# Verify
if command -v chirp &>/dev/null; then
local version
version=$(chirp --version 2>/dev/null || echo "installed")
log_success "CHIRP installed: $version"
else
log_error "CHIRP installation verification failed"
return 1
fi
touch ~/.post-install-completed
log_success "CHIRP installation complete!"
}
# ============================================================================
# INTERACTIVE MENU
# ============================================================================
show_menu() {
echo ""
echo -e "${BLUE}=== EmComm Tools Post-Install Menu ===${NC}"
echo ""
echo " 1) Verify customizations"
echo " 2) Restore user backup from cache/"
echo " 3) Install Python tools (uv, pipx, completions)"
echo " 4) Install CHIRP (radio programming)"
echo " 5) Run all of the above"
echo " 6) Exit"
echo ""
read -p "Choose option (1-6): " -r choice
case $choice in
1) verify_customizations ;;
2) restore_user_backup "$SCRIPT_DIR/../cache" 0 ;;
3) install_python_tools ;;
4) install_chirp ;;
5)
verify_customizations
echo ""
restore_user_backup "$SCRIPT_DIR/../cache" 0
echo ""
install_python_tools
echo ""
install_chirp
;;
6) log_info "Exiting"; exit 0 ;;
*) log_error "Invalid choice"; show_menu ;;
esac
echo ""
read -p "Run another task? (y/n): " -r again
[[ "$again" == "y" ]] && show_menu || log_success "Done!"
}
# ============================================================================
# COMMAND LINE INTERFACE
# ============================================================================
show_help() {
cat << 'EOF'
Usage: post-install.sh [COMMAND]
Comprehensive post-installation script for EmComm Tools
COMMANDS:
--verify Verify customizations were applied
--restore Restore user backup from cache/
--restore-wine Restore user backup AND Wine/VARA
--python-tools Install Python tools (uv, pipx, completions)
--chirp Install CHIRP radio programming software
--all Run all checks and installations
(none) Interactive menu
OPTIONS:
-d, --dir DIR Use backup directory (default: cache/)
-v, --verbose Enable verbose output
-h, --help Show this help message
EXAMPLES:
# Interactive mode
./post-install.sh
# Verify only
./post-install.sh --verify
# Install Python tools
./post-install.sh --python-tools
# Restore from specific directory
./post-install.sh --restore --dir ~/backups
# Full automation
./post-install.sh --all
EOF
}
# Parse arguments
BACKUP_DIR="${SCRIPT_DIR}/../cache"
RESTORE_WINE=0
while [[ $# -gt 0 ]]; do
case $1 in
--verify)
verify_customizations
exit $?
;;
--restore)
restore_user_backup "$BACKUP_DIR" "$RESTORE_WINE"
exit $?
;;
--restore-wine)
RESTORE_WINE=1
restore_user_backup "$BACKUP_DIR" "$RESTORE_WINE"
exit $?
;;
--python-tools)
install_python_tools
exit $?
;;
--chirp)
install_chirp
exit $?
;;
--all)
verify_customizations
echo ""
restore_user_backup "$BACKUP_DIR" 0
echo ""
install_python_tools
echo ""
install_chirp
exit $?
;;
-d|--dir)
BACKUP_DIR="$2"
shift 2
;;
-v|--verbose)
VERBOSE=1
shift
;;
-h|--help)
show_help
exit 0
;;
*)
log_error "Unknown option: $1"
show_help
exit 1
;;
esac
done
# Default: interactive menu
if [[ "$MODE" == "interactive" ]]; then
show_menu
fi