On WSL, if there's whitespace in VBoxManage variables, exit
plus some printf statement cosmetic changes
This commit is contained in:
+16
-19
@@ -2,7 +2,7 @@
|
|||||||
# One-key semi-automatic installer of macOS on VirtualBox
|
# One-key semi-automatic installer of macOS on VirtualBox
|
||||||
# (c) img2tab, licensed under GPL2.0 or higher
|
# (c) img2tab, licensed under GPL2.0 or higher
|
||||||
# url: https://github.com/img2tab/macos-guest-virtualbox
|
# url: https://github.com/img2tab/macos-guest-virtualbox
|
||||||
# version 0.54
|
# version 0.55
|
||||||
|
|
||||||
# Requirements: 33.5GB available storage on host
|
# Requirements: 33.5GB available storage on host
|
||||||
# Dependencies: bash>=4.0, unzip, wget, dmg2img,
|
# Dependencies: bash>=4.0, unzip, wget, dmg2img,
|
||||||
@@ -101,20 +101,22 @@ if [ -z "$(VBoxManage -v 2>/dev/null)" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Windows Subsystem for Linux (WSL)
|
# Windows Subsystem for Linux (WSL)
|
||||||
wsl_home=""
|
wsl_home="" # if the Windows home directory path contains spaces, please assign a rw-able path without spaces
|
||||||
if [[ "$(cat /proc/sys/kernel/osrelease 2>/dev/null)" == *"Microsoft"* ]]; then
|
if [[ -z "${wsl_home}" && "$(cat /proc/sys/kernel/osrelease 2>/dev/null)" == *"Microsoft"* ]]; then
|
||||||
wsl_home="$(cmd.exe /C cd)"
|
wsl_home="$(cmd.exe /C cd)"
|
||||||
wsl_home="${wsl_home:0:-1}"'\' # remove trailing newline \M
|
wsl_home="${wsl_home:0:-1}"'\' # remove trailing newline \M
|
||||||
printf '
|
if [[ ${wsl_home} == *" "* || ${vmname} == *" "* ]]; then
|
||||||
Windows Subsystem for Linux results in unexpected behavior when VBoxManage
|
printf 'VBoxManage behaves unexpectedly when interpreting variables with whitespace
|
||||||
interprets '${whiteonblack}'quoted variables with whitespace'${defaultcolor}', so if your Windows home directory
|
on Windows Subsystem for Linux. '${whiteonblack}'Please assign values without whitespace'${defaultcolor}' to the
|
||||||
or assigned script variables contain whitespaces please choose ones without.
|
variables "wsl_home", a Windows-style backslash-terminated path for a readable
|
||||||
'
|
and writable working directory (for example "C:\\Users\\Default\\"), and "vmname".\n'
|
||||||
|
exit
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# macOS
|
# macOS
|
||||||
if [ -n "$(sw_vers 2>/dev/null)" ]; then
|
if [ -n "$(sw_vers 2>/dev/null)" ]; then
|
||||||
printf 'This script is not tested on macOS. Exiting.'
|
printf '\nThis script is not tested on macOS. Exiting.'
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -160,8 +162,7 @@ echo "Found BaseSystem.dmg URL: ${urlbase}BaseSystem.dmg"
|
|||||||
# Prompt to delete existing virtual machine config:
|
# Prompt to delete existing virtual machine config:
|
||||||
function prompt_delete_existing_vm() {
|
function prompt_delete_existing_vm() {
|
||||||
if [ -n "$(VBoxManage showvminfo "${vmname}")" ]; then
|
if [ -n "$(VBoxManage showvminfo "${vmname}")" ]; then
|
||||||
printf '
|
printf '\n'"${vmname}"' virtual machine already exists.
|
||||||
'"${vmname}"' virtual machine already exists.
|
|
||||||
'${whiteonred}'Delete existing virtual machine "'${vmname}'"?'${defaultcolor}
|
'${whiteonred}'Delete existing virtual machine "'${vmname}'"?'${defaultcolor}
|
||||||
delete=""
|
delete=""
|
||||||
read -n 1 -p " [y/n] " delete 2>/dev/tty
|
read -n 1 -p " [y/n] " delete 2>/dev/tty
|
||||||
@@ -169,8 +170,7 @@ if [ -n "$(VBoxManage showvminfo "${vmname}")" ]; then
|
|||||||
if [ "${delete}" == "y" ]; then
|
if [ "${delete}" == "y" ]; then
|
||||||
VBoxManage unregistervm "${vmname}" --delete
|
VBoxManage unregistervm "${vmname}" --delete
|
||||||
else
|
else
|
||||||
printf '
|
printf '\n'${whiteonblack}'Please assign a different VM name to variable "vmname" by editing the script,'${defaultcolor}'
|
||||||
'${whiteonblack}'Please assign a different VM name to variable "vmname" by editing the script,'${defaultcolor}'
|
|
||||||
or skip this check manually as described in "'${0}' stages".'
|
or skip this check manually as described in "'${0}' stages".'
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
@@ -180,8 +180,7 @@ fi
|
|||||||
# Attempt to create new virtual machine named "${vmname}"
|
# Attempt to create new virtual machine named "${vmname}"
|
||||||
function create_vm() {
|
function create_vm() {
|
||||||
if [ -n "$(VBoxManage createvm --name "${vmname}" --ostype "MacOS1013_64" --register 2>&1 1>/dev/null)" ]; then
|
if [ -n "$(VBoxManage createvm --name "${vmname}" --ostype "MacOS1013_64" --register 2>&1 1>/dev/null)" ]; then
|
||||||
printf '
|
printf '\nError: Could not create virtual machine "'${vmname}'".
|
||||||
Error: Could not create virtual machine "'${vmname}'".
|
|
||||||
'${whiteonblack}'Please delete exising "'${vmname}'" VirtualBox configuration files '${whiteonred}'manually'${defaultcolor}'.
|
'${whiteonblack}'Please delete exising "'${vmname}'" VirtualBox configuration files '${whiteonred}'manually'${defaultcolor}'.
|
||||||
|
|
||||||
Error message:
|
Error message:
|
||||||
@@ -658,8 +657,7 @@ function boot_macos_installer() {
|
|||||||
echo "The VM will boot from the target virtual disk image."
|
echo "The VM will boot from the target virtual disk image."
|
||||||
VBoxManage startvm "${vmname}"
|
VBoxManage startvm "${vmname}"
|
||||||
|
|
||||||
printf '
|
printf '\nmacOS Mojave 10.14 will now install and start up.
|
||||||
macOS Mojave 10.14 will now install and start up.
|
|
||||||
|
|
||||||
Temporary files are safe to delete. '${whiteonred}'Delete temporary files?'${defaultcolor}
|
Temporary files are safe to delete. '${whiteonred}'Delete temporary files?'${defaultcolor}
|
||||||
delete=""
|
delete=""
|
||||||
@@ -686,8 +684,7 @@ That'\''s it. Enjoy your virtual machine.
|
|||||||
}
|
}
|
||||||
|
|
||||||
function stages() {
|
function stages() {
|
||||||
printf '
|
printf '\nUSAGE: '${whiteonblack}${0}' [STAGE]...'${defaultcolor}'
|
||||||
USAGE: '${whiteonblack}${0}' [STAGE]...'${defaultcolor}'
|
|
||||||
|
|
||||||
The script is divided into stages that run as separate functions.
|
The script is divided into stages that run as separate functions.
|
||||||
Add one or more stage titles to the command line to run the corresponding
|
Add one or more stage titles to the command line to run the corresponding
|
||||||
|
|||||||
Reference in New Issue
Block a user