From fba0a666580518e6b46b7fe13b786368818e74fe Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 14 Nov 2024 02:27:42 +0100 Subject: [PATCH] feat: Generate Apple MAC address (#124) --- readme.md | 4 +++- src/install.sh | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index ac1744f..7ee1874 100644 --- a/readme.md +++ b/readme.md @@ -86,7 +86,9 @@ kubectl apply -f https://raw.githubusercontent.com/dockur/macos/refs/heads/maste ### 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 13 (Ventura) will be installed, as it offers the best performance. + + 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: diff --git a/src/install.sh b/src/install.sh index fd5d9ae..7d36719 100644 --- a/src/install.sh +++ b/src/install.sh @@ -2,7 +2,13 @@ set -Eeuo pipefail # Docker environment variables -: "${VERSION:="ventura"}" # OSX Version + +: "${SN:=""}" +: "${MLB:=""}" +: "${MAC:=""}" +: "${UUID:=""}" +: "${MODEL:="iMacPro1,1"}" +: "${VERSION:="13"}" # OSX Version TMP="$STORAGE/tmp" BASE_IMG_ID="InstallMedia" @@ -62,6 +68,35 @@ downloadImage() { return 0 } +generateID() { + + local file="$STORAGE/$PROCESS.id" + + [ -n "$UUID" ] && return 0 + [ -s "$file" ] && UUID=$(<"$file") + [ -n "$UUID" ] && return 0 + + UUID=$(cat /proc/sys/kernel/random/uuid) + echo "${UUID^^}" > "$file" + + return 0 +} + +generateAddress() { + + local file="$STORAGE/$PROCESS.mac" + + [ -n "$MAC" ] && return 0 + [ -s "$file" ] && MAC=$(<"$file") + [ -n "$MAC" ] && return 0 + + # Generate Apple MAC address based on Docker container ID in hostname + MAC=$(echo "$HOST" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/00:16:cb:\3:\4:\5/') + echo "${MAC^^}" > "$file" + + return 0 +} + if [ ! -f "$BASE_IMG" ] || [ ! -s "$BASE_IMG" ]; then if ! downloadImage "$VERSION"; then rm -rf "$TMP" @@ -82,6 +117,14 @@ if [ "$VERSION" != "$STORED_VERSION" ]; then fi fi +if !generateID; then + error "Failed to generate UUID!" && exit 35 +fi + +if !generateAddress; then + error "Failed to generate MAC address!" && exit 36 +fi + DISK_OPTS="-device virtio-blk-pci,drive=${BASE_IMG_ID},bus=pcie.0,addr=0x6" DISK_OPTS+=" -drive file=$BASE_IMG,id=$BASE_IMG_ID,format=dmg,cache=unsafe,readonly=on,if=none"