Unverified Commit fc6e44a8 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

build: Use mtools instead of libguestfs to generate image (#28)

parent 07e0c5be
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -10,8 +10,8 @@ ARG DEBCONF_NONINTERACTIVE_SEEN="true"
RUN set -eu && \
    apt-get update && \
    apt-get --no-install-recommends -y install \
    guestfish \
    linux-image-generic && \
    fdisk \
    mtools && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

+11 −9
Original line number Diff line number Diff line
@@ -1015,7 +1015,7 @@
			<key>HibernateSkipsPicker</key>
			<false/>
			<key>HideAuxiliary</key>
			<true/>
			<false/>
			<key>InstanceIdentifier</key>
			<string></string>
			<key>LauncherOption</key>
@@ -1037,7 +1037,7 @@
			<key>TakeoffDelay</key>
			<integer>0</integer>
			<key>Timeout</key>
			<integer>15</integer>
			<integer>0</integer>
		</dict>
		<key>Debug</key>
		<dict>
@@ -1063,7 +1063,7 @@
		<key>Security</key>
		<dict>
			<key>AllowSetDefault</key>
			<true/>
			<false/>
			<key>ApECID</key>
			<integer>0</integer>
			<key>AuthRestart</key>
@@ -1083,7 +1083,7 @@
			<key>PasswordSalt</key>
			<data></data>
			<key>ScanPolicy</key>
			<integer>17761027</integer>
			<integer>18809603</integer>
			<key>SecureBootModel</key>
			<string>Disabled</string>
			<key>Vault</key>
@@ -1189,7 +1189,7 @@
				<key>SystemAudioVolume</key>
				<data>Rg==</data>
				<key>boot-args</key>
				<string>-v keepsyms=1 amfi_get_out_of_my_way=1 tlbto_us=0 vti=9</string>
				<string>keepsyms=1</string>
				<key>csr-active-config</key>
				<data>Jg8=</data>
				<key>prev-lang:kbd</key>
@@ -1260,11 +1260,13 @@
			<key>AdviseFeatures</key>
			<false/>
			<key>MLB</key>
			<string>C02119700QXJG36JC</string>
			<string>C02717306J9JG361M</string>
			<key>MaxBIOSVersion</key>
			<false/>
			<key>ProcessorType</key>
			<integer>0</integer>
			<key>ROM</key>
			<string>0022412e3d4a</string>
			<data>m7zhIYfl</data>
			<key>SpoofVendor</key>
			<true/>
			<key>SystemMemoryStatus</key>
@@ -1272,9 +1274,9 @@
			<key>SystemProductName</key>
			<string>iMacPro1,1</string>
			<key>SystemSerialNumber</key>
			<string>C02FPBZPHX87</string>
			<string>C02TM2ZBHX87</string>
			<key>SystemUUID</key>
			<string>213FA768-A62C-4299-8598-47AA666E436F</string>
			<string>007076A6-F2A2-4461-BBE5-BAD019F8025A</string>
		</dict>
		<key>UpdateDataHub</key>
		<true/>
+2 −2
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ kubectl apply -f kubernetes.yml
  
  - Start the container and connect to [port 8006](http://localhost:8006) using your web browser.

  - Select `macOS Base System` by pressing the enter key to begin the installation.
  - Select `macOS Base System` (by pressing the enter key) to begin the installation.

  - Choose `Disk Utility` and then select the largest `Apple Inc. VirtIO Block Media` disk.

@@ -69,7 +69,7 @@ kubectl apply -f kubernetes.yml

  - Close the current window and proceed the installation by clicking `Reinstall macOS`.
  
  - When prompted where you want to install macOS, select the disk you just created previously.
  - When prompted where you want to install it, select the disk you just created previously.
 
  - There will be several reboots, select `macOS Installer` each time until it shows your own disk.

+58 −39
Original line number Diff line number Diff line
#!/usr/bin/env bash
set -Eeuo pipefail

function msg() {
  local txt="$1"
  local bold="\x1b[1m"
  local normal="\x1b[0m"
  echo -e "${bold}### ${txt}${normal}"
}

function cleanup() {
  if test "$GUESTFISH_PID" != ""; then
    guestfish --remote -- exit >/dev/null 2>&1 || true
echo "Extracting template image..."

DST="/images"
OUT="/tmp/extract"

rm -rf "$OUT"
rm -rf "$DST"

mkdir -p "$OUT"
mkdir -p "$DST"

if [ ! -f "$1" ] || [ ! -s "$1" ]; then
  error "Could not find image file \"$1\"." && exit 10
fi
}

function fish() {
  echo "#" "$@"
  guestfish --remote -- "$@" || exit 1
}
START=$(sfdisk -l "$1" | grep -i -m 1 "EFI System" | awk '{print $2}')
mcopy -bspmQ -i "$1@@${START}S" ::EFI "$OUT"

cp "$2" "$OUT/EFI/OC/"

echo "Creating OpenCore image..."

rm -rf /images
msg "Mounting template ISO..."
START=2048
COUNT=522207
SIZE=268435456

trap 'cleanup' EXIT
FILE="OpenCore.img"
IMG="/tmp/$SIZE.img"
NAME=$(basename "$IMG")

export LIBGUESTFS_BACKEND=direct
# shellcheck disable=SC2046
eval $(guestfish --listen)
if test "$GUESTFISH_PID" = ""; then
  echo "ERROR: Starting Guestfish failed!"
  exit 1
rm -f "$IMG"

if ! truncate -s "$SIZE" "$IMG"; then
  rm -f "$IMG"
  error "Could not allocate file $IMG for the OpenCore image." && exit 11
fi

fish add "$1"
fish run
fish mount /dev/sda1 /
fish ls /EFI
PART="/tmp/partition.fdisk"

{       echo "label: gpt"
        echo "label-id: 1ACB1E00-3B8F-4B2A-86A4-D99ED21DCAEB"
        echo "device: $NAME"
        echo "unit: sectors"
        echo "first-lba: 34"
        echo "last-lba: 524254"
        echo "sector-size: 512"
        echo ""
        echo "${NAME}1 : start=$START, size=$COUNT, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=05157F6E-0AE8-4D1A-BEA5-AC172453D02C, name=\"primary\""

} > "$PART"

sfdisk -q "$IMG" < "$PART"

echo "drive c: file=\"$IMG\" partition=0 offset=1048576" > /etc/mtools.conf

mformat -F -M 512 -c 4 -T "$COUNT" -v "EFI" "C:"

msg "Overriding config..."
echo "Copying files to image..."

fish copy-in "$2" /EFI/OC/
fish umount-all
mcopy -bspmQ "$OUT/EFI" "C:"

mkdir -p /images
mv "$1" /images/OpenCore.img
mv -f "$IMG" "$DST/$FILE"

msg "Finished succesfully!"
echo "Finished succesfully!"