Skip to content

Commit

Permalink
feat: Update bootloader automaticly (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Jun 9, 2024
1 parent 76e2781 commit ba8dd28
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM --platform=linux/amd64 debian:trixie-slim AS builder

ARG VERSION_OPENCORE="v21"
ARG REPO_OPENCORE="https://github.com/thenickdude/KVM-Opencore"
ARG VERSION_KVM_OPENCORE="v21"
ARG REPO_KVM_OPENCORE="https://github.com/thenickdude/KVM-Opencore"

ARG DEBCONF_NOWARNINGS="yes"
ARG DEBIAN_FRONTEND="noninteractive"
Expand All @@ -18,7 +18,7 @@ RUN set -eu && \
COPY --chmod=755 ./src/build.sh /run
COPY --chmod=644 ./config.plist /run

ADD $REPO_OPENCORE/releases/download/$VERSION_OPENCORE/OpenCore-$VERSION_OPENCORE.iso.gz /tmp/opencore.iso.gz
ADD $REPO_KVM_OPENCORE/releases/download/$VERSION_KVM_OPENCORE/OpenCore-$VERSION_KVM_OPENCORE.iso.gz /tmp/opencore.iso.gz

RUN gzip -d /tmp/opencore.iso.gz && \
run/build.sh /tmp/opencore.iso /run/config.plist && \
Expand All @@ -28,8 +28,11 @@ FROM scratch AS runner
COPY --from=qemux/qemu-docker:5.11 / /

ARG VERSION_ARG="0.0"
ARG VERSION_OPENCORE="1.0.0"
ARG VERSION_OSX_KVM="326053dd61f49375d5dfb28ee715d38b04b5cd8e"

ARG REPO_OSX_KVM="https://raw.githubusercontent.com/kholia/OSX-KVM"
ARG REPO_OPENCORE="https://raw.githubusercontent.com/acidanthera/OpenCorePkg"

ARG DEBCONF_NOWARNINGS="yes"
ARG DEBIAN_FRONTEND="noninteractive"
Expand All @@ -44,9 +47,9 @@ RUN set -eu && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY --chmod=755 ./src /run/
COPY --from=builder /images /images
COPY --chmod=644 --from=builder /images /images

ADD --chmod=755 $REPO_OSX_KVM/$VERSION_OSX_KVM/fetch-macOS-v2.py /run/
ADD --chmod=755 $REPO_OPENCORE/$VERSION_OPENCORE/Utilities/macrecovery/macrecovery.py /run/
ADD --chmod=644 \
$REPO_OSX_KVM/$VERSION_OSX_KVM/OVMF_CODE.fd \
$REPO_OSX_KVM/$VERSION_OSX_KVM/OVMF_VARS.fd \
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ kubectl apply -f kubernetes.yml

## Acknowledgements

Special thanks to [seitenca](https://github.com/seitenca), [OSX-KVM](https://github.com/kholia/OSX-KVM) and [KVM-Opencore](https://github.com/thenickdude/KVM-Opencore), this project would not exist without their invaluable work.
Special thanks to [seitenca](https://github.com/seitenca), [OpenCore](https://github.com/acidanthera/OpenCorePkg), [OSX-KVM](https://github.com/kholia/OSX-KVM) and [KVM-Opencore](https://github.com/thenickdude/KVM-Opencore), this project would not exist without their invaluable work.

## Stars
[![Stars](https://starchart.cc/dockur/macos.svg?variant=adaptive)](https://starchart.cc/dockur/macos)
Expand Down
15 changes: 14 additions & 1 deletion src/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,24 @@ BOOT_OPTS+=" -drive if=pflash,format=raw,file=$DEST.vars"
# OpenCoreBoot
BOOT_DRIVE_ID="OpenCore"
BOOT_DRIVE="$STORAGE/boot.img"
BOOT_VERSION="$STORAGE/boot.version"
BOOT_FILE="/images/OpenCore.img.gz"
BOOT_SIZE=$(stat -c%s "$BOOT_FILE")

CURRENT_SIZE=""
if [ -f "$BOOT_VERSION" ]; then
CURRENT_SIZE=$(<"$BOOT_VERSION")
fi

if [ "$CURRENT_SIZE" != "$BOOT_SIZE" ]; then
rm -f "$BOOT_DRIVE" 2>/dev/null || true
fi

if [ ! -f "$BOOT_DRIVE" ] || [ ! -s "$BOOT_DRIVE" ]; then
msg="Extracting boot image"
info "$msg..." && html "$msg..."
gzip -dkc /images/OpenCore.img.gz > "$BOOT_DRIVE"
gzip -dkc "$BOOT_FILE" > "$BOOT_DRIVE"
echo "$BOOT_SIZE" > "$BOOT_VERSION"
fi

DISK_OPTS+=" -device virtio-blk-pci,drive=${BOOT_DRIVE_ID},scsi=off,bus=pcie.0,addr=0x5,iothread=io2,bootindex=$BOOT_INDEX"
Expand Down
19 changes: 11 additions & 8 deletions src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set -Eeuo pipefail
TMP="$STORAGE/tmp"
BASE_IMG_ID="InstallMedia"
BASE_IMG="$STORAGE/base.dmg"
BASE_VERSION="$STORAGE/$PROCESS.version"

downloadImage() {

Expand All @@ -32,15 +33,15 @@ downloadImage() {
esac

local msg="Downloading macOS ${version^}"
info "$msg..." && html "$msg..."
info "$msg recovery image..." && html "$msg..."

rm -rf "$TMP"
mkdir -p "$TMP"

/run/progress.sh "$path" "" "$msg ([P])..." &

if ! /run/fetch-macOS-v2.py --action download -b "$board" -n "$file" -o "$TMP"; then
error "Failed to fetch macOS \"${version^}\" with board id \"$board\"!"
if ! /run/macrecovery.py -b "$board" -n "$file" -o "$TMP" download; then
error "Failed to fetch macOS \"${version^}\" recovery image with board id \"$board\"!"
fKill "progress.sh"
return 1
fi
Expand All @@ -52,11 +53,10 @@ downloadImage() {
return 1
fi

echo "$version" > "$STORAGE/$PROCESS.version"

mv "$path" "$BASE_IMG"
mv -f "$path" "$BASE_IMG"
rm -rf "$TMP"

echo "$version" > "$BASE_VERSION"
return 0
}

Expand All @@ -67,10 +67,13 @@ if [ ! -f "$BASE_IMG" ] || [ ! -s "$BASE_IMG" ]; then
fi
fi

STORED_VERSION=$(cat "$STORAGE/$PROCESS.version")
STORED_VERSION=""
if [ -f "$BASE_VERSION" ]; then
STORED_VERSION=$(<"$BASE_VERSION")
fi

if [ "$VERSION" != "$STORED_VERSION" ]; then
info "Different version detected, switching base image from $STORED_VERSION to $VERSION"
info "Different version detected, switching base image from \"$STORED_VERSION\" to \"$VERSION\""
if ! downloadImage "$VERSION"; then
rm -rf "$TMP"
exit 34
Expand Down

0 comments on commit ba8dd28

Please sign in to comment.