-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·557 lines (487 loc) · 16.7 KB
/
install.sh
File metadata and controls
executable file
·557 lines (487 loc) · 16.7 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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
#!/usr/bin/env bash
# shellcheck disable=SC2249
#===============================================================================
# Strict Mode (Bash-first, zsh best-effort)
#===============================================================================
if [[ -n "${ZSH_VERSION:-}" ]]; then
emulate -L sh
setopt NO_UNSET
setopt PIPE_FAIL
setopt NO_BEEP
fi
set -uo pipefail
IFS=$'\n\t'
# =============================================================================
# NAME : install.sh
# DESCRIPTION : Pentest environment installer with TUI menu and CLI modes.
# Orchestrator/dispatcher only - no heavy logic.
# AUTHOR : Adam Compton
# DATE CREATED: 2025-01-17
# =============================================================================
# EDIT HISTORY:
# DATE | EDITED BY | DESCRIPTION OF CHANGE
# ---------------------|--------------|----------------------------------------
# 2025-01-17 | Claude | Initial creation (refactored entrypoint).
# 2026-01-17 | Claude | Migrated to new common_core API.
# | | Removed load_common_core (config.sh does it).
# | | Added --dry-run support.
# =============================================================================
###############################################################################
# Version
###############################################################################
readonly VERSION="2.0.0"
###############################################################################
# Determine script directory
###############################################################################
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export SCRIPT_DIR
###############################################################################
# Bootstrap logging (until common_core is loaded via config.sh)
###############################################################################
function _bootstrap_info() { printf '[INFO ] %s\n' "${*}" >&2; }
function _bootstrap_warn() { printf '[WARN ] %s\n' "${*}" >&2; }
function _bootstrap_error() { printf '[ERROR] %s\n' "${*}" >&2; }
function _bootstrap_fail() { printf '[FAIL ] %s\n' "${*}" >&2; }
###############################################################################
# function show_usage()
#------------------------------------------------------------------------------
# Purpose : Display usage information.
# Usage : show_usage
# Returns : PASS (0) always
###############################################################################
function show_usage() {
cat << EOF
Pentest Setup Installer v${VERSION}
USAGE:
./install.sh [OPTIONS]
OPTIONS:
(no options) Launch interactive TUI menu
--auto Run full installation non-interactively
--dry-run Show what would be done without executing
--preflight Run pre-flight checks only
--env Run environment setup only
--req Run requirements installation only
--tools Run tools installation only
--post Run post-installation tasks only
--test Test all tool installations
--help, -h Show this help message
--version, -v Show version information
ENVIRONMENT:
DEBUG=true Enable debug output
DRY_RUN=true Enable dry-run mode
EXAMPLES:
./install.sh # Interactive TUI menu
./install.sh --auto # Full automated installation
./install.sh --auto --dry-run # Show what --auto would do
./install.sh --env --req # Setup environment and requirements
./install.sh --test # Test all installed tools
REQUIREMENTS:
- Ubuntu 20.04+ or Debian 11+ (including WSL2)
- Bash 4.0+
- common_core library at ~/.config/bash/lib/common_core
- Root privileges recommended for system-wide installations
EOF
}
###############################################################################
# function show_version()
#------------------------------------------------------------------------------
# Purpose : Display version information.
# Usage : show_version
# Returns : PASS (0) always
###############################################################################
function show_version() {
echo "Pentest Setup Installer v${VERSION}"
}
###############################################################################
# function check_bash_version()
#------------------------------------------------------------------------------
# Purpose : Verify Bash version meets requirements.
# Usage : check_bash_version
# Returns : PASS (0) if OK, FAIL (1) if not
###############################################################################
function check_bash_version() {
if [[ -z "${BASH_VERSION:-}" ]]; then
_bootstrap_fail "This script must be run under Bash"
return 1
fi
if [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then
_bootstrap_fail "Bash 4.0+ required. Current: ${BASH_VERSION}"
return 1
fi
return 0
}
###############################################################################
# function check_home_set()
#------------------------------------------------------------------------------
# Purpose : Ensure HOME environment variable is set.
# Usage : check_home_set
# Returns : PASS (0) if HOME set, FAIL (1) if not
###############################################################################
function check_home_set() {
if [[ -z "${HOME:-}" ]]; then
if command -v getent &> /dev/null; then
HOME=$(getent passwd "$(whoami)" | cut -d: -f6)
export HOME
else
HOME=$(eval echo ~)
export HOME
fi
if [[ -z "${HOME}" ]]; then
_bootstrap_fail "Could not determine HOME directory"
return 1
fi
fi
return 0
}
###############################################################################
# function load_config()
#------------------------------------------------------------------------------
# Purpose : Load configuration files (config.sh sources common_core).
# Usage : load_config
# Returns : PASS (0) if loaded, FAIL (1) if failed
###############################################################################
function load_config() {
local config_file="${SCRIPT_DIR}/config/config.sh"
if [[ ! -f "${config_file}" ]]; then
_bootstrap_fail "Config not found: ${config_file}"
return 1
fi
# shellcheck source=/dev/null
if ! source "${config_file}"; then
_bootstrap_fail "Failed to load: ${config_file}"
return 1
fi
# Now common_core is available, load lists.sh
local lists_file="${SCRIPT_DIR}/config/lists.sh"
if [[ -f "${lists_file}" ]]; then
# shellcheck source=/dev/null
if ! source "${lists_file}"; then
fail "Failed to load: ${lists_file}"
return 1
fi
pass "Loaded configuration files"
fi
return 0
}
###############################################################################
# function load_menus()
#------------------------------------------------------------------------------
# Purpose : Load menu modules from menus/ directory.
# Usage : load_menus
# Returns : PASS (0) if loaded, number of failures otherwise
###############################################################################
function load_menus() {
local -a menu_files=(
"${SCRIPT_DIR}/menus/00_preflight.sh"
"${SCRIPT_DIR}/menus/01_environment.sh"
"${SCRIPT_DIR}/menus/02_requirements.sh"
"${SCRIPT_DIR}/menus/03_tools.sh"
"${SCRIPT_DIR}/menus/04_post.sh"
)
local errors=0
local menu_file
for menu_file in "${menu_files[@]}"; do
if [[ -f "${menu_file}" ]]; then
debug "Loading: ${menu_file}"
# shellcheck source=/dev/null
if source "${menu_file}"; then
debug "Loaded: $(basename "${menu_file}")"
else
fail "Failed to load: ${menu_file}"
((errors++))
fi
else
warn "Menu file not found: ${menu_file}"
((errors++))
fi
done
if ((errors == 0)); then
pass "All menu modules loaded"
fi
return "${errors}"
}
###############################################################################
# function load_tool_modules()
#------------------------------------------------------------------------------
# Purpose : Load tool modules from modules/tools/ directory.
# Usage : load_tool_modules
# Returns : PASS (0) always (warns on failures but continues)
###############################################################################
function load_tool_modules() {
local tools_dir="${SCRIPT_DIR}/modules/tools"
local tool_file
if [[ ! -d "${tools_dir}" ]]; then
warn "Tools directory not found: ${tools_dir}"
return 0
fi
debug "Loading tool modules from: ${tools_dir}"
for tool_file in "${tools_dir}"/*.sh; do
[[ -f "${tool_file}" ]] || continue
# shellcheck source=/dev/null
if ! source "${tool_file}"; then
warn "Failed to load tool module: ${tool_file}"
fi
done
pass "Tool modules loaded"
return 0
}
###############################################################################
# function main_menu()
#------------------------------------------------------------------------------
# Purpose : Display the main interactive menu.
# Usage : main_menu
# Returns : PASS (0) when user exits
###############################################################################
function main_menu() {
local -a menu_items=(
"1) Pre-Flight Checks"
"2) Setup Environment"
"3) Install Requirements"
"4) Install Tools"
"5) Post-Installation"
"6) Run Full Installation"
"7) Test All Tools"
"Q) Quit"
)
while true; do
echo ""
echo "=============================================="
echo " PENTEST SETUP INSTALLER v${VERSION}"
if is_dry_run; then
echo " [DRY-RUN MODE]"
fi
echo "=============================================="
echo ""
for item in "${menu_items[@]}"; do
echo " ${item}"
done
echo ""
read -r -p "Select option: " choice
case "${choice}" in
1)
preflight::run_all
;;
2)
environment::run_all
;;
3)
requirements::run_all
;;
4)
installer::run_all
;;
5)
post::run_all
;;
6)
run_full_installation
;;
7)
post::validate_tool_installs
;;
[Qq])
echo ""
info "Goodbye!"
return 0
;;
*)
warn "Invalid option: ${choice}"
;;
esac
echo ""
read -r -p "Press Enter to continue..."
done
}
###############################################################################
# function run_full_installation()
#------------------------------------------------------------------------------
# Purpose : Run the complete installation process.
# Usage : run_full_installation
# Returns : PASS (0) on success, count of failed sections otherwise
###############################################################################
function run_full_installation() {
local rc=0
echo ""
echo "=============================================="
echo " FULL PENTEST SETUP INSTALLATION"
if is_dry_run; then
echo " [DRY-RUN MODE]"
fi
echo "=============================================="
echo ""
# Step 1: Pre-flight checks
info "Step 1/5: Running pre-flight checks..."
if ! preflight::run_all; then
fail "Pre-flight checks failed"
return 1
fi
echo ""
# Step 2: Environment setup
info "Step 2/5: Setting up environment..."
if ! environment::run_all; then
warn "Environment setup had issues"
((rc++))
fi
echo ""
# Step 3: Requirements installation
info "Step 3/5: Installing requirements..."
if ! requirements::run_all; then
warn "Requirements installation had issues"
((rc++))
fi
echo ""
# Step 4: Tools installation
info "Step 4/5: Installing tools..."
if ! installer::run_all; then
warn "Tools installation had issues"
((rc++))
fi
echo ""
# Step 5: Post-installation
info "Step 5/5: Running post-installation tasks..."
if ! post::run_all; then
warn "Post-installation had issues"
((rc++))
fi
echo ""
if ((rc == 0)); then
pass "Full installation completed successfully!"
else
warn "Installation completed with ${rc} section(s) having issues"
fi
return "${rc}"
}
###############################################################################
# function main()
#------------------------------------------------------------------------------
# Purpose : Main entry point - parse args, load modules, dispatch.
# Usage : main "$@"
# Returns : PASS (0) on success, FAIL (1) on failure
###############################################################################
function main() {
local run_preflight=false
local run_env=false
local run_req=false
local run_tools=false
local run_post=false
local run_test=false
local run_auto=false
local dry_run=false
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--help | -h)
show_usage
return 0
;;
--version | -v)
show_version
return 0
;;
--auto)
run_auto=true
shift
;;
--dry-run)
dry_run=true
shift
;;
--preflight)
run_preflight=true
shift
;;
--env)
run_env=true
shift
;;
--req)
run_req=true
shift
;;
--tools)
run_tools=true
shift
;;
--post)
run_post=true
shift
;;
--test)
run_test=true
shift
;;
*)
_bootstrap_fail "Unknown option: $1"
show_usage
return 1
;;
esac
done
# Check basic requirements before loading anything
if ! check_bash_version; then
return 1
fi
if ! check_home_set; then
return 1
fi
# Set DRY_RUN before loading config
if [[ "${dry_run}" == "true" ]]; then
export DRY_RUN=true
fi
# Load configuration (this also loads common_core)
if ! load_config; then
_bootstrap_fail "Failed to load configuration"
return 1
fi
# Now common_core is available - check root
if ! os::is_root; then
warn "Not running as root. Some operations may fail."
warn "Consider running with: sudo ./install.sh"
fi
# Load menu modules
if ! load_menus; then
warn "Some menu modules failed to load"
fi
# Load tool modules
load_tool_modules
# Determine what to run
if [[ "${run_auto}" == "true" ]]; then
run_full_installation
return $?
fi
# Check if any specific section was requested
local sections_requested=false
for flag in "${run_preflight}" "${run_env}" "${run_req}" "${run_tools}" "${run_post}" "${run_test}"; do
if [[ "${flag}" == "true" ]]; then
sections_requested=true
break
fi
done
if [[ "${sections_requested}" == "true" ]]; then
local rc=0
if [[ "${run_preflight}" == "true" ]]; then
preflight::run_all || ((rc++))
fi
if [[ "${run_env}" == "true" ]]; then
environment::run_all || ((rc++))
fi
if [[ "${run_req}" == "true" ]]; then
requirements::run_all || ((rc++))
fi
if [[ "${run_tools}" == "true" ]]; then
installer::run_all || ((rc++))
fi
if [[ "${run_post}" == "true" ]]; then
post::run_all || ((rc++))
fi
if [[ "${run_test}" == "true" ]]; then
post::validate_tool_installs || ((rc++))
fi
return "${rc}"
fi
# Default: run interactive menu
main_menu
return $?
}
# Run main
main "$@"