diff --git a/Dockerfile b/Dockerfile index 20ecc07..6e64c5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,8 +20,9 @@ COPY --chmod=644 ./config.plist /run ADD $REPO_OPENCORE/releases/download/$VERSION_OPENCORE/OpenCore-$VERSION_OPENCORE.iso.gz /tmp/opencore.iso.gz -RUN gzip -d /tmp/opencore.iso.gz -RUN run/build.sh /tmp/opencore.iso /run/config.plist +RUN gzip -d /tmp/opencore.iso.gz && \ + run/build.sh /tmp/opencore.iso /run/config.plist && \ + rm -rf /tmp/* FROM scratch AS runner COPY --from=qemux/qemu-docker:5.11 / / diff --git a/config.plist b/config.plist index 526ce17..f6e7fa7 100644 --- a/config.plist +++ b/config.plist @@ -1033,7 +1033,7 @@ PollAppleHotKeys ShowPicker - + TakeoffDelay 0 Timeout @@ -1871,7 +1871,7 @@ ReloadOptionRoms RequestBootVarRouting - + ResizeGpuBars -1 ResizeUsePciRbIo diff --git a/readme.md b/readme.md index 66a6e05..3eda73e 100644 --- a/readme.md +++ b/readme.md @@ -16,8 +16,8 @@ OSX (macOS) inside a Docker container. ## Features - KVM acceleration - - Image downloader - Web-based viewer + - Automatic download ## Usage @@ -61,8 +61,6 @@ 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. - - Choose `Disk Utility` and then select the largest `Apple Inc. VirtIO Block Media` disk. - Click the `Erase` button to format the disk, and give it any recognizable name you like. @@ -71,11 +69,7 @@ kubectl apply -f kubernetes.yml - 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. - - After all files are copied, select your region, language, and account settings. - - - Once you see the desktop, your macOS installation is ready for use. Enjoy your brand new machine, and don't forget to star this repo! @@ -144,13 +138,17 @@ kubectl apply -f kubernetes.yml If you receive an error from `kvm-ok` indicating that KVM acceleration can't be used, check the virtualization settings in the BIOS. +* ### How do I run Windows in a container? + + You can use [dockur/windows](https://github.com/dockur/windows) for that. It shares many of the same features, and even has completely automatic installation. + * ### Is this project legal? Yes, this project contains only open-source code and does not distribute any copyrighted material. So under all applicable laws, this project will be considered legal. ## Acknowledgements -Special thanks to [OSX-KVM](https://github.com/kholia/OSX-KVM), [KVM-Opencore](https://github.com/thenickdude/KVM-Opencore) and [seitenca](https://github.com/seitenca), this project would not exist without their invaluable work. +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. ## Stars [![Stars](https://starchart.cc/dockur/macos.svg?variant=adaptive)](https://starchart.cc/dockur/macos) diff --git a/src/boot.sh b/src/boot.sh index 5878763..9e2cb09 100644 --- a/src/boot.sh +++ b/src/boot.sh @@ -6,9 +6,6 @@ set -Eeuo pipefail BOOT_DESC="" BOOT_OPTS="" -BOOT_DRIVE_ID="OpenCoreBoot" -BOOT_DRIVE="/images/OpenCore.img" - SECURE="off" OVMF="/usr/share/OVMF" @@ -62,6 +59,15 @@ BOOT_OPTS+=" -drive if=pflash,format=raw,readonly=on,file=$DEST.rom" BOOT_OPTS+=" -drive if=pflash,format=raw,file=$DEST.vars" # OpenCoreBoot +BOOT_DRIVE_ID="OpenCore" +BOOT_DRIVE="$STORAGE/boot.img" + +if [ ! -f "$BOOT_DRIVE" ] || [ ! -s "$BOOT_DRIVE" ]; then + msg="Extracting boot image" + info "$msg..." && html "$msg..." + gzip -dkc /images/OpenCore.img.gz > "$BOOT_DRIVE" +fi + DISK_OPTS+=" -device virtio-blk-pci,drive=${BOOT_DRIVE_ID},scsi=off,bus=pcie.0,addr=0x5,iothread=io2,bootindex=$BOOT_INDEX" DISK_OPTS+=" -drive file=$BOOT_DRIVE,id=$BOOT_DRIVE_ID,format=raw,cache=$DISK_CACHE,aio=$DISK_IO,readonly=on,if=none" diff --git a/src/build.sh b/src/build.sh index 64df478..e68f1a7 100644 --- a/src/build.sh +++ b/src/build.sh @@ -1,8 +1,6 @@ #!/usr/bin/env bash set -Eeuo pipefail -echo "Extracting template image..." - DST="/images" OUT="/tmp/extract" @@ -12,56 +10,68 @@ rm -rf "$DST" mkdir -p "$OUT" mkdir -p "$DST" +echo "Extracting template image..." + if [ ! -f "$1" ] || [ ! -s "$1" ]; then - error "Could not find image file \"$1\"." && exit 10 + echo "Could not find image file \"$1\"." && exit 10 fi START=$(sfdisk -l "$1" | grep -i -m 1 "EFI System" | awk '{print $2}') mcopy -bspmQ -i "$1@@${START}S" ::EFI "$OUT" +echo "Building OpenCore image..." + cp "$2" "$OUT/EFI/OC/" -echo "Creating OpenCore image..." - +MB=256 +CLUSTER=4 START=2048 -COUNT=522207 -SIZE=268435456 +SECTOR=512 +FIRST_LBA=34 + +SIZE=$(( MB*1024*1024 )) +OFFSET=$(( START*SECTOR )) +TOTAL=$(( SIZE-(FIRST_LBA*SECTOR) )) +LAST_LBA=$(( TOTAL/SECTOR )) +COUNT=$(( LAST_LBA-(START-1) )) FILE="OpenCore.img" -IMG="/tmp/$SIZE.img" -NAME=$(basename "$IMG") - +IMG="/tmp/$FILE" rm -f "$IMG" if ! truncate -s "$SIZE" "$IMG"; then rm -f "$IMG" - error "Could not allocate file $IMG for the OpenCore image." && exit 11 + echo "Could not allocate file $IMG for the OpenCore image." && exit 11 fi PART="/tmp/partition.fdisk" { echo "label: gpt" echo "label-id: 1ACB1E00-3B8F-4B2A-86A4-D99ED21DCAEB" - echo "device: $NAME" + echo "device: $FILE" echo "unit: sectors" - echo "first-lba: 34" - echo "last-lba: 524254" - echo "sector-size: 512" + echo "first-lba: $FIRST_LBA" + echo "last-lba: $LAST_LBA" + echo "sector-size: $SECTOR" echo "" - echo "${NAME}1 : start=$START, size=$COUNT, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=05157F6E-0AE8-4D1A-BEA5-AC172453D02C, name=\"primary\"" + echo "${FILE}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 +echo "drive c: file=\"$IMG\" partition=0 offset=$OFFSET" > /etc/mtools.conf -mformat -F -M 512 -c 4 -T "$COUNT" -v "EFI" "C:" +mformat -F -M "$SECTOR" -c "$CLUSTER" -T "$COUNT" -v "EFI" "C:" echo "Copying files to image..." mcopy -bspmQ "$OUT/EFI" "C:" +rm -rf "$OUT" -mv -f "$IMG" "$DST/$FILE" +echo "Compressing image..." + +gzip -c "$IMG" > "$DST/$FILE.gz" +rm -f "$IMG" echo "Finished succesfully!" diff --git a/src/install.sh b/src/install.sh index 6922073..0605dfe 100644 --- a/src/install.sh +++ b/src/install.sh @@ -29,9 +29,9 @@ downloadImage() { *) error "Unknown VERSION specified, value \"${version}\" is not recognized!" return 1 ;; - esac + esac - local msg="Downloading macOS ($version) image" + local msg="Downloading macOS ${version^}" info "$msg..." && html "$msg..." rm -rf "$TMP" @@ -40,7 +40,7 @@ downloadImage() { /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\"!" + error "Failed to fetch macOS \"${version^}\" with board id \"$board\"!" fKill "progress.sh" return 1 fi