Unverified Commit fba0a666 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Generate Apple MAC address (#124)

parent f6831a5b
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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:
+44 −1
Original line number Diff line number Diff line
@@ -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"