From 8bf8242a7ab4c9b5a57eef24176fe083ee408e51 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 5 Jun 2024 14:16:56 +0200 Subject: [PATCH] feat: Add support for AMD CPU's (#21) --- Dockerfile | 13 +++---------- compose.yml | 2 +- readme.md | 16 ++++++++-------- src/boot.sh | 14 +++++++++++++- src/entry.sh | 5 ++--- src/install.sh | 50 +++++++++++++++++++++++++++++++++----------------- 6 files changed, 60 insertions(+), 40 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3de1665..1ebdde7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM scratch -COPY --from=qemux/qemu-docker:5.10 / / +COPY --from=qemux/qemu-docker:5.11 / / ARG VERSION_ARG="0.0" ARG VERSION_OSX_KVM="326053dd61f49375d5dfb28ee715d38b04b5cd8e" @@ -12,14 +12,7 @@ ARG DEBCONF_NONINTERACTIVE_SEEN="true" RUN set -eu && \ apt-get update && \ apt-get --no-install-recommends -y install \ - uml-utilities \ - libguestfs-tools \ - p7zip-full \ - make \ - dmg2img \ - python3 \ - tesseract-ocr \ - tesseract-ocr-eng && \ + python3 && \ apt-get clean && \ echo "$VERSION_ARG" > /run/version && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* @@ -40,6 +33,6 @@ VOLUME /storage ENV RAM_SIZE "3G" ENV CPU_CORES "2" ENV DISK_SIZE "32G" -ENV VERSION "ventura" +ENV VERSION "sonoma" ENTRYPOINT ["/usr/bin/tini", "-s", "/run/entry.sh"] diff --git a/compose.yml b/compose.yml index dcac88c..7eb83e7 100644 --- a/compose.yml +++ b/compose.yml @@ -3,7 +3,7 @@ services: image: dockurr/macos container_name: macos environment: - VERSION: "ventura" + VERSION: "sonoma" devices: - /dev/kvm cap_add: diff --git a/readme.md b/readme.md index 70c17b5..56d15bc 100644 --- a/readme.md +++ b/readme.md @@ -29,7 +29,7 @@ services: image: dockurr/macos container_name: macos environment: - VERSION: "ventura" + VERSION: "sonoma" devices: - /dev/kvm cap_add: @@ -83,21 +83,21 @@ kubectl apply -f kubernetes.yml * ### How do I select the macOS version? - By default, macOS 13 (Ventura) will be installed. But you can add the `VERSION` environment variable to your compose file, in order to specify an alternative macOS version to be downloaded: + By default, macOS Sonoma will be installed. But you can add the `VERSION` environment variable to your compose file, in order to specify an alternative macOS version to be downloaded: ```yaml environment: - VERSION: "ventura" + VERSION: "sonoma" ``` Select from the values below: - | **Value** | **Version** | + | **Value** | **Version** | |----|-----| - | `sonoma` | macOS 14 (Sonoma) | - | `ventura` | macOS 13 (Ventura) | - | `monterey` | macOS 12 (Monterey) | - | `big-sur` | macOS 11 (Big Sur) | + | `sonoma` | macOS Sonoma | + | `ventura` | macOS Ventura | + | `monterey` | macOS Monterey | + | `big-sur` | macOS Big Sur | * ### How do I change the storage location? diff --git a/src/boot.sh b/src/boot.sh index 915cae7..e3bcafb 100644 --- a/src/boot.sh +++ b/src/boot.sh @@ -8,6 +8,7 @@ BOOT_DESC="" BOOT_OPTS="" BOOT_DRIVE_ID="OpenCoreBoot" BOOT_DRIVE="/images/OpenCore.qcow2" + SECURE="off" OVMF="/usr/share/OVMF" @@ -48,6 +49,17 @@ BOOT_OPTS="$BOOT_OPTS -drive if=pflash,format=raw,file=$OVMF/$VARS" # OpenCoreBoot DISK_OPTS="$DISK_OPTS -device virtio-blk-pci,drive=${BOOT_DRIVE_ID},scsi=off,bus=pcie.0,addr=0x5,iothread=io2,bootindex=1" -DISK_OPTS="$DISK_OPTS -drive file=$BOOT_DRIVE,id=$BOOT_DRIVE_ID,format=qcow2,cache=$DISK_CACHE,aio=$DISK_IO,discard=$DISK_DISCARD,detect-zeroes=on,if=none" +DISK_OPTS="$DISK_OPTS -drive file=$BOOT_DRIVE,id=$BOOT_DRIVE_ID,format=qcow2,cache=$DISK_CACHE,aio=$DISK_IO,readonly=on,if=none" + +CPU_VENDOR=$(lscpu | awk '/Vendor ID/{print $3}') +CPU_FLAGS="vendor=GenuineIntel,vmware-cpuid-freq=on,-pdpe1gb" + +if [[ "$CPU_VENDOR" != "GenuineIntel" ]]; then + CPU_MODEL="Haswell-noTSX" +fi + +USB="nec-usb-xhci,id=xhci" +USB="$USB -device usb-kbd,bus=xhci.0" +USB="$USB -global nec-usb-xhci.msi=off" return 0 diff --git a/src/entry.sh b/src/entry.sh index bd36ca6..11d4373 100644 --- a/src/entry.sh +++ b/src/entry.sh @@ -1,12 +1,11 @@ #!/usr/bin/env bash set -Eeuo pipefail +: "${VGA:="vmware"}" : "${DISK_TYPE:="blk"}" -: "${USB:="qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0"}" APP="macOS" -VGA="vmware" -SUPPORT="https://github.com/dockur/osx/" +SUPPORT="https://github.com/dockur/macos" cd /run diff --git a/src/install.sh b/src/install.sh index 63b8a1d..0b9acdd 100644 --- a/src/install.sh +++ b/src/install.sh @@ -2,47 +2,63 @@ set -Eeuo pipefail # Docker environment variables -: "${VERSION:="ventura"}" # OSX Version +: "${VERSION:="sonoma"}" # OSX Version +TMP="$STORAGE/tmp" +BASE_FILE="BaseSystem" BASE_IMG_ID="InstallMedia" -BASE_IMG="$STORAGE/BaseSystem.img" +BASE_IMG="$STORAGE/base.dmg" +BASE_TMP="$TMP/$BASE_FILE.dmg" downloadImage() { - local msg="Downloading $APP $VERSION image..." - info "$msg" && html "$msg" + rm -rf "$TMP" + mkdir -p "$TMP" - if ! /run/fetch-macOS-v2.py -s "$VERSION"; then - error "Failed to fetch MacOS $VERSION!" + local msg="Downloading macOS ($VERSION) image" + info "$msg..." && html "$msg..." + + /run/progress.sh "$BASE_TMP" "" "$msg ([P])..." & + + if ! /run/fetch-macOS-v2.py --action download -s "$VERSION" -n "$BASE_FILE" -o "$TMP"; then + error "Failed to fetch macOS ($VERSION)!" + fKill "progress.sh" return 1 fi - msg="Converting base image format..." - info "$msg" && html "$msg" + fKill "progress.sh" - if ! dmg2img -i BaseSystem.dmg "$BASE_IMG"; then - error "Failed to convert base image format!" + if [ ! -f "$BASE_TMP" ] || [ ! -s "$BASE_TMP" ]; then + error "Failed to find file $BASE_TMP !" return 1 fi - rm -f BaseSystem.dmg - echo "$VERSION" > "$STORAGE/$PROCESS.version" + + mv "$BASE_TMP" "$BASE_IMG" + rm -rf "$TMP" + + return 0 } -if [ ! -f "$BASE_IMG" ]; then - ! downloadImage && exit 34 +if [ ! -f "$BASE_IMG" ] || [ ! -s "$BASE_IMG" ]; then + if ! downloadImage; then + rm -rf "$TMP" + exit 34 + fi fi STORED_VERSION=$(cat "$STORAGE/$PROCESS.version") if [ "$VERSION" != "$STORED_VERSION" ]; then info "Different version detected, switching base image from $STORED_VERSION to $VERSION" - rm -f "$BASE_IMG" - ! downloadImage && exit 34 + if ! downloadImage; then + rm -rf "$TMP" + exit 34 + fi fi DISK_OPTS="$DISK_OPTS -device virtio-blk-pci,drive=${BASE_IMG_ID},scsi=off,bus=pcie.0,addr=0x6,iothread=io2" -DISK_OPTS="$DISK_OPTS -drive file=$BASE_IMG,id=$BASE_IMG_ID,format=raw,cache=$DISK_CACHE,aio=$DISK_IO,discard=$DISK_DISCARD,detect-zeroes=on,if=none" +DISK_OPTS="$DISK_OPTS -drive file=$BASE_IMG,id=$BASE_IMG_ID,format=dmg,cache=$DISK_CACHE,aio=$DISK_IO,readonly=on,if=none" return 0