Skip to content

Commit 4e63501

Browse files
closes #31: updated app shell script
1 parent 01b70dd commit 4e63501

File tree

1 file changed

+42
-35
lines changed

1 file changed

+42
-35
lines changed

app/RunMojaveVirtualbox.app/Contents/Resources/runMojaveVirtualbox.sh

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,21 @@ readonly SCRIPTPATH="$(
2020
readonly INST_VERS="$(find /Applications -maxdepth 1 -type d -name 'Install macOS*' | wc -l | tr -d '[:space:]')"
2121
readonly INST_VER="$(find /Applications -maxdepth 1 -type d -name 'Install macOS*' -print -quit)"
2222
readonly INST_BIN="$INST_VER/Contents/Resources/createinstallmedia"
23-
readonly DST_DIR="/tmp"
24-
readonly VM="macOS-Mojave"
25-
readonly VM_DIR="$HOME/VirtualBox VMs/$VM"
26-
readonly VM_SIZE="32768"
27-
readonly VM_RES="1680x1050"
28-
readonly VM_RAM="4096"
29-
readonly VM_VRAM="128"
30-
readonly VM_CPU="2"
31-
readonly DST_DMG="$DST_DIR/$VM.dmg"
32-
readonly DST_CLOVER="$DST_DIR/${VM}Clover"
33-
readonly DST_VOL="/Volumes/$VM"
34-
readonly DST_ISO="$DST_DIR/$VM.iso.cdr"
35-
readonly FILE_EFI="$DST_DIR/apfs.efi"
23+
readonly DST_DIR="${DST_DIR:-$HOME/VirtualBox VMs}"
24+
readonly VM_NAME="${VM_NAME:-macOS-Mojave}"
25+
readonly VM_DIR="${VM_DIR:-$DST_DIR/$VM_NAME}"
26+
readonly VM_SIZE="${VM_SIZE:-32768}"
27+
readonly VM_RES="${VM_RES:-1680x1050}"
28+
readonly VM_RAM="${VM_RAM:-4096}"
29+
readonly VM_VRAM="${VM_VRAM:-128}"
30+
readonly VM_CPU="${VM_CPU:-2}"
31+
readonly DST_DMG="$DST_DIR/$VM_NAME.dmg"
32+
readonly DST_CLOVER="$DST_DIR/${VM_NAME}Clover"
33+
readonly DST_VOL="/Volumes/$VM_NAME"
34+
readonly DST_ISO="$DST_DIR/$VM_NAME.iso.cdr"
35+
readonly FILE_EFI="/tmp/apfs.efi"
3636
readonly FILE_CFG="$SCRIPTPATH/config.plist"
37+
readonly FILE_EFIMOVER="$SCRIPTPATH/moveCloverToEFI.sh"
3738
readonly FILE_LOG="$HOME/Library/Logs/runMojaveVirtualbox.log"
3839
###############################################################################
3940

@@ -114,7 +115,7 @@ runChecks() {
114115
fi
115116
if ! type VBoxManage >/dev/null 2>&1; then
116117
error "'VBoxManage' not installed. Trying to install automatically, if you've brew installed..."
117-
if ! type brew >/dev/null 2>&1; then
118+
if type brew >/dev/null 2>&1; then
118119
brew cask install virtualbox || exit 2
119120
else
120121
exit 2
@@ -124,6 +125,7 @@ runChecks() {
124125
error "'xz' not installed. Trying to install automatically, if you've brew installed..."
125126
if type brew >/dev/null 2>&1; then
126127
brew install xz || exit 3
128+
brew link xz || exit 3
127129
else
128130
exit 3
129131
fi
@@ -171,8 +173,10 @@ createImage() {
171173
if [ ! -e "$DST_DMG" ]; then
172174
result "."
173175
ejectAll
176+
mkdir -p "$DST_DIR"
174177
hdiutil create -o "$DST_DMG" -size 10g -layout SPUD -fs HFS+J &&
175178
hdiutil attach "$DST_DMG" -mountpoint "$DST_VOL" &&
179+
echo sudo "$INST_BIN" --nointeraction --volume "$DST_VOL" --applicationpath "$INST_VER"
176180
sudo "$INST_BIN" --nointeraction --volume "$DST_VOL" --applicationpath "$INST_VER"
177181
ejectAll
178182
else
@@ -181,6 +185,7 @@ createImage() {
181185
info "Creating iso '$DST_ISO' (around 25 seconds)..." 40
182186
if [ ! -e "$DST_ISO" ]; then
183187
result "."
188+
mkdir -p "$DST_DIR"
184189
hdiutil convert "$DST_DMG" -format UDTO -o "$DST_ISO"
185190
else
186191
result "already exists."
@@ -204,14 +209,14 @@ createClover() {
204209
info "Creating clover image '$DST_CLOVER.iso' (around 30 seconds)..."
205210
if [ ! -e "$DST_CLOVER.iso" ]; then
206211
result "."
212+
mkdir -p "$DST_DIR"
207213
extractAPFS
208-
while [ ! -f "clover.tar.lzma" ]; do
214+
while [ ! -f "Clover-v2.4k-4533-X64.iso" ]; do
209215
info " - Downloading Clover (needs Internet access)..." 80
210216
curl -Lk https://sourceforge.net/projects/cloverefiboot/files/Bootable_ISO/CloverISO-4533.tar.lzma/download -o clover.tar.lzma
217+
xz -d clover.tar.lzma && tar xf clover.tar
211218
sleep 1
212219
done
213-
xz -d clover.tar.lzma
214-
tar xf clover.tar
215220
hdiutil detach /Volumes/Clover-v2.4k-4533-X64/ 2>/dev/null || true
216221
hdiutil attach Clover-v2.4k-4533-X64.iso
217222
hdiutil create -megabytes 16 -fs MS-DOS -volname MojaveClover -o "$DST_CLOVER.dmg"
@@ -220,9 +225,11 @@ createClover() {
220225
cp -r /Volumes/Clover-v2.4k-4533-X64/* /Volumes/NO\ NAME/
221226
cp "$FILE_CFG" /Volumes/NO\ NAME/EFI/CLOVER/
222227
cp "$FILE_EFI" /Volumes/NO\ NAME/EFI/CLOVER/drivers64UEFI/
228+
cp "$FILE_EFIMOVER" /Volumes/NO\ NAME/
223229
hdiutil detach /Volumes/Clover-v2.4k-4533-X64/
224230
hdiutil detach /Volumes/NO\ NAME/
225231
hdiutil makehybrid -iso -joliet -o "$DST_CLOVER.iso" "$DST_CLOVER.dmg"
232+
rm -f "$DST_CLOVER.dmg" "$DST_CLOVER.dmg"
226233
else
227234
result "already exists."
228235
fi
@@ -232,34 +239,34 @@ createVM() {
232239
if [ ! -e "$VM_DIR" ]; then
233240
mkdir -p "$VM_DIR"
234241
fi
235-
info "Creating VM HDD '$VM_DIR/$VM.vdi' (around 5 seconds)..." 90
236-
if [ ! -e "$VM_DIR/$VM.vdi" ]; then
242+
info "Creating VM HDD '$VM_DIR/$VM_NAME.vdi' (around 5 seconds)..." 90
243+
if [ ! -e "$VM_DIR/$VM_NAME.vdi" ]; then
237244
result "."
238-
VBoxManage createhd --filename "$VM_DIR/$VM.vdi" --variant Standard --size "$VM_SIZE"
245+
VBoxManage createhd --filename "$VM_DIR/$VM_NAME.vdi" --variant Standard --size "$VM_SIZE"
239246
else
240247
result "already exists."
241248
fi
242-
info "Creating VM '$VM' (around 2 seconds)..." 99
243-
if ! VBoxManage showvminfo "$VM" >/dev/null 2>&1; then
249+
info "Creating VM '$VM_NAME' (around 2 seconds)..." 99
250+
if ! VBoxManage showvminfo "$VM_NAME" >/dev/null 2>&1; then
244251
result "."
245-
VBoxManage createvm --register --name "$VM" --ostype MacOS1013_64
246-
VBoxManage modifyvm "$VM" --usbxhci on --memory "$VM_RAM" --vram "$VM_VRAM" --cpus "$VM_CPU" --firmware efi --chipset ich9 --mouse usbtablet --keyboard usb
247-
VBoxManage setextradata "$VM" "CustomVideoMode1" "${VM_RES}x32"
248-
VBoxManage setextradata "$VM" VBoxInternal2/EfiGraphicsResolution "$VM_RES"
249-
VBoxManage storagectl "$VM" --name "SATA Controller" --add sata --controller IntelAHCI --hostiocache on
250-
VBoxManage storageattach "$VM" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --nonrotational on --medium "$VM_DIR/$VM.vdi"
251-
VBoxManage storageattach "$VM" --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium "$DST_CLOVER.iso"
252-
VBoxManage storageattach "$VM" --storagectl "SATA Controller" --port 2 --device 0 --type dvddrive --medium "$DST_ISO"
252+
VBoxManage createvm --register --name "$VM_NAME" --ostype MacOS1013_64
253+
VBoxManage modifyvm "$VM_NAME" --usbxhci on --memory "$VM_RAM" --vram "$VM_VRAM" --cpus "$VM_CPU" --firmware efi --chipset ich9 --mouse usbtablet --keyboard usb
254+
VBoxManage setextradata "$VM_NAME" "CustomVideoMode1" "${VM_RES}x32"
255+
VBoxManage setextradata "$VM_NAME" VBoxInternal2/EfiGraphicsResolution "$VM_RES"
256+
VBoxManage storagectl "$VM_NAME" --name "SATA Controller" --add sata --controller IntelAHCI --hostiocache on
257+
VBoxManage storageattach "$VM_NAME" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --nonrotational on --medium "$VM_DIR/$VM_NAME.vdi"
258+
VBoxManage storageattach "$VM_NAME" --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium "$DST_CLOVER.iso"
259+
VBoxManage storageattach "$VM_NAME" --storagectl "SATA Controller" --port 2 --device 0 --type dvddrive --medium "$DST_ISO"
253260
else
254261
result "already exists."
255262
fi
256263
}
257264

258265
runVM() {
259-
info "Starting VM '$VM' (3 minutes in the VM)..." 100
266+
info "Starting VM '$VM_NAME' (3 minutes in the VM)..." 100
260267
if ! VBoxManage showvminfo 'macOS-Mojave' | grep "State:" | grep -i running >/dev/null; then
261268
result "."
262-
VBoxManage startvm "$VM" --type gui
269+
VBoxManage startvm "$VM_NAME" --type gui
263270
echo "Next steps:"
264271
echo " 1. Disk Utility: erase the virtual drive using APFS and call it 'Mojave' (it will be converted otherwise)"
265272
echo " 2. Install macOS: on the erased virtual drive 'Mojave' (around 4 minutes)"
@@ -281,7 +288,7 @@ cleanup() {
281288
local command="${4:-}"
282289
local funcstack="${5:-}"
283290
ejectAll
284-
if [[ "$err" -ne "0" ]]; then
291+
if [[ $err -ne "0" ]]; then
285292
debug "line $line - command '$command' exited with status: $err."
286293
debug "In $funcstack called at line $linecallfunc."
287294
debug "From function ${funcstack[0]} (line $linecallfunc)."
@@ -300,7 +307,7 @@ main() {
300307
case "$ARG" in
301308
check) runChecks ;;
302309
clean) runClean ;;
303-
stash) VBoxManage unregistervm --delete "$VM" || true ;;
310+
stash) VBoxManage unregistervm --delete "$VM_NAME" || true ;;
304311
installer) createImage ;;
305312
clover) createClover ;;
306313
vm) createVM ;;
@@ -313,5 +320,5 @@ main() {
313320
###############################################################################
314321

315322
# Run script ##################################################################
316-
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && trap 'cleanup "${?}" "${LINENO}" "${BASH_LINENO}" "${BASH_COMMAND}" $(printf "::%s" ${FUNCNAME[@]:-})' EXIT && main "${@:-}"
323+
[[ ${BASH_SOURCE[0]} == "${0}" ]] && trap 'cleanup "${?}" "${LINENO}" "${BASH_LINENO}" "${BASH_COMMAND}" $(printf "::%s" ${FUNCNAME[@]:-})' EXIT && main "${@:-}"
317324
###############################################################################

0 commit comments

Comments
 (0)