Skip to content

Commit

Permalink
feat: Generate Apple MAC address (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Nov 14, 2024
1 parent f6831a5 commit fba0a66
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
45 changes: 44 additions & 1 deletion src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"

Expand Down

0 comments on commit fba0a66

Please sign in to comment.