From eb86edb8954072aa69d6bcaa6df375663ccacfab Mon Sep 17 00:00:00 2001 From: img2tab <31696646+img2tab@users.noreply.github.com> Date: Sat, 9 Mar 2019 03:59:00 +0000 Subject: [PATCH] absolute path for WSL only --- macos-guest-virtualbox.sh | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/macos-guest-virtualbox.sh b/macos-guest-virtualbox.sh index 78b4e52..e682efa 100644 --- a/macos-guest-virtualbox.sh +++ b/macos-guest-virtualbox.sh @@ -2,7 +2,7 @@ # One-key semi-automatic installer of macOS on VirtualBox # (c) img2tab, licensed under GPL2.0 or higher # url: https://github.com/img2tab/macos-guest-virtualbox -# version 0.45 +# version 0.46 # Requirements: 33.5GB available storage on host # Dependencies: bash>=4.0, unzip, wget, dmg2img, @@ -99,6 +99,13 @@ if [ -z "$(VBoxManage -v 2>/dev/null)" ]; then fi fi +# WSL working directory hijinks +tmp_path="" +if [[ "$(cat /proc/sys/kernel/osrelease 2>/dev/null)" == *"Microsoft"* ]]; then + tmp_path="${PWD}/" +fi + + # dmg2img if [ -z "$(dmg2img -d 2>/dev/null)" ]; then if [ -z "$(cygcheck -V 2>/dev/null)" ]; then @@ -169,9 +176,15 @@ or http://swscan.apple.com/content/catalogs/others/ exit fi echo "Downloaded BaseSystem.dmg. Converting to BaseSystem.img" - dmg2img "BaseSystem.dmg" "BaseSystem.img" - VBoxManage convertfromraw --format VDI "${PWD}/BaseSystem.img" "${PWD}/BaseSystem.vdi" - rm "BaseSystem.dmg" "BaseSystem.img" + if [ -n "$(${PWD}/dmg2img -d 2>/dev/null)" ]; then + ${PWD}/dmg2img "BaseSystem.dmg" "BaseSystem.img" + else + dmg2img "BaseSystem.dmg" "BaseSystem.img" + fi + VBoxManage convertfromraw --format VDI "${tmp_path}BaseSystem.img" "${tmp_path}BaseSystem.vdi" + if [ -s BaseSystem.vdi ]; then + rm "BaseSystem.dmg" "BaseSystem.img" 2>/dev/null + fi fi } @@ -186,7 +199,7 @@ elif [ "${storagesize}" -lt 22000 ]; then else echo "Creating ${vmname} target system virtual disk image." VBoxManage createmedium --size="${storagesize}" \ - --filename "${PWD}/${vmname}.vdi" \ + --filename "${tmp_path}${vmname}.vdi" \ --variant standard 2>/dev/tty fi } @@ -198,7 +211,7 @@ if [ -r "Install ${vmname}.vdi" ]; then else echo "Creating ${vmname} installation media virtual disk image." VBoxManage createmedium --size=8000 \ - --filename "${PWD}/Install ${vmname}.vdi" \ + --filename "${tmp_path}Install ${vmname}.vdi" \ --variant fixed 2>/dev/tty fi } @@ -208,11 +221,11 @@ fi function attach_initial_storage() { VBoxManage storagectl "${vmname}" --add sata --name SATA --hostiocache on VBoxManage storageattach "${vmname}" --storagectl SATA --port 0 \ - --type hdd --nonrotational on --medium "${PWD}/${vmname}.vdi" + --type hdd --nonrotational on --medium "${tmp_path}${vmname}.vdi" VBoxManage storageattach "${vmname}" --storagectl SATA --port 1 \ - --type hdd --nonrotational on --medium "${PWD}/Install ${vmname}.vdi" + --type hdd --nonrotational on --medium "${tmp_path}Install ${vmname}.vdi" VBoxManage storageattach "${vmname}" --storagectl SATA --port 2 \ - --type hdd --nonrotational on --medium "${PWD}/BaseSystem.vdi" + --type hdd --nonrotational on --medium "${tmp_path}BaseSystem.vdi" } # Configure the VM @@ -630,8 +643,8 @@ read -n 1 -p " [y/n] " delete 2>/dev/tty echo "" if [ "${delete}" == "y" ]; then # temporary files cleanup - VBoxManage closemedium "BaseSystem.vdi" - VBoxManage closemedium "Install ${vmname}.vdi" + VBoxManage closemedium "${tmp_path}BaseSystem.vdi" + VBoxManage closemedium "${tmp_path}Install ${vmname}.vdi" rm "BaseSystem.vdi" "Install ${vmname}.vdi" fi @@ -663,5 +676,5 @@ if [ -z "${1}" ]; then else check_dependencies initialize_script_functions - ${1} + for argument in $@; do ${argument}; done fi