2021-02-23 23:12:38 -06:00
|
|
|
#!/bin/bash
|
|
|
|
# ____ __ ____ ______ __
|
|
|
|
# / __ \____ _____/ /_____ _____/ __ \/ ___/ |/ /
|
|
|
|
# / / / / __ \/ ___/ //_/ _ \/ ___/ / / /\__ \| /
|
|
|
|
# / /_/ / /_/ / /__/ ,< / __/ / / /_/ /___/ / |
|
|
|
|
# /_____/\____/\___/_/|_|\___/_/ \____//____/_/|_| SERIALIZER
|
|
|
|
#
|
|
|
|
# Repo: https://github.com/sickcodes/Docker-OSX/
|
|
|
|
# Title: Mac on Docker (Docker-OSX)
|
|
|
|
# Author: Sick.Codes https://sick.codes/
|
|
|
|
# Version: 3.1
|
|
|
|
# License: GPLv3+
|
|
|
|
|
|
|
|
help_text="Usage: generate-unique-machine-values.sh
|
|
|
|
|
|
|
|
General options:
|
|
|
|
--count, -n, -c <count> Number of serials to generate
|
2021-02-24 03:46:18 -06:00
|
|
|
--model, -m <model> Device model, e.g. 'iMacPro1,1'
|
2021-02-23 23:12:38 -06:00
|
|
|
--csv <filename> Optionally change the CSV output filename.
|
2021-02-24 03:46:18 -06:00
|
|
|
--tsv <filename> Optionally change the TSV output filename.
|
2021-02-23 23:12:38 -06:00
|
|
|
--output-dir <directory> Optionally change the script output location.
|
2021-02-23 23:52:17 -06:00
|
|
|
|
2021-02-23 23:12:38 -06:00
|
|
|
--help, -h, help Display this help and exit
|
2021-02-23 23:52:17 -06:00
|
|
|
--plists Create corresponding config.plists for each serial set.
|
|
|
|
--qcows [SLOW] Create corresponding boot disk images for each serial set.
|
2021-02-23 23:12:38 -06:00
|
|
|
|
2021-02-24 03:46:18 -06:00
|
|
|
Example:
|
|
|
|
./generate-unique-machine-values.sh --count 1 --model='iMacPro1,1' --plists --qcows
|
|
|
|
|
|
|
|
The above example will generate a
|
|
|
|
- serial
|
|
|
|
- board serial
|
|
|
|
- uuid
|
|
|
|
- MAC address
|
|
|
|
- ROM value based on lowercase MAC address
|
|
|
|
- Boot disk qcow image.
|
|
|
|
- config.plist
|
|
|
|
|
2021-02-23 23:12:38 -06:00
|
|
|
Notes:
|
2021-02-24 03:46:18 -06:00
|
|
|
- Default is 1 serial for 'iMacPro1,1' in the current working directory.
|
|
|
|
- Default output is CSV, whereas setting the TSV option will output as tab-separated.
|
2021-02-23 23:12:38 -06:00
|
|
|
- CSV is double quoted.
|
|
|
|
- If you do not set a CSV filename, the output will be sent to the output-dir.
|
|
|
|
- If you do not set an output-dir, the current directory will be the output directory.
|
2021-02-24 03:46:18 -06:00
|
|
|
- Sourcable environment variable shell files will be written to a folder, 'envs'.
|
|
|
|
- config.plist files will be written to a folder, 'plists'.
|
2021-02-23 23:12:38 -06:00
|
|
|
|
|
|
|
Author: Sick.Codes https://sick.codes/
|
|
|
|
Project: https://github.com/sickcodes/Docker-OSX/
|
|
|
|
"
|
|
|
|
|
|
|
|
MACINFOPKG_VERSION=2.1.2
|
2021-02-23 23:52:17 -06:00
|
|
|
PLIST_MASTER=config-nopicker-custom.plist
|
2021-02-23 23:12:38 -06:00
|
|
|
|
|
|
|
# gather arguments
|
|
|
|
while (( "$#" )); do
|
|
|
|
case "${1}" in
|
|
|
|
|
|
|
|
--help | -h | h | help )
|
|
|
|
echo "${help_text}" && exit 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
--count=* | -c=* | -n=* )
|
|
|
|
export SERIAL_SET_COUNT="${1#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--count* | -c* | -n* )
|
|
|
|
export SERIAL_SET_COUNT="${2}"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
|
|
|
|
--csv=* )
|
|
|
|
export CSV_OUTPUT_FILENAME="${1#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--csv* )
|
|
|
|
export CSV_OUTPUT_FILENAME="${2}"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
|
2021-02-24 03:46:18 -06:00
|
|
|
--tsv=* )
|
|
|
|
export TSV_OUTPUT_FILENAME="${1#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--tsv* )
|
|
|
|
export TSV_OUTPUT_FILENAME="${2}"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
|
2021-02-23 23:12:38 -06:00
|
|
|
--output-dir=* )
|
|
|
|
export OUTPUT_DIRECTORY="${1#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--output-dir* )
|
|
|
|
export OUTPUT_DIRECTORY="${2}"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
|
|
|
|
--model=* | -m=* )
|
|
|
|
export DEVICE_MODEL="${1#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--model* | -m* )
|
|
|
|
export DEVICE_MODEL="${2}"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
|
2021-02-23 23:52:17 -06:00
|
|
|
--plists )
|
|
|
|
export CREATE_PLISTS=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--qcows )
|
|
|
|
export CREATE_QCOWS=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
|
2021-02-23 23:12:38 -06:00
|
|
|
*)
|
|
|
|
echo "Invalid option. Running with default values..."
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
build_mac_serial () {
|
2021-02-23 23:29:17 -06:00
|
|
|
export MACINFOPKG_VERSION="${MACINFOPKG_VERSION:=2.1.2}"
|
2021-02-23 23:12:38 -06:00
|
|
|
wget -O "${TARBALL:=./MacInfoPkg.tar.gz}" \
|
2021-02-23 23:29:17 -06:00
|
|
|
"https://github.com/acidanthera/MacInfoPkg/archive/${MACINFOPKG_VERSION}.tar.gz"
|
2021-02-23 23:12:38 -06:00
|
|
|
tar -xzvf "${TARBALL}"
|
|
|
|
cd "./MacInfoPkg-${MACINFOPKG_VERSION}/macserial" \
|
2021-02-23 23:29:17 -06:00
|
|
|
&& ./build.tool \
|
2021-02-23 23:12:38 -06:00
|
|
|
&& cd -
|
|
|
|
mv "./MacInfoPkg-${MACINFOPKG_VERSION}/macserial/bin/macserial" .
|
|
|
|
rm -f "${TARBALL}"
|
|
|
|
rm -rf "./MacInfoPkg-${MACINFOPKG_VERSION}/"
|
2021-02-23 23:29:17 -06:00
|
|
|
chmod +x ./macserial
|
2021-02-23 23:12:38 -06:00
|
|
|
stat ./macserial
|
|
|
|
}
|
|
|
|
|
|
|
|
download_vendor_mac_addresses () {
|
|
|
|
# download the MAC Address vendor list
|
|
|
|
[[ -e "${MAC_ADDRESSES_FILE:=vendor_macs.tsv}" ]] || wget -O "${MAC_ADDRESSES_FILE}" https://gitlab.com/wireshark/wireshark/-/raw/master/manuf
|
|
|
|
}
|
|
|
|
|
2021-02-23 23:52:17 -06:00
|
|
|
download_qcow_efi_folder () {
|
2021-02-24 03:46:18 -06:00
|
|
|
git clone --depth 1 https://github.com/kholia/OSX-KVM.git
|
2021-02-23 23:52:17 -06:00
|
|
|
cp -ra ./OSX-KVM/OpenCore-Catalina/EFI .
|
|
|
|
mkdir -p ./EFI/OC/Resources
|
|
|
|
# clone some Apple drivers
|
2021-02-24 03:46:18 -06:00
|
|
|
git clone --depth 1 https://github.com/acidanthera/OcBinaryData.git
|
2021-02-23 23:52:17 -06:00
|
|
|
# copy said drivers into EFI/OC/Resources
|
|
|
|
cp -a ./OcBinaryData/Resources/* ./EFI/OC/Resources
|
|
|
|
# EFI Shell commands
|
|
|
|
touch startup.nsh && echo 'fs0:\EFI\BOOT\BOOTx64.efi' > startup.nsh
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-23 23:12:38 -06:00
|
|
|
generate_serial_sets () {
|
|
|
|
mkdir -p "${OUTPUT_DIRECTORY}/envs"
|
|
|
|
export DATE_NOW="$(date +%F-%T)"
|
|
|
|
export DEVICE_MODEL="${DEVICE_MODEL:=iMacPro1,1}"
|
|
|
|
export VENDOR_REGEX="${VENDOR_REGEX:=Apple, Inc.}"
|
|
|
|
|
2021-02-24 03:46:18 -06:00
|
|
|
if [[ "${CSV_OUTPUT_FILENAME}" ]] || [[ "${TSV_OUTPUT_FILENAME}" ]]; then
|
|
|
|
[[ ${CSV_OUTPUT_FILENAME} ]] && export CSV_SERIAL_SETS_FILE="${CSV_OUTPUT_FILENAME}"
|
|
|
|
[[ ${TSV_OUTPUT_FILENAME} ]] && export TSV_SERIAL_SETS_FILE="${TSV_OUTPUT_FILENAME}"
|
2021-02-23 23:12:38 -06:00
|
|
|
else
|
|
|
|
export SERIAL_SETS_FILE="${OUTPUT_DIRECTORY}/serial_sets-${DATE_NOW}.csv"
|
|
|
|
fi
|
|
|
|
|
|
|
|
touch "${SERIAL_SETS_FILE}"
|
|
|
|
echo "Writing serial sets to ${SERIAL_SETS_FILE}"
|
|
|
|
|
|
|
|
./macserial \
|
|
|
|
--num "${SERIAL_SET_COUNT:=1}" \
|
|
|
|
--model "${DEVICE_MODEL}" \
|
|
|
|
| while IFS='\ \|\ ' read -r Serial BoardSerial; do
|
|
|
|
# make a uuid...
|
|
|
|
SmUUID="$(uuidgen)"
|
|
|
|
SmUUID="${SmUUID^^}"
|
|
|
|
|
|
|
|
# get a random vendor specific MAC address.
|
|
|
|
RANDOM_MAC_PREFIX="$(grep -e "${VENDOR_REGEX}" < "${MAC_ADDRESSES_FILE:=vendor_macs.tsv}" | sort --random-sort | head -n1)"
|
|
|
|
RANDOM_MAC_PREFIX="$(cut -d$'\t' -f1 <<< "${RANDOM_MAC_PREFIX}")"
|
|
|
|
MacAddress="$(printf "${RANDOM_MAC_PREFIX}:%02X:%02X:%02X" $[RANDOM%256] $[RANDOM%256] $[RANDOM%256])"
|
|
|
|
|
2021-02-24 03:46:18 -06:00
|
|
|
# append to csv file
|
|
|
|
if [[ "${CSV_SERIAL_SETS_FILE}" ]]; then
|
|
|
|
echo "\"${DEVICE_MODEL}\",\"${Serial}\",\"${BoardSerial}\",\"${SmUUID}\",\"${MacAddress}\"" >> "${CSV_SERIAL_SETS_FILE}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# append to tsv file
|
|
|
|
if [[ "${TSV_SERIAL_SETS_FILE}" ]]; then
|
|
|
|
printf "${DEVICE_MODEL}\t${Serial}\t${BoardSerial}\t${SmUUID}\t${MacAddress}\n" >> "${TSV_SERIAL_SETS_FILE}"
|
|
|
|
fi
|
|
|
|
|
2021-02-23 23:12:38 -06:00
|
|
|
touch "${OUTPUT_DIRECTORY}/envs/${Serial}.env.sh"
|
|
|
|
cat <<EOF > "${OUTPUT_DIRECTORY}/envs/${Serial}.env.sh"
|
|
|
|
export Type=${DEVICE_MODEL}
|
|
|
|
export Serial=${Serial}
|
|
|
|
export BoardSerial=${BoardSerial}
|
|
|
|
export SmUUID=${SmUUID}
|
|
|
|
export MacAddress=${MacAddress}
|
|
|
|
EOF
|
2021-02-23 23:52:17 -06:00
|
|
|
|
2021-02-24 03:46:18 -06:00
|
|
|
# plist required for qcows, so create anyway.
|
2021-02-23 23:52:17 -06:00
|
|
|
if [[ "${CREATE_PLISTS}" ]] || [[ "${CREATE_QCOWS}" ]]; then
|
|
|
|
mkdir -p "${OUTPUT_DIRECTORY}/plists"
|
2021-02-24 03:46:18 -06:00
|
|
|
source "${OUTPUT_DIRECTORY}/envs/${Serial}.env.sh"
|
|
|
|
ROM_VALUE="${MacAddress//\:/}"
|
|
|
|
ROM_VALUE="${ROM_VALUE,,}"
|
2021-02-23 23:52:17 -06:00
|
|
|
sed -e s/{{DEVICE_MODEL}}/"${Type}"/g \
|
|
|
|
-e s/{{SERIAL_OLD}}/"${Serial}"/g \
|
|
|
|
-e s/{{BOARD_SERIAL_OLD}}/"${BoardSerial}"/g \
|
|
|
|
-e s/{{SYSTEM_UUID_OLD}}/"${SmUUID}"/g \
|
|
|
|
-e s/{{ROM_OLD}}/"${ROM_VALUE}"/g \
|
|
|
|
"${PLIST_MASTER}" > "${OUTPUT_DIRECTORY}/plists/${Serial}.config.plist" || exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${CREATE_QCOWS}" ]]; then
|
|
|
|
mkdir -p "${OUTPUT_DIRECTORY}/qcows"
|
|
|
|
./opencore-image-ng.sh \
|
|
|
|
--cfg "${OUTPUT_DIRECTORY}/plists/${Serial}.config.plist" \
|
|
|
|
--img "${OUTPUT_DIRECTORY}/qcows/${Serial}.OpenCore-nopicker.qcow2" || exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
2021-02-23 23:12:38 -06:00
|
|
|
|
2021-02-24 03:46:18 -06:00
|
|
|
[[ -e "${CSV_SERIAL_SETS_FILE}" ]] && \
|
|
|
|
cat <(echo "Type,Serial,BoardSerial,SmUUID,MacAddress") "${CSV_SERIAL_SETS_FILE}"
|
|
|
|
|
|
|
|
|
|
|
|
[[ -e "${TSV_SERIAL_SETS_FILE}" ]] && \
|
|
|
|
cat <(printf "Type\tSerial\tBoardSerial\tSmUUID\tMacAddress\n") "${TSV_SERIAL_SETS_FILE}"
|
|
|
|
|
2021-02-23 23:12:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
main () {
|
|
|
|
# setting default variables if there are no options
|
2021-02-23 23:29:17 -06:00
|
|
|
export DEVICE_MODEL="${DEVICE_MODEL:=iMacPro1,1}"
|
|
|
|
export SERIAL_SET_COUNT="${SERIAL_SET_COUNT:=1}"
|
|
|
|
export OUTPUT_DIRECTORY="${OUTPUT_DIRECTORY:=.}"
|
2021-02-23 23:12:38 -06:00
|
|
|
cat <<EOF
|
2021-02-23 23:29:17 -06:00
|
|
|
DEVICE_MODEL: ${DEVICE_MODEL}
|
|
|
|
SERIAL_SET_COUNT: ${SERIAL_SET_COUNT}
|
|
|
|
OUTPUT_DIRECTORY: ${OUTPUT_DIRECTORY}
|
2021-02-23 23:12:38 -06:00
|
|
|
EOF
|
|
|
|
[[ -d "${OUTPUT_DIRECTORY}" ]] || mkdir -p "${OUTPUT_DIRECTORY}"
|
|
|
|
[[ -e ./macserial ]] || build_mac_serial
|
|
|
|
download_vendor_mac_addresses
|
2021-02-23 23:52:17 -06:00
|
|
|
download_qcow_efi_folder
|
2021-02-23 23:12:38 -06:00
|
|
|
generate_serial_sets
|
|
|
|
echo "${SERIAL_SETS_FILE}"
|
|
|
|
}
|
|
|
|
|
|
|
|
main
|
|
|
|
|