replaced various newlines with $'\n'

This commit is contained in:
Jack
2020-04-27 20:59:53 +03:00
parent 13cde82df1
commit 9f286192f6
+39 -63
View File
@@ -186,11 +186,10 @@ if [[ -n "$(sw_vers 2>/dev/null)" ]]; then
fi fi
# if csplit isn't GNU variant, exit # if csplit isn't GNU variant, exit
if [[ -z "$(csplit --help 2>/dev/null)" ]]; then if [[ -z "$(csplit --help 2>/dev/null)" ]]; then
echo "" printf $'\n''macOS detected.'$'\n''Please use a package manager such as '"${highlight_color}"'homebrew'"${default_color}"', '"${highlight_color}"'pkgsrc'"${default_color}"', '"${highlight_color}"'nix'"${default_color}"', or '"${highlight_color}"'MacPorts'"${default_color}"'.'$'\n'
printf 'macOS detected.\nPlease use a package manager such as '"${highlight_color}"'homebrew'"${default_color}"', '"${highlight_color}"'pkgsrc'"${default_color}"', '"${highlight_color}"'nix'"${default_color}"', or '"${highlight_color}"'MacPorts'"${default_color}"'.\n'
echo "Please make sure the following packages are installed and that" echo "Please make sure the following packages are installed and that"
echo "their path is in the PATH variable:" echo "their path is in the PATH variable:"
printf "${highlight_color}"'bash coreutils dmg2img gzip unzip wget xxd'"${default_color}"'\n' printf "${highlight_color}"'bash coreutils dmg2img gzip unzip wget xxd'"${default_color}"$'\n'
echo "Please make sure Bash and coreutils are the GNU variant." echo "Please make sure Bash and coreutils are the GNU variant."
exit exit
fi fi
@@ -244,20 +243,16 @@ if [[ -n "$(cygcheck -V 2>/dev/null)" ]]; then
elif [[ "$(cat /proc/sys/kernel/osrelease 2>/dev/null)" =~ [Mm]icrosoft ]]; then elif [[ "$(cat /proc/sys/kernel/osrelease 2>/dev/null)" =~ [Mm]icrosoft ]]; then
osrelease="$(cat /proc/sys/kernel/osrelease 2>/dev/null)" osrelease="$(cat /proc/sys/kernel/osrelease 2>/dev/null)"
if [[ "${osrelease}" =~ microsoft ]]; then # WSL2 if [[ "${osrelease}" =~ microsoft ]]; then # WSL2
echo "" echo $'\n'"Using WSL2 and VirtualBox requires using Hyper-V with VirtualBox."
echo "Using WSL2 and VirtualBox requires using Hyper-V with VirtualBox." printf "${warning_color}"'VirtualBox usually doen'"'"'t work with WSL2 installed.'"${default_color}"$'\n'
printf "${warning_color}"'VirtualBox usually doen'"'"'t work with WSL2 installed.'"${default_color}"'\n' printf $'\n'"${highlight_color}"'Press enter to continue, CTRL-C to exit.'"${default_color}"
echo ""
printf "${highlight_color}"'Press enter to continue, CTRL-C to exit.'"${default_color}"
clear_input_buffer_then_read clear_input_buffer_then_read
elif [[ ( "${osrelease}" =~ Microsoft ) ]]; then # WSL (1) elif [[ ( "${osrelease}" =~ Microsoft ) ]]; then # WSL (1)
echo "" echo $'\n'"Some versions of WSL require the script to run on a Windows filesystem path,"
echo "Some versions of WSL require the script to run on a Windows filesystem path," printf 'for example '"${highlight_color}"'/mnt/c/Users/Public/Documents'"${default_color}"$'\n'
printf 'for example '"${highlight_color}"'/mnt/c/Users/Public/Documents'"${default_color}"'\n'
echo "Switch to a path on the Windows filesystem if VBoxManage.exe fails to" echo "Switch to a path on the Windows filesystem if VBoxManage.exe fails to"
echo "create or open a file." echo "create or open a file."
echo "" printf $'\n'"${highlight_color}"'Press enter to continue, CTRL-C to exit.'"${default_color}"
printf "${highlight_color}"'Press enter to continue, CTRL-C to exit.'"${default_color}"
clear_input_buffer_then_read clear_input_buffer_then_read
fi fi
if [[ -n "$(VBoxManage.exe -v 2>/dev/null)" ]]; then if [[ -n "$(VBoxManage.exe -v 2>/dev/null)" ]]; then
@@ -296,13 +291,11 @@ if [[ -z "${vbox_version}" || -z "${vbox_version:2:1}" ]]; then
exit exit
elif [[ ! ( "${vbox_version:0:1}" -gt 5 elif [[ ! ( "${vbox_version:0:1}" -gt 5
|| "${vbox_version:0:3}" =~ 5\.2 ) ]]; then || "${vbox_version:0:3}" =~ 5\.2 ) ]]; then
echo "" echo $'\n'"Please make sure VirtualBox version 5.2 or higher is installed."
echo "Please make sure VirtualBox version 5.2 or higher is installed."
echo "Exiting." echo "Exiting."
exit exit
elif [[ "${vbox_version:0:1}" = 5 ]]; then elif [[ "${vbox_version:0:1}" = 5 ]]; then
echo "" printf $'\n'"${highlight_color}"'VirtualBox version '"${vbox_version}"' detected.'"${default_color}"' Please see the following
printf "${highlight_color}"'VirtualBox version '"${vbox_version}"' detected.'"${default_color}"' Please see the following
URL for issues with the VISO filesystem on VirtualBox 5.2 to 5.2.40: URL for issues with the VISO filesystem on VirtualBox 5.2 to 5.2.40:
https://github.com/myspaghetti/macos-guest-virtualbox/issues/86 https://github.com/myspaghetti/macos-guest-virtualbox/issues/86
@@ -353,8 +346,7 @@ if [[ "${macOS_release_name:0:1}" =~ [Cc] ]]; then
"${vbox_version}" =~ ^6\.1\.[4-9] || "${vbox_version}" =~ ^6\.1\.[4-9] ||
"${vbox_version}" =~ ^6\.1\.[123][0-9] || "${vbox_version}" =~ ^6\.1\.[123][0-9] ||
"${vbox_version}" =~ ^6\.[2-9] ) ]]; then "${vbox_version}" =~ ^6\.[2-9] ) ]]; then
echo "" echo $'\n'"macOS Catalina requires VirtualBox version 6.1.4 or higher."
echo "macOS Catalina requires VirtualBox version 6.1.4 or higher."
echo "Exiting." echo "Exiting."
exit exit
fi fi
@@ -382,8 +374,7 @@ if [[ -n "$(VBoxManage showvminfo "${vm_name}" 2>/dev/null)" ]]; then
echo "Deleting ${vm_name} virtual machine." echo "Deleting ${vm_name} virtual machine."
VBoxManage unregistervm "${vm_name}" --delete VBoxManage unregistervm "${vm_name}" --delete
else else
echo "" printf $'\n'"${highlight_color}"'Please assign a different VM name to variable "vm_name" by editing the script,'"${default_color}"$'\n'
printf "${highlight_color}"'Please assign a different VM name to variable "vm_name" by editing the script,'"${default_color}\n"
echo "or skip this check manually as described when running the following command:" echo "or skip this check manually as described when running the following command:"
would_you_like_to_know_less would_you_like_to_know_less
exit exit
@@ -395,7 +386,7 @@ fi
function create_vm() { function create_vm() {
print_dimly "stage: create_vm" print_dimly "stage: create_vm"
if [[ -n "$( VBoxManage createvm --name "${vm_name}" --ostype "MacOS1013_64" --register 2>&1 >/dev/null )" ]]; then if [[ -n "$( VBoxManage createvm --name "${vm_name}" --ostype "MacOS1013_64" --register 2>&1 >/dev/null )" ]]; then
printf '\nError: Could not create virtual machine "'"${vm_name}"'". printf $'\n''Error: Could not create virtual machine "'"${vm_name}"'".
'"${highlight_color}"'Please delete exising "'"${vm_name}"'" VirtualBox configuration files '"${warning_color}"'manually'"${default_color}"'. '"${highlight_color}"'Please delete exising "'"${vm_name}"'" VirtualBox configuration files '"${warning_color}"'manually'"${default_color}"'.
Error message: Error message:
@@ -408,8 +399,7 @@ fi
function prepare_macos_installation_files() { function prepare_macos_installation_files() {
print_dimly "stage: prepare_macos_installation_files" print_dimly "stage: prepare_macos_installation_files"
# Find the correct download URL in the Apple catalog # Find the correct download URL in the Apple catalog
echo "" echo $'\n'"Downloading Apple macOS ${macOS_release_name} software update catalog"
echo "Downloading Apple macOS ${macOS_release_name} software update catalog"
wget "${sucatalog}" \ wget "${sucatalog}" \
${wgetargs} \ ${wgetargs} \
--output-document="${macOS_release_name}_sucatalog" --output-document="${macOS_release_name}_sucatalog"
@@ -417,8 +407,7 @@ wget "${sucatalog}" \
# if file was not downloaded correctly # if file was not downloaded correctly
if [[ ! -s "${macOS_release_name}_sucatalog" ]]; then if [[ ! -s "${macOS_release_name}_sucatalog" ]]; then
wget --debug -O /dev/null -o "${macOS_release_name}_wget.log" "${sucatalog}" wget --debug -O /dev/null -o "${macOS_release_name}_wget.log" "${sucatalog}"
echo "" echo $'\n'"Couldn't download the Apple software update catalog."
echo "Couldn't download the Apple software update catalog."
if [[ "$(expr match "$(cat "${macOS_release_name}_wget.log")" '.*ERROR[[:print:]]*is not trusted')" -gt "0" ]]; then if [[ "$(expr match "$(cat "${macOS_release_name}_wget.log")" '.*ERROR[[:print:]]*is not trusted')" -gt "0" ]]; then
printf ' printf '
Make sure certificates from a certificate authority are installed. Make sure certificates from a certificate authority are installed.
@@ -444,8 +433,7 @@ for catalog in "${macOS_release_name}_sucatalog_"* "error"; do
--output-document="${catalog}_InstallAssistantAuto.smd" --output-document="${catalog}_InstallAssistantAuto.smd"
found_version="$(head -n 6 "${catalog}_InstallAssistantAuto.smd" | tail -n 1)" found_version="$(head -n 6 "${catalog}_InstallAssistantAuto.smd" | tail -n 1)"
if [[ "${found_version}" == *${CFBundleShortVersionString}* ]]; then if [[ "${found_version}" == *${CFBundleShortVersionString}* ]]; then
echo "Found download URL: ${urlbase}" echo "Found download URL: ${urlbase}"$'\n'
echo ""
rm "${macOS_release_name}_sucatalog"* rm "${macOS_release_name}_sucatalog"*
break break
fi fi
@@ -462,15 +450,13 @@ for filename in "BaseSystem.chunklist" \
--output-document "${macOS_release_name}_${filename}" --output-document "${macOS_release_name}_${filename}"
done done
echo "" echo $'\n'"Splitting the several-GB InstallESDDmg.pkg into 1GB parts because"
echo "Splitting the several-GB InstallESDDmg.pkg into 1GB parts because"
echo "VirtualBox hasn't implemented UDF/HFS VISO support yet and macOS" echo "VirtualBox hasn't implemented UDF/HFS VISO support yet and macOS"
echo "doesn't support ISO 9660 Level 3 with files larger than 2GB." echo "doesn't support ISO 9660 Level 3 with files larger than 2GB."
split --verbose -a 2 -d -b 1000000000 "${macOS_release_name}_InstallESDDmg.pkg" "${macOS_release_name}_InstallESD.part" split --verbose -a 2 -d -b 1000000000 "${macOS_release_name}_InstallESDDmg.pkg" "${macOS_release_name}_InstallESD.part"
if [[ ! -s "ApfsDriverLoader.efi" ]]; then if [[ ! -s "ApfsDriverLoader.efi" ]]; then
echo "" echo $'\n'"Downloading open-source APFS EFI drivers used for VirtualBox 6.0 and 5.2"
echo "Downloading open-source APFS EFI drivers used for VirtualBox 6.0 and 5.2"
[[ "${vbox_version:0:1}" -gt 6 || ( "${vbox_version:0:1}" = 6 && "${vbox_version:2:1}" -ge 1 ) ]] && echo "...even though VirtualBox version 6.1 or higher is detected." [[ "${vbox_version:0:1}" -gt 6 || ( "${vbox_version:0:1}" = 6 && "${vbox_version:2:1}" -ge 1 ) ]] && echo "...even though VirtualBox version 6.1 or higher is detected."
wget 'https://github.com/acidanthera/AppleSupportPkg/releases/download/2.0.4/AppleSupport-v2.0.4-RELEASE.zip' \ wget 'https://github.com/acidanthera/AppleSupportPkg/releases/download/2.0.4/AppleSupport-v2.0.4-RELEASE.zip' \
${wgetargs} \ ${wgetargs} \
@@ -592,10 +578,8 @@ for %a run (1 5)
endif endif
endfor' >> "${vm_name}_startup.nsh" endfor' >> "${vm_name}_startup.nsh"
echo "" echo $'\n'"Creating VirtualBox 6 virtual ISO containing the"
echo "Creating VirtualBox 6 virtual ISO containing the" echo "installation files from swcdn.apple.com"$'\n'
echo "installation files from swcdn.apple.com"
echo ""
pseudouuid="$(od -tx -N16 /dev/urandom | xxd -r | xxd -p)" pseudouuid="$(od -tx -N16 /dev/urandom | xxd -r | xxd -p)"
pseudouuid="${pseudouuid:0:8}-${pseudouuid:8:4}-${pseudouuid:12:4}-${pseudouuid:16:4}-${pseudouuid:20:12}" pseudouuid="${pseudouuid:0:8}-${pseudouuid:8:4}-${pseudouuid:12:4}-${pseudouuid:16:4}-${pseudouuid:20:12}"
echo "--iprt-iso-maker-file-marker-bourne-sh "${pseudouuid}" echo "--iprt-iso-maker-file-marker-bourne-sh "${pseudouuid}"
@@ -643,8 +627,7 @@ print_dimly "stage: create_basesystem_vdi"
if [[ -s "${macOS_release_name}_BaseSystem.vdi" ]]; then if [[ -s "${macOS_release_name}_BaseSystem.vdi" ]]; then
echo "${macOS_release_name}_BaseSystem.vdi bootstrap virtual disk image exists." echo "${macOS_release_name}_BaseSystem.vdi bootstrap virtual disk image exists."
elif [[ ! -s "${macOS_release_name}_BaseSystem.dmg" ]]; then elif [[ ! -s "${macOS_release_name}_BaseSystem.dmg" ]]; then
echo "" echo $'\n'"Could not find ${macOS_release_name}_BaseSystem.dmg; exiting."
echo "Could not find ${macOS_release_name}_BaseSystem.dmg; exiting."
exit exit
else else
local failed='' local failed=''
@@ -880,13 +863,10 @@ echo "The VM will boot from the populated installer base system virtual disk."
prompt_lang_utils prompt_lang_utils
prompt_terminal_ready prompt_terminal_ready
add_another_terminal add_another_terminal
echo "" echo $'\n'"The second open Terminal in the virtual machine copies EFI and NVRAM files"
echo "The second open Terminal in the virtual machine copies EFI and NVRAM files"
echo "to the target EFI system partition when the installer finishes preparing." echo "to the target EFI system partition when the installer finishes preparing."
echo "" echo $'\n'"After the installer finishes preparing and the EFI and NVRAM files are copied,"
echo "After the installer finishes preparing and the EFI and NVRAM files are copied," echo "macOS will install and run when booting the target disk."$'\n'
echo "macOS will install and run when booting the target disk."
echo ""
# run script concurrently, catch SIGUSR1 when installer finishes preparing # run script concurrently, catch SIGUSR1 when installer finishes preparing
kbstring='disks="$(diskutil list | grep -o "[0-9][^ ]* GB *disk[0-9]$" | sort -gr | grep -o disk[0-9])" && '\ kbstring='disks="$(diskutil list | grep -o "[0-9][^ ]* GB *disk[0-9]$" | sort -gr | grep -o disk[0-9])" && '\
'disks=(${disks[@]}) && '\ 'disks=(${disks[@]}) && '\
@@ -917,13 +897,13 @@ powers off the virtual machine and detaches the device "'"Install ${macOS_releas
booting into the initial installer environment again.' booting into the initial installer environment again.'
clear_input_buffer_then_read clear_input_buffer_then_read
VBoxManage controlvm "${vm_name}" poweroff >/dev/null 2>&1 VBoxManage controlvm "${vm_name}" poweroff >/dev/null 2>&1
for (( i=10; i>5; i-- )); do printf ' \r'"${i}"; sleep 0.5; done for (( i=10; i>5; i-- )); do printf $' \r'"${i}"; sleep 0.5; done
VBoxManage storagectl "${vm_name}" --remove --name SATA >/dev/null 2>&1 VBoxManage storagectl "${vm_name}" --remove --name SATA >/dev/null 2>&1
VBoxManage storagectl "${vm_name}" --add sata --name SATA --hostiocache on >/dev/null 2>&1 VBoxManage storagectl "${vm_name}" --add sata --name SATA --hostiocache on >/dev/null 2>&1
VBoxManage storageattach "${vm_name}" --storagectl SATA --port 0 \ VBoxManage storageattach "${vm_name}" --storagectl SATA --port 0 \
--type hdd --nonrotational on --medium "${vm_name}.vdi" --type hdd --nonrotational on --medium "${vm_name}.vdi"
echo "" echo ""
for (( i=5; i>0; i-- )); do printf ' \r'"${i}"; sleep 0.5; done for (( i=5; i>0; i-- )); do printf $' \r'"${i}"; sleep 0.5; done
fi fi
printf ' printf '
For further information, such as applying EFI and NVRAM variables to enable For further information, such as applying EFI and NVRAM variables to enable
@@ -931,7 +911,7 @@ iMessage connectivity, see the documentation with the following command:
' '
would_you_like_to_know_less would_you_like_to_know_less
printf '\n'"${highlight_color}"'That'"'"'s it! Enjoy your virtual machine.'"${default_color}"'\n' printf $'\n'"${highlight_color}"'That'"'"'s it! Enjoy your virtual machine.'"${default_color}"$'\n'
} }
@@ -943,7 +923,7 @@ then
and without a suspended state by running the following command at the script'"'"'s and without a suspended state by running the following command at the script'"'"'s
working directory: working directory:
'"${highlight_color}${0} delete_temporary_files${default_color}"'\n' '"${highlight_color}${0} delete_temporary_files${default_color}"$'\n'
else else
# detach temporary VDIs and attach the macOS target disk # detach temporary VDIs and attach the macOS target disk
VBoxManage storagectl "${vm_name}" --remove --name SATA >/dev/null 2>&1 VBoxManage storagectl "${vm_name}" --remove --name SATA >/dev/null 2>&1
@@ -954,8 +934,7 @@ else
fi fi
VBoxManage closemedium "Install ${macOS_release_name}.vdi" >/dev/null 2>&1 VBoxManage closemedium "Install ${macOS_release_name}.vdi" >/dev/null 2>&1
VBoxManage closemedium "${macOS_release_name}_BaseSystem.vdi" >/dev/null 2>&1 VBoxManage closemedium "${macOS_release_name}_BaseSystem.vdi" >/dev/null 2>&1
echo 'The following temporary files are safe to delete:' echo 'The following temporary files are safe to delete:'$'\n'
echo ""
temporary_files=("${macOS_release_name}_Apple"* temporary_files=("${macOS_release_name}_Apple"*
"${macOS_release_name}_BaseSystem"* "${macOS_release_name}_BaseSystem"*
"${macOS_release_name}_Install"* "${macOS_release_name}_Install"*
@@ -967,8 +946,7 @@ else
"AppleSupport-v2.0.4-RELEASE.zip" "AppleSupport-v2.0.4-RELEASE.zip"
"dmg2img.exe") "dmg2img.exe")
ls -d "${temporary_files[@]}" 2>/dev/null ls -d "${temporary_files[@]}" 2>/dev/null
echo "" printf $'\n'"${warning_color}"'Delete temporary files listed above?'"${default_color}"
printf "${warning_color}"'Delete temporary files listed above?'"${default_color}"
prompt_delete_y_n prompt_delete_y_n
if [[ "${delete}" == "y" ]]; then if [[ "${delete}" == "y" ]]; then
rm -f "${temporary_files[@]}" 2>/dev/null rm -f "${temporary_files[@]}" 2>/dev/null
@@ -980,7 +958,7 @@ fi
function documentation() { function documentation() {
low_contrast_stages="" low_contrast_stages=""
for stage in ${stages}; do for stage in ${stages}; do
low_contrast_stages="${low_contrast_stages}"' '"${low_contrast_color}${stage}${default_color}"'\n' low_contrast_stages="${low_contrast_stages}"' '"${low_contrast_color}${stage}${default_color}"$'\n'
done done
printf " printf "
${highlight_color}NAME${default_color} ${highlight_color}NAME${default_color}
@@ -1185,7 +1163,7 @@ default_color=$'\033[0m'
# prints positional parameters in low contrast preceded and followed by newline # prints positional parameters in low contrast preceded and followed by newline
function print_dimly() { function print_dimly() {
printf "\n${low_contrast_color}$@${default_color}\n" printf $'\n'"${low_contrast_color}$@${default_color}"$'\n'
} }
# don't need sleep when we can read! # don't need sleep when we can read!
@@ -1365,10 +1343,10 @@ function send_enter() {
function prompt_lang_utils() { function prompt_lang_utils() {
# called after the virtual machine boots up # called after the virtual machine boots up
printf '\n'"${highlight_color}"'Press enter when the Language window is ready.'"${default_color}" printf $'\n'"${highlight_color}"'Press enter when the Language window is ready.'"${default_color}"
clear_input_buffer_then_read clear_input_buffer_then_read
send_enter send_enter
printf '\n'"${highlight_color}"'Press enter when the macOS Utilities window is ready.'"${default_color}" printf $'\n'"${highlight_color}"'Press enter when the macOS Utilities window is ready.'"${default_color}"
clear_input_buffer_then_read clear_input_buffer_then_read
kbspecial='CTRLprs F2 CTRLrls u ENTER t ENTER' kbspecial='CTRLprs F2 CTRLrls u ENTER t ENTER'
send_special send_special
@@ -1376,7 +1354,7 @@ function prompt_lang_utils() {
function prompt_terminal_ready() { function prompt_terminal_ready() {
# called after the Utilities window is ready # called after the Utilities window is ready
printf '\n'"${highlight_color}"'Press enter when the Terminal command prompt is ready.'"${default_color}" printf $'\n'"${highlight_color}"'Press enter when the Terminal command prompt is ready.'"${default_color}"
clear_input_buffer_then_read clear_input_buffer_then_read
} }
@@ -1406,9 +1384,9 @@ function cycle_through_terminal_windows() {
function would_you_like_to_know_less() { function would_you_like_to_know_less() {
if [[ -z "$(less --version 2>/dev/null)" ]]; then if [[ -z "$(less --version 2>/dev/null)" ]]; then
printf ' '"${highlight_color}${0} documentation${default_color}"'\n' printf ' '"${highlight_color}${0} documentation${default_color}"$'\n'
else else
printf ' '"${highlight_color}${0} documentation | less -R${default_color}"'\n' printf ' '"${highlight_color}${0} documentation | less -R${default_color}"$'\n'
fi fi
} }
@@ -1459,12 +1437,10 @@ stages_without_newlines="${stages_without_newlines//troubleshoot/}" # strip al
# for the command-line argument checking below to work # for the command-line argument checking below to work
for argument in $@; do for argument in $@; do
if [[ "${stages_without_newlines}" != *" ${argument} "* ]]; then if [[ "${stages_without_newlines}" != *" ${argument} "* ]]; then
echo "" echo $'\n'"Can't parse one or more specified arguments. See documentation"
echo "Can't parse one or more specified arguments. See documentation"
echo "by entering the following command:" echo "by entering the following command:"
would_you_like_to_know_less would_you_like_to_know_less
echo "" echo $'\n'"Available stages: ${stages}"
echo "Available stages: ${stages}"
exit exit
fi fi
done done