@@ -4,30 +4,46 @@ set -e # Exit immediately if a command exits with non-zero status
44# Check if distribution is provided
55if [ -z " $1 " ]; then
66 echo " Usage: $0 <distribution> [version]"
7- echo " distribution: k8s, k3s, or k0s"
8- echo " version: Optional version override (default: uses version in packer config)"
7+ echo " distribution: common, k8s, k3s, or k0s"
8+ echo " version: Optional version override for k8s/k3s/k0s (default: uses version in packer config)"
99 exit 1
1010fi
1111
1212DISTRIBUTION=$1
1313VERSION=$2
1414
1515# Validate distribution
16- if [[ ! " $DISTRIBUTION " =~ ^(k8s| k3s| k0s)$ ]]; then
17- echo " Error: Distribution must be k8s, k3s, or k0s"
16+ if [[ ! " $DISTRIBUTION " =~ ^(common | k8s| k3s| k0s)$ ]]; then
17+ echo " Error: Distribution must be common, k8s, k3s, or k0s"
1818 exit 1
1919fi
2020
21+ # Check if building a distribution-specific box and common box exists
22+ if [[ " $DISTRIBUTION " != " common" ]]; then
23+ # Check if common-base box exists
24+ if ! vagrant box list | grep -q " common-base" ; then
25+ echo " Error: common-base box not found. Please build it first with: $0 common"
26+ exit 1
27+ fi
28+ fi
29+
2130echo " Building $DISTRIBUTION base box..."
2231
2332# Init packer
24- packer init " packer/ $DISTRIBUTION -base-box.pkr.hcl "
25-
26- # Build base box with optional version override
27- if [ -z " $VERSION " ] ; then
28- packer build -force " packer/$DISTRIBUTION -base-box.pkr.hcl"
33+ if [[ " $DISTRIBUTION " == " common " ]] ; then
34+ packer init " packer/common-base-box.pkr.hcl "
35+
36+ # Build common base box (no version parameter needed)
37+ packer build -force " packer/common -base-box.pkr.hcl"
2938else
30- packer build -force -var " version=$VERSION " " packer/$DISTRIBUTION -base-box.pkr.hcl"
39+ packer init " packer/$DISTRIBUTION -base-box.pkr.hcl"
40+
41+ # Build distribution-specific base box with optional version override
42+ if [ -z " $VERSION " ]; then
43+ packer build -force " packer/$DISTRIBUTION -base-box.pkr.hcl"
44+ else
45+ packer build -force -var " version=$VERSION " " packer/$DISTRIBUTION -base-box.pkr.hcl"
46+ fi
3147fi
3248
3349echo " $DISTRIBUTION base box built successfully!"
0 commit comments