-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPacker.sh
More file actions
executable file
·77 lines (59 loc) · 1.65 KB
/
Packer.sh
File metadata and controls
executable file
·77 lines (59 loc) · 1.65 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
#!/bin/bash
# 2025 08 30 - MK Initial Commit
# 2025 09 01 - Few typos
# 2025 12 10 - Per-template .pkr.env.hcl files
set -e
echo ""
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEMPLATES_DIR="$SCRIPT_DIR/Packs"
REQUIRED_PLAYBOOK="$SCRIPT_DIR/ansible/playbook-system-updater.yml"
# Check for ANSIBLE playbook file
if [[ ! -f "$REQUIRED_PLAYBOOK" ]]; then
echo "Required playbook not found: $REQUIRED_PLAYBOOK"
exit 1
fi
if [[ ! -d "$TEMPLATES_DIR" ]]; then
echo "Templates directory not found: $TEMPLATES_DIR"
exit 1
fi
# Build list of .pkr.hcl files
recipes=()
for f in "$TEMPLATES_DIR"/*.pkr.hcl; do
[ -e "$f" ] || continue # skip if none found
recipes+=("$f")
done
if [[ ${#recipes[@]} -eq 0 ]]; then
echo "No .pkr.hcl files found in $TEMPLATES_DIR"
exit 1
fi
echo ""
echo "PACKER BUILDER"
echo "Available recipes:"
i=1
for recipe in "${recipes[@]}"; do
printf "%2d) %s\n" "$i" "$(basename "$recipe")"
i=$((i+1))
done
read -rp "Select recipe number to build: " selection
if ! [[ "$selection" =~ ^[0-9]+$ ]] || (( selection < 1 || selection > ${#recipes[@]} )); then
echo "Invalid selection."
exit 1
fi
recipe="${recipes[$((selection-1))]}"
env_file="${recipe%.pkr.hcl}.pkr.env.hcl"
echo ""
echo "Building $(basename "$recipe")"
echo ""
# Verify matching .pkr.env.hcl file exists
if [[ ! -f "$env_file" ]]; then
echo "ERROR: Missing environment file: $(basename "$env_file")"
echo "Expected location: $env_file"
exit 1
fi
echo "Using environment: $(basename "$env_file")"
echo ""
packer init "$recipe"
packer validate -var-file="$env_file" "$recipe"
packer build -var-file="$env_file" "$recipe"
echo ""