Add config.plist and OpenCore boot disk generator to the script.

This commit is contained in:
sickcodes 2021-02-24 05:52:17 +00:00
parent 372905218f
commit d3e86e1c53
2 changed files with 212 additions and 1 deletions

View File

@ -21,7 +21,10 @@ General options:
--model, -m <model> Device model, e.g. "iMacPro1,1" --model, -m <model> Device model, e.g. "iMacPro1,1"
--csv <filename> Optionally change the CSV output filename. --csv <filename> Optionally change the CSV output filename.
--output-dir <directory> Optionally change the script output location. --output-dir <directory> Optionally change the script output location.
--help, -h, help Display this help and exit --help, -h, help Display this help and exit
--plists Create corresponding config.plists for each serial set.
--qcows [SLOW] Create corresponding boot disk images for each serial set.
Notes: Notes:
- Default is 1 serial for "iMacPro1,1" in the current working directory. - Default is 1 serial for "iMacPro1,1" in the current working directory.
@ -29,12 +32,14 @@ Notes:
- If you do not set a CSV filename, the output will be sent to the output-dir. - 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. - If you do not set an output-dir, the current directory will be the output directory.
- Sourcable environment variable shell files will be written to a folder, "envs". - Sourcable environment variable shell files will be written to a folder, "envs".
- config.plist files will be written to a folder, "plists".
Author: Sick.Codes https://sick.codes/ Author: Sick.Codes https://sick.codes/
Project: https://github.com/sickcodes/Docker-OSX/ Project: https://github.com/sickcodes/Docker-OSX/
" "
MACINFOPKG_VERSION=2.1.2 MACINFOPKG_VERSION=2.1.2
PLIST_MASTER=config-nopicker-custom.plist
# gather arguments # gather arguments
while (( "$#" )); do while (( "$#" )); do
@ -84,6 +89,15 @@ while (( "$#" )); do
shift shift
;; ;;
--plists )
export CREATE_PLISTS=1
shift
;;
--qcows )
export CREATE_QCOWS=1
shift
;;
*) *)
echo "Invalid option. Running with default values..." echo "Invalid option. Running with default values..."
shift shift
@ -112,6 +126,21 @@ download_vendor_mac_addresses () {
[[ -e "${MAC_ADDRESSES_FILE:=vendor_macs.tsv}" ]] || wget -O "${MAC_ADDRESSES_FILE}" https://gitlab.com/wireshark/wireshark/-/raw/master/manuf [[ -e "${MAC_ADDRESSES_FILE:=vendor_macs.tsv}" ]] || wget -O "${MAC_ADDRESSES_FILE}" https://gitlab.com/wireshark/wireshark/-/raw/master/manuf
} }
download_qcow_efi_folder () {
git clone https://github.com/kholia/OSX-KVM.git
cp -ra ./OSX-KVM/OpenCore-Catalina/EFI .
mkdir -p ./EFI/OC/Resources
# clone some Apple drivers
git clone https://github.com/acidanthera/OcBinaryData.git
# 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
}
generate_serial_sets () { generate_serial_sets () {
mkdir -p "${OUTPUT_DIRECTORY}/envs" mkdir -p "${OUTPUT_DIRECTORY}/envs"
export DATE_NOW="$(date +%F-%T)" export DATE_NOW="$(date +%F-%T)"
@ -149,6 +178,24 @@ export BoardSerial=${BoardSerial}
export SmUUID=${SmUUID} export SmUUID=${SmUUID}
export MacAddress=${MacAddress} export MacAddress=${MacAddress}
EOF EOF
if [[ "${CREATE_PLISTS}" ]] || [[ "${CREATE_QCOWS}" ]]; then
mkdir -p "${OUTPUT_DIRECTORY}/plists"
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 done
cat <(echo "Type,Serial,BoardSerial,SmUUID,MacAddress") "${SERIAL_SETS_FILE}" cat <(echo "Type,Serial,BoardSerial,SmUUID,MacAddress") "${SERIAL_SETS_FILE}"
@ -167,6 +214,7 @@ EOF
[[ -d "${OUTPUT_DIRECTORY}" ]] || mkdir -p "${OUTPUT_DIRECTORY}" [[ -d "${OUTPUT_DIRECTORY}" ]] || mkdir -p "${OUTPUT_DIRECTORY}"
[[ -e ./macserial ]] || build_mac_serial [[ -e ./macserial ]] || build_mac_serial
download_vendor_mac_addresses download_vendor_mac_addresses
download_qcow_efi_folder
generate_serial_sets generate_serial_sets
echo "${SERIAL_SETS_FILE}" echo "${SERIAL_SETS_FILE}"
} }

163
custom/opencore-image-ng.sh Executable file
View File

@ -0,0 +1,163 @@
#!/usr/bin/env bash
# https://github.com/kraxel/imagefish
######################################################################
# defaults
iso=""
img=""
cfg=""
######################################################################
# create work dir
function msg() {
local txt="$1"
local bold="\x1b[1m"
local normal="\x1b[0m"
echo -e "${bold}### ${txt}${normal}"
}
function do_cleanup() {
msg "cleaning up ..."
if test "$GUESTFISH_PID" != ""; then
guestfish --remote -- exit >/dev/null 2>&1 || true
fi
sudo rm -rf "$WORK"
}
WORK="${TMPDIR-/var/tmp}/${0##*/}-$$"
mkdir "$WORK" || exit 1
trap 'do_cleanup' EXIT
BASE="$(dirname $0)"
######################################################################
# parse args
function print_help() {
cat <<EOF
usage: $0 [ options ]
options:
--iso <iso-image>
--img <disk-image>
--cfg <clover-config>
EOF
}
while test "$1" != ""; do
case "$1" in
--iso)
iso="$2"
shift; shift
;;
--img)
img="$2"
shift; shift
;;
--cfg)
cfg="$2"
shift; shift
;;
esac
done
######################################################################
# guestfish script helpers
function fish() {
echo "#" "$@"
guestfish --remote -- "$@" || exit 1
}
function fish_init() {
local format
case "$img" in
*.raw) format="raw" ;;
*) format="qcow2";;
esac
msg "creating and adding disk image"
fish disk-create $img $format 384M
fish add $img
fish run
}
function fish_fini() {
fish umount-all
}
######################################################################
# sanity checks
if test ! -f "$cfg"; then
echo "ERROR: cfg not found: $cfg"
exit 1
fi
if test -f "$img"; then
if test "$allow_override" = "yes"; then
rm -f "$img"
else
echo "ERROR: image exists: $img"
exit 1
fi
fi
######################################################################
# go!
msg "copy files from local folder"
BASE="$(dirname $0)"
cp -a $BASE/EFI $WORK
find "$WORK"
#msg "[debug] list drivers in EFI/OC"
#(cd $WORK/EFI/OC; find driver* -print)
export LIBGUESTFS_BACKEND=direct
eval $(guestfish --listen)
if test "$GUESTFISH_PID" = ""; then
echo "ERROR: starting guestfish failed"
exit 1
fi
fish_init
msg "partition disk image"
fish part-init /dev/sda gpt
fish part-add /dev/sda p 2048 300000
fish part-add /dev/sda p 302048 -2048
fish part-set-gpt-type /dev/sda 1 C12A7328-F81F-11D2-BA4B-00A0C93EC93B
fish part-set-bootable /dev/sda 1 true
fish mkfs vfat /dev/sda1 label:EFI
fish mkfs vfat /dev/sda2 label:OpenCoreBoo
fish mount /dev/sda2 /
fish mkdir /ESP
fish mount /dev/sda1 /ESP
msg "copy files to disk image"
cp -v "$cfg" $WORK/config.plist
fish mkdir /ESP/EFI
fish mkdir /ESP/EFI/OC
fish mkdir /ESP/EFI/OC/Kexts
fish mkdir /ESP/EFI/OC/ACPI
fish mkdir /ESP/EFI/OC/Resources
fish mkdir /ESP/EFI/OC/Tools
fish copy-in $WORK/EFI/BOOT /ESP/EFI
fish copy-in $WORK/EFI/OC/OpenCore.efi /ESP/EFI/OC
fish copy-in $WORK/EFI/OC/Drivers /ESP/EFI/OC/
fish copy-in $WORK/EFI/OC/Kexts /ESP/EFI/OC/
fish copy-in $WORK/EFI/OC/ACPI /ESP/EFI/OC/
fish copy-in $WORK/EFI/OC/Resources /ESP/EFI/OC/
fish copy-in $WORK/EFI/OC/Tools /ESP/EFI/OC/
# Note
fish copy-in startup.nsh /
BASE="$(dirname $0)"
fish copy-in "$WORK/config.plist" /ESP/EFI/OC/
fish find /ESP/
fish_fini