@underpostnet/underpost 2.96.0 → 2.97.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/.dockerignore +1 -2
  2. package/.env.development +0 -3
  3. package/.env.production +0 -3
  4. package/.env.test +0 -3
  5. package/.prettierignore +1 -2
  6. package/README.md +31 -31
  7. package/baremetal/commission-workflows.json +64 -17
  8. package/baremetal/packer-workflows.json +11 -0
  9. package/cli.md +72 -40
  10. package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
  11. package/manifests/deployment/dd-test-development/deployment.yaml +4 -4
  12. package/package.json +3 -2
  13. package/packer/images/Rocky9Amd64/rocky9.pkr.hcl +6 -2
  14. package/packer/images/Rocky9Arm64/Makefile +69 -0
  15. package/packer/images/Rocky9Arm64/README.md +122 -0
  16. package/packer/images/Rocky9Arm64/http/rocky9.ks.pkrtpl.hcl +114 -0
  17. package/packer/images/Rocky9Arm64/rocky9.pkr.hcl +171 -0
  18. package/scripts/disk-clean.sh +128 -187
  19. package/scripts/ipxe-setup.sh +197 -0
  20. package/scripts/packer-init-vars-file.sh +16 -6
  21. package/scripts/packer-setup.sh +270 -33
  22. package/scripts/ports-ls.sh +31 -0
  23. package/scripts/quick-tftp.sh +19 -0
  24. package/src/api/document/document.controller.js +15 -0
  25. package/src/api/document/document.model.js +14 -0
  26. package/src/api/document/document.router.js +1 -0
  27. package/src/api/document/document.service.js +61 -3
  28. package/src/cli/baremetal.js +1716 -439
  29. package/src/cli/cloud-init.js +354 -231
  30. package/src/cli/cluster.js +1 -1
  31. package/src/cli/db.js +22 -0
  32. package/src/cli/deploy.js +6 -2
  33. package/src/cli/image.js +1 -0
  34. package/src/cli/index.js +40 -36
  35. package/src/cli/run.js +77 -11
  36. package/src/cli/ssh.js +1 -1
  37. package/src/client/components/core/Input.js +3 -1
  38. package/src/client/components/core/Panel.js +161 -15
  39. package/src/client/components/core/PanelForm.js +198 -35
  40. package/src/client/components/core/Translate.js +11 -0
  41. package/src/client/services/document/document.service.js +19 -0
  42. package/src/index.js +2 -1
  43. package/src/server/dns.js +8 -2
  44. package/src/server/start.js +14 -6
  45. package/manifests/mariadb/config.yaml +0 -10
  46. package/manifests/mariadb/secret.yaml +0 -8
@@ -1,216 +1,157 @@
1
1
  #!/usr/bin/env bash
2
2
  # disk-clean.sh
3
- # Safe, interactive disk cleanup for Rocky/RHEL-like systems.
4
-
5
- set -u # Detect undefined variables (removed -e to handle errors manually where it matters)
6
- IFS=$'\n\t'
7
-
8
- AUTO_YES=0
9
- LXD_FLAG=0
10
- VACUUM_SIZE="500M"
11
- TMP_AGE_DAYS=7
12
- LOG_GZ_AGE_DAYS=90
13
- ROOT_CACHE_AGE_DAYS=30
14
- AGGRESSIVE=0
15
-
16
- # Colors for better readability
17
- RED='\033[0;31m'
18
- GREEN='\033[0;32m'
19
- YELLOW='\033[1;33m'
20
- NC='\033[0m' # No Color
21
-
22
- usage() {
23
- cat <<EOF
24
- Usage: $0 [--yes] [--aggressive] [--lxd] [--vacuum-size SIZE]
25
-
26
- Options:
27
- --yes run destructive actions without asking
28
- --aggressive clean user caches (npm, pip, conda, root .cache)
29
- --lxd enable lxc image prune
30
- --vacuum-size X set journalctl --vacuum-size (default: $VACUUM_SIZE)
31
- -h, --help show this help
32
- EOF
3
+ # Automatic safe cleanup script for Rocky Linux 9
4
+ # This script ALWAYS runs non-interactively (batch)
5
+ # Usage: sudo ./disk-clean.sh
6
+ set -euo pipefail
7
+
8
+ VACUUM_SIZE="200M" # journalctl vacuum target
9
+ LARGE_LOG_SIZE="+100M" # threshold for truncation (find syntax)
10
+ TMP_AGE_DAYS=3 # remove files older than this from /tmp and /var/tmp
11
+ CACHE_AGE_DAYS=30 # remove caches older than this from /var/cache
12
+ KEEP_KERNELS=2 # keep this many latest kernels
13
+ REMOVE_OPT=0 # ALWAYS allow removing /opt entries (user requested)
14
+
15
+ timestamp() { date +"%F %T"; }
16
+ log() {
17
+ echo "$(timestamp) $*"
33
18
  }
34
19
 
35
- # Parse args
36
- while [[ $# -gt 0 ]]; do
37
- case "$1" in
38
- --yes) AUTO_YES=1; shift;;
39
- --aggressive) AGGRESSIVE=1; shift;;
40
- --lxd) LXD_FLAG=1; shift;;
41
- --vacuum-size) VACUUM_SIZE="$2"; shift 2;;
42
- -h|--help) usage; exit 0;;
43
- *) echo "Unknown argument: $1"; usage; exit 2;;
44
- esac
45
- done
20
+ # must be root
21
+ if [ "$EUID" -ne 0 ]; then
22
+ echo "This script must be run as root. Exiting."
23
+ exit 1
24
+ fi
46
25
 
47
- log() { echo -e "${GREEN}[INFO]${NC} $*"; }
48
- warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
49
- error() { echo -e "${RED}[ERROR]${NC} $*"; }
50
-
51
- run() {
52
- # Runs the command safely
53
- echo "+ $*"
54
- # Execute the command passed as arguments, preserving quotes/spaces
55
- "$@" || {
56
- warn "Command failed (non-critical): $*"
57
- return 0
58
- }
59
- }
26
+ log "=== Starting Rocky Linux 9 automated cleanup (batch mode) ==="
27
+ log "Command line: $0 $*"
28
+ log "REMOVE_OPT=$REMOVE_OPT"
29
+ log "VACUUM_SIZE=$VACUUM_SIZE, LARGE_LOG_SIZE=$LARGE_LOG_SIZE, TMP_AGE_DAYS=$TMP_AGE_DAYS, CACHE_AGE_DAYS=$CACHE_AGE_DAYS"
30
+
31
+ # Report current disk usage
32
+ log "Disk usage before cleanup:"
33
+ df -h
34
+ log "Top-level disk usage ( / ):"
35
+ du -xh --max-depth=1 / | sort -rh | head -n 20
36
+
37
+ # 1) DNF cleanup
38
+ log "Cleaning DNF caches and removing orphaned packages..."
39
+ dnf -y clean all || true
40
+ dnf -y autoremove || true
41
+
42
+ # 2) Journal logs vacuum
43
+ log "Vacuuming systemd journal to keep ${VACUUM_SIZE}..."
44
+ journalctl --vacuum-size="$VACUUM_SIZE" || true
45
+
46
+ # 3) Truncate very large logs in /var/log (safer than delete)
47
+ log "Truncating logs in /var/log larger than ${LARGE_LOG_SIZE} (keeps zero-sized file so services don't break)..."
48
+ find /var/log -type f -size "$LARGE_LOG_SIZE" -print0 2>/dev/null | while IFS= read -r -d '' f; do
49
+ echo "Truncating $f"
50
+ : > "$f" || echo "Failed to truncate $f"
51
+ done
60
52
 
61
- confirm() {
62
- if [[ $AUTO_YES -eq 1 ]]; then
63
- return 0
53
+ # 4) Clean /tmp and /var/tmp older than TMP_AGE_DAYS
54
+ log "Removing files older than ${TMP_AGE_DAYS} days from /tmp and /var/tmp..."
55
+ find /tmp -mindepth 1 -mtime +"$TMP_AGE_DAYS" -print0 2>/dev/null | xargs -0r rm -rf -- || true
56
+ find /var/tmp -mindepth 1 -mtime +"$TMP_AGE_DAYS" -print0 2>/dev/null | xargs -0r rm -rf -- || true
57
+
58
+ # 5) Clean /var/cache older than CACHE_AGE_DAYS (but not all cache immediately)
59
+ log "Removing entries in /var/cache older than ${CACHE_AGE_DAYS} days..."
60
+ find /var/cache -mindepth 1 -mtime +"$CACHE_AGE_DAYS" -print0 2>/dev/null | xargs -0r rm -rf -- || true
61
+
62
+ # 6) Clean user caches (~/.cache) and Downloads older than CACHE_AGE_DAYS
63
+ log "Cleaning user caches and old downloads (home dirs)..."
64
+ for homedir in /home/* /root; do
65
+ [ -d "$homedir" ] || continue
66
+ usercache="$homedir/.cache"
67
+ userdownloads="$homedir/Downloads"
68
+ usertrash="$homedir/.local/share/Trash"
69
+
70
+ if [ -d "$usercache" ]; then
71
+ log "Removing contents of $usercache"
72
+ rm -rf "${usercache:?}/"* 2>/dev/null || true
64
73
  fi
65
- # Use </dev/tty to ensure we read from user even inside a pipe loop
66
- read -r -p "$1 [y/N]: " ans </dev/tty
67
- case "$ans" in
68
- [Yy]|[Yy][Ee][Ss]) return 0;;
69
- *) return 1;;
70
- esac
71
- }
72
-
73
- require_root() {
74
- if [[ $EUID -ne 0 ]]; then
75
- error "This script must be run as root."
76
- exit 1
74
+ if [ -d "$userdownloads" ]; then
75
+ log "Removing files older than ${CACHE_AGE_DAYS} days from $userdownloads"
76
+ find "$userdownloads" -type f -mtime +"$CACHE_AGE_DAYS" -print0 2>/dev/null | xargs -0r rm -f -- 2>/dev/null || true
77
77
  fi
78
- }
79
-
80
- command_exists() {
81
- command -v "$1" >/dev/null 2>&1
82
- }
83
-
84
- require_root
85
-
86
- log "Starting cleanup (aggressive=$AGGRESSIVE)"
87
-
88
- # 1) Package Manager (DNF)
89
- if command_exists dnf; then
90
- log "Cleaning DNF caches"
91
- run dnf clean all
92
- run rm -rf /var/cache/dnf
93
- if confirm "Run 'dnf autoremove -y' for orphan packages?"; then
94
- run dnf autoremove -y
95
- else
96
- log "Skipped dnf autoremove"
78
+ if [ -d "$usertrash" ]; then
79
+ log "Emptying trash in $usertrash"
80
+ rm -rf "${usertrash:?}/"* 2>/dev/null || true
97
81
  fi
98
- else
99
- warn "dnf not found"
100
- fi
101
-
102
- # 2) Journal logs
103
- if command_exists journalctl; then
104
- log "Current Journal disk usage:"
105
- journalctl --disk-usage || true
82
+ done
106
83
 
107
- if confirm "Run 'journalctl --vacuum-size=$VACUUM_SIZE'?"; then
108
- run journalctl --vacuum-size="$VACUUM_SIZE"
109
- else
110
- log "Skipped journal vacuum"
111
- fi
84
+ # 7) Docker / Podman cleanup (if present)
85
+ if command -v docker >/dev/null 2>&1; then
86
+ log "Docker detected: pruning images/containers/volumes (aggressive)..."
87
+ docker system df || true
88
+ docker system prune -a --volumes -f || true
112
89
  fi
113
90
 
114
- # 3) /var/tmp
115
- if [[ -d /var/tmp ]]; then
116
- if confirm "Delete files in /var/tmp older than $TMP_AGE_DAYS days?"; then
117
- find /var/tmp -mindepth 1 -mtime +$TMP_AGE_DAYS -delete
118
- fi
91
+ if command -v podman >/dev/null 2>&1; then
92
+ log "Podman detected: pruning images/containers (aggressive)..."
93
+ podman system df || true
94
+ podman system prune -a -f || true
119
95
  fi
120
96
 
121
- # 4) Old compressed logs
122
- if [[ -d /var/log ]]; then
123
- if confirm "Delete compressed logs (.gz) in /var/log older than $LOG_GZ_AGE_DAYS days?"; then
124
- find /var/log -type f -name '*.gz' -mtime +$LOG_GZ_AGE_DAYS -delete
125
- fi
97
+ # 8) Flatpak unused runtimes/apps (if present)
98
+ if command -v flatpak >/dev/null 2>&1; then
99
+ log "Flatpak detected: trying to uninstall unused runtimes/apps..."
100
+ flatpak uninstall --unused -y || flatpak uninstall --unused || true
101
+ flatpak repair || true
126
102
  fi
127
103
 
128
- # 5) Snap: disabled revisions
129
- if command_exists snap; then
130
- log "Searching for old Snap revisions"
131
- # Save to variable only if successful
132
- disabled_snaps=$(snap list --all 2>/dev/null | awk '/disabled/ {print $1, $3}') || disabled_snaps=""
133
-
134
- if [[ -n "$disabled_snaps" ]]; then
135
- echo "Disabled snap revisions found:"
136
- echo "$disabled_snaps"
137
- if confirm "Remove all disabled revisions?"; then
138
- while read -r pkg rev; do
139
- [[ -z "$pkg" ]] && continue
140
- log "Removing snap $pkg (revision $rev)"
141
- run snap remove "$pkg" --revision="$rev"
142
- done <<< "$disabled_snaps"
143
-
144
- log "Setting snap retention to 2"
145
- run snap set system refresh.retain=2
146
- fi
147
- else
148
- log "No disabled snap revisions found."
104
+ # 9) Python Pip cleanup
105
+ if command -v pip3 >/dev/null 2>&1 || command -v pip >/dev/null 2>&1; then
106
+ log "Python Pip detected: cleaning cache..."
107
+ if command -v pip3 >/dev/null 2>&1; then
108
+ pip3 cache purge || true
109
+ elif command -v pip >/dev/null 2>&1; then
110
+ pip cache purge || true
149
111
  fi
150
112
  fi
151
113
 
152
- # 6) LXD
153
- if command_exists lxc; then
154
- if [[ $LXD_FLAG -eq 1 ]]; then
155
- if confirm "Run 'lxc image prune'?"; then
156
- run lxc image prune -f
157
- fi
158
- else
159
- log "Skipping LXD (use --lxd to enable)"
160
- fi
114
+ # 10) Conda cleanup
115
+ if command -v conda >/dev/null 2>&1; then
116
+ log "Conda detected: cleaning all..."
117
+ conda clean --all -y || true
161
118
  fi
162
119
 
163
- # 7) Docker / Containerd
164
- if command_exists docker; then
165
- if confirm "Run 'docker system prune -a --volumes'? (WARNING: Removes stopped containers)"; then
166
- run docker system prune -a --volumes -f
167
- fi
168
- elif command_exists crictl; then
169
- if confirm "Attempt to remove images with crictl?"; then
170
- run crictl rmi --prune
171
- fi
120
+ # 11) Remove old kernels but keep the last KEEP_KERNELS (safe)
121
+ log "Removing old kernels, keeping the last $KEEP_KERNELS kernels..."
122
+ OLD_KERNELS=$(dnf repoquery --installonly --latest-limit=-$KEEP_KERNELS -q 2>/dev/null || true)
123
+ if [ -n "$OLD_KERNELS" ]; then
124
+ log "Old kernels to remove: $OLD_KERNELS"
125
+ dnf -y remove $OLD_KERNELS || true
126
+ else
127
+ log "No old kernels found by DNF repoquery. Only $KEEP_KERNELS or fewer are currently installed."
172
128
  fi
173
129
 
174
- # 8) Large Files (>1G) - Completely rewritten logic
175
- log "Scanning for files larger than 1G (this may take a while)..."
176
-
177
- # Use while loop with find -print0 to handle filenames with spaces safely
178
- FOUND_LARGE=0
179
- # Note: find does not modify filesystem here, safe to run always
180
- while IFS= read -r -d '' file; do
181
- FOUND_LARGE=1
182
- # Get readable size to show user
183
- filesize=$(du -h "$file" | cut -f1)
184
-
185
- echo -e "Large file found: ${YELLOW}$file${NC} (Size: $filesize)"
186
-
187
- if confirm " -> Delete this file?"; then
188
- run rm -vf "$file"
130
+ # 12) /opt review and removal (ON by default now)
131
+ if [ -d /opt ]; then
132
+ log "/opt usage (top entries):"
133
+ du -sh /opt/* 2>/dev/null | sort -h | head -n 20 || true
134
+
135
+ if [ "$REMOVE_OPT" = "1" ]; then
136
+ OPT_TARGETS=(/opt/local-path-provisioner)
137
+ for t in "${OPT_TARGETS[@]}"; do
138
+ if [ -d "$t" ]; then
139
+ log "Removing $t as REMOVE_OPT=1"
140
+ rm -rf "$t" || true
141
+ fi
142
+ done
189
143
  else
190
- log "Skipped: $file"
144
+ log "Automatic /opt removals disabled (set REMOVE_OPT=1 to enable)."
191
145
  fi
192
- done < <(find / -xdev -type f -size +1G -print0 2>/dev/null)
193
-
194
- if [[ $FOUND_LARGE -eq 0 ]]; then
195
- log "No files >1G found in /"
196
146
  fi
197
147
 
198
- # 9) Aggressive Caches
199
- if [[ $AGGRESSIVE -eq 1 ]]; then
200
- log "Aggressive mode enabled"
201
- command_exists npm && confirm "Run 'npm cache clean --force'?" && run npm cache clean --force
202
- command_exists pip && confirm "Run 'pip cache purge'?" && run pip cache purge
203
- command_exists conda && confirm "Run 'conda clean --all -y'?" && run conda clean --all -y
204
-
205
- if [[ -d /root/.cache ]]; then
206
- if confirm "Delete /root/.cache (> $ROOT_CACHE_AGE_DAYS days)?"; then
207
- find /root/.cache -type f -mtime +$ROOT_CACHE_AGE_DAYS -delete
208
- fi
209
- fi
210
- fi
148
+ # 13) Find large files > 100MB (report only)
149
+ log "Listing files larger than 100MB (report only):"
150
+ find / -xdev -type f -size +100M -printf '%s\t%p\n' 2>/dev/null | sort -nr | head -n 50 | awk '{printf "%.1fMB\t%s\n",$1/1024/1024,$2}' || true
211
151
 
212
- # 10) Final
213
- log "Final disk usage:"
214
- df -h --total | grep total || df -h /
152
+ # Final disk usage
153
+ log "Disk usage after cleanup:"
154
+ df -h
215
155
 
216
- log "Cleanup finished."
156
+ log "=== Cleanup finished ==="
157
+ exit 0
@@ -0,0 +1,197 @@
1
+ #!/bin/bash
2
+
3
+ # --- Configuration ---
4
+ # Set the target architecture you want to build for.
5
+ # Options: "aarch64" (for ARM64 servers/devices) or "x86_64" (for standard Intel/AMD servers)
6
+ TARGET_ARCH="${TARGET_ARCH:-aarch64}"
7
+
8
+ IPXE_SRC_DIR="/home/dd/ipxe"
9
+ EFI_FILENAME="ipxe.efi"
10
+
11
+ # --- Argument Parsing ---
12
+ TARGET_DIR_ARG=""
13
+ REBUILD=false
14
+ EMBED_SCRIPT=""
15
+
16
+ while [[ $# -gt 0 ]]; do
17
+ case $1 in
18
+ --rebuild)
19
+ REBUILD=true
20
+ shift # past argument
21
+ ;;
22
+ --target-arch)
23
+ case "$2" in
24
+ arm64)
25
+ TARGET_ARCH="aarch64"
26
+ ;;
27
+ amd64)
28
+ TARGET_ARCH="x86_64"
29
+ ;;
30
+ *)
31
+ echo "Error: Unsupported architecture '$2'. Use 'arm64' or 'amd64'."
32
+ exit 1
33
+ ;;
34
+ esac
35
+ shift # past argument
36
+ shift # past value
37
+ ;;
38
+ --embed-script)
39
+ EMBED_SCRIPT="$2"
40
+ shift # past argument
41
+ shift # past value
42
+ ;;
43
+ *)
44
+ if [ -z "$TARGET_DIR_ARG" ]; then
45
+ TARGET_DIR_ARG="$1"
46
+ fi
47
+ shift # past argument
48
+ ;;
49
+ esac
50
+ done
51
+
52
+ # Use argument if provided, otherwise env var, otherwise current dir
53
+ TARGET_DIR="${TARGET_DIR_ARG:-${TARGET_DIR:-.}}"
54
+
55
+ # --- 1. Detect System Architecture ---
56
+ HOST_ARCH=$(uname -m)
57
+ echo "--- System Detection ---"
58
+ echo "Host Architecture: $HOST_ARCH"
59
+ echo "Target Architecture: $TARGET_ARCH"
60
+ echo "Target Directory: $TARGET_DIR"
61
+ echo "Rebuild Mode: $REBUILD"
62
+ echo "Embed Script: ${EMBED_SCRIPT:-none}"
63
+
64
+ # Determine iPXE build target based on requested architecture
65
+ if [ "$TARGET_ARCH" = "aarch64" ]; then
66
+ BUILD_TARGET="bin-arm64-efi/ipxe.efi"
67
+ elif [ "$TARGET_ARCH" = "x86_64" ]; then
68
+ BUILD_TARGET="bin-x86_64-efi/ipxe.efi"
69
+ else
70
+ echo "Error: Unsupported target architecture '$TARGET_ARCH'"
71
+ exit 1
72
+ fi
73
+
74
+ # Define the full path to the compiled binary
75
+ COMPILED_SRC_PATH="$IPXE_SRC_DIR/src/$BUILD_TARGET"
76
+
77
+ # Decide whether to build
78
+ DO_BUILD=false
79
+
80
+ if [ "$REBUILD" = true ]; then
81
+ DO_BUILD=true
82
+ elif [ ! -f "$COMPILED_SRC_PATH" ]; then
83
+ echo "Binary not found at $COMPILED_SRC_PATH. Initiating build..."
84
+ DO_BUILD=true
85
+ else
86
+ echo "Binary found at $COMPILED_SRC_PATH. Skipping build."
87
+ fi
88
+
89
+ if [ "$DO_BUILD" = true ]; then
90
+
91
+ # Helper function for package manager
92
+ if command -v dnf &> /dev/null; then
93
+ PKG_MGR="dnf"
94
+ else
95
+ PKG_MGR="yum"
96
+ fi
97
+
98
+ # --- 2. Install Dependencies (RHEL/CentOS/Fedora) ---
99
+ echo ""
100
+ echo "--- Installing Build Dependencies ---"
101
+ echo "Requesting sudo permissions..."
102
+
103
+ COMMON_PKGS="git make binutils-devel xz-devel perl"
104
+
105
+ # Logic to determine if we need native or cross-compilers
106
+ if [ "$HOST_ARCH" = "$TARGET_ARCH" ]; then
107
+ # Native compilation
108
+ echo "Architecture match ($HOST_ARCH). Installing native GCC..."
109
+ sudo $PKG_MGR install -y $COMMON_PKGS gcc
110
+ CROSS_COMPILE_PREFIX=""
111
+
112
+ elif [ "$HOST_ARCH" = "x86_64" ] && [ "$TARGET_ARCH" = "aarch64" ]; then
113
+ # Cross-compilation: x86_64 host -> aarch64 target
114
+ echo "Cross-compiling for $TARGET_ARCH on $HOST_ARCH..."
115
+ # Note: Ensure EPEL repo is enabled on RHEL/CentOS for this package
116
+ sudo $PKG_MGR install -y $COMMON_PKGS gcc-aarch64-linux-gnu
117
+ CROSS_COMPILE_PREFIX="aarch64-linux-gnu-"
118
+
119
+ else
120
+ echo "Error: No automated path defined for Host: $HOST_ARCH -> Target: $TARGET_ARCH"
121
+ echo "You may need to install specific cross-compilers manually."
122
+ exit 1
123
+ fi
124
+
125
+ # --- 3. Clone iPXE Source ---
126
+ echo ""
127
+ echo "--- Downloading iPXE Source Code ---"
128
+ if [ -d "$IPXE_SRC_DIR" ]; then
129
+ echo "Directory $IPXE_SRC_DIR already exists. Pulling latest changes..."
130
+ cd $IPXE_SRC_DIR
131
+ git pull
132
+ else
133
+ git clone https://github.com/ipxe/ipxe.git $IPXE_SRC_DIR
134
+ cd $IPXE_SRC_DIR
135
+ fi
136
+
137
+ # --- 4. Compile the Binary ---
138
+ echo ""
139
+ echo "--- Compiling $EFI_FILENAME for $TARGET_ARCH ---"
140
+ cd src
141
+
142
+ # Clean previous builds to ensure no arch mismatch
143
+ make clean
144
+
145
+ # Build with embedded script if provided
146
+ if [ -n "$EMBED_SCRIPT" ]; then
147
+ echo "Embedding script into iPXE binary..."
148
+ if [ ! -f "$EMBED_SCRIPT" ]; then
149
+ echo "Error: Embed script file not found: $EMBED_SCRIPT"
150
+ exit 1
151
+ fi
152
+ echo "Running make for target: $BUILD_TARGET with EMBED=$EMBED_SCRIPT..."
153
+ make CROSS_COMPILE=$CROSS_COMPILE_PREFIX EMBED="$EMBED_SCRIPT" $BUILD_TARGET
154
+ else
155
+ echo "Running make for target: $BUILD_TARGET..."
156
+ make CROSS_COMPILE=$CROSS_COMPILE_PREFIX $BUILD_TARGET
157
+ fi
158
+
159
+ if [ $? -ne 0 ]; then
160
+ echo "Error: Compilation failed."
161
+ if [ -n "$CROSS_COMPILE_PREFIX" ]; then
162
+ echo "Check that cross-compiler '$CROSS_COMPILE_PREFIX' is installed and in your PATH."
163
+ fi
164
+ exit 1
165
+ fi
166
+ fi
167
+
168
+ # --- 5. Deploy Binary ---
169
+ echo ""
170
+ echo "--- Deploying Binary ---"
171
+
172
+ # Copy the file
173
+ if [ -f "$COMPILED_SRC_PATH" ]; then
174
+ # Create target directory if it doesn't exist
175
+ if [ ! -d "$TARGET_DIR" ]; then
176
+ echo "Creating target directory: $TARGET_DIR"
177
+ mkdir -p "$TARGET_DIR"
178
+ fi
179
+
180
+ echo "Copying $COMPILED_SRC_PATH to $TARGET_DIR/$EFI_FILENAME..."
181
+ cp "$COMPILED_SRC_PATH" "$TARGET_DIR/$EFI_FILENAME"
182
+
183
+ if [ $? -eq 0 ]; then
184
+ echo "✓ Success!"
185
+ echo "---------------------------------------------------"
186
+ echo "Target: $TARGET_ARCH"
187
+ echo "Source: $COMPILED_SRC_PATH"
188
+ echo "Destination: $TARGET_DIR/$EFI_FILENAME"
189
+ echo "---------------------------------------------------"
190
+ else
191
+ echo "Error: Failed to copy file to $TARGET_DIR"
192
+ exit 1
193
+ fi
194
+ else
195
+ echo "Error: Compiled file not found at $COMPILED_SRC_PATH"
196
+ exit 1
197
+ fi
@@ -14,15 +14,25 @@ for image_dir in "$PACKER_DIR"/*; do
14
14
  echo "Checking UEFI VARS files for $image_name..."
15
15
 
16
16
  # Create x86_64 VARS file if it doesn't exist
17
- if [ -f /usr/share/edk2/ovmf/OVMF_VARS.fd ] && [ ! -f "$image_dir/x86_64_VARS.fd" ]; then
18
- cp /usr/share/edk2/ovmf/OVMF_VARS.fd "$image_dir/x86_64_VARS.fd"
19
- echo "Created $image_dir/x86_64_VARS.fd"
17
+ if [ ! -f "$image_dir/x86_64_VARS.fd" ]; then
18
+ for src in /usr/share/edk2/ovmf/OVMF_VARS.fd /usr/share/OVMF/OVMF_VARS.fd; do
19
+ if [ -f "$src" ]; then
20
+ cp "$src" "$image_dir/x86_64_VARS.fd"
21
+ echo "Created $image_dir/x86_64_VARS.fd from $src"
22
+ break
23
+ fi
24
+ done
20
25
  fi
21
26
 
22
27
  # Create aarch64 VARS file if it doesn't exist
23
- if [ -f /usr/share/edk2/aarch64/AAVMF_VARS.fd ] && [ ! -f "$image_dir/aarch64_VARS.fd" ]; then
24
- cp /usr/share/edk2/aarch64/AAVMF_VARS.fd "$image_dir/aarch64_VARS.fd"
25
- echo "Created $image_dir/aarch64_VARS.fd"
28
+ if [ ! -f "$image_dir/aarch64_VARS.fd" ]; then
29
+ for src in /usr/share/AAVMF/AAVMF_VARS.fd /usr/share/edk2/aarch64/AAVMF_VARS.fd /usr/share/edk2/aarch64/QEMU_VARS.fd; do
30
+ if [ -f "$src" ]; then
31
+ cp "$src" "$image_dir/aarch64_VARS.fd"
32
+ echo "Created $image_dir/aarch64_VARS.fd from $src"
33
+ break
34
+ fi
35
+ done
26
36
  fi
27
37
  fi
28
38
  done