exit if running in an elevated shell
This commit is contained in:
+16
-15
@@ -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.55
|
# version 0.56
|
||||||
|
|
||||||
# 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,14 +101,15 @@ if [ -z "$(VBoxManage -v 2>/dev/null)" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Windows Subsystem for Linux (WSL)
|
# Windows Subsystem for Linux (WSL)
|
||||||
wsl_home="" # if the Windows home directory path contains spaces, please assign a rw-able path without spaces
|
windows_home="" # if the Windows home directory path contains spaces, please assign a rw-able path without spaces
|
||||||
if [[ -z "${wsl_home}" && "$(cat /proc/sys/kernel/osrelease 2>/dev/null)" == *"Microsoft"* ]]; then
|
if [[ -z "${windows_home}" && "$(cat /proc/sys/kernel/osrelease 2>/dev/null)" == *"Microsoft"* ]]; then
|
||||||
wsl_home="$(cmd.exe /C cd)"
|
windows_home="$(cmd.exe /C cd)" # returns Windows user's home directory
|
||||||
wsl_home="${wsl_home:0:-1}"'\' # remove trailing newline \M
|
windows_home="${windows_home:0:-1}"'\' # remove trailing newline \M
|
||||||
if [[ ${wsl_home} == *" "* || ${vmname} == *" "* ]]; then
|
if [[ "${windows_home,,}" =~ .*sytem32.* ]]; then echo "Please run this script without elevated privileges."; exit; fi
|
||||||
|
if [[ ${windows_home} == *" "* || ${vmname} == *" "* ]]; then
|
||||||
printf 'VBoxManage behaves unexpectedly when interpreting variables with whitespace
|
printf 'VBoxManage behaves unexpectedly when interpreting variables with whitespace
|
||||||
on Windows Subsystem for Linux. '${whiteonblack}'Please assign values without whitespace'${defaultcolor}' to the
|
on Windows Subsystem for Linux. '${whiteonblack}'Please assign values without whitespace'${defaultcolor}' to the
|
||||||
variables "wsl_home", a Windows-style backslash-terminated path for a readable
|
variables "windows_home", a Windows-style backslash-terminated path for a readable
|
||||||
and writable working directory (for example "C:\\Users\\Default\\"), and "vmname".\n'
|
and writable working directory (for example "C:\\Users\\Default\\"), and "vmname".\n'
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
@@ -207,7 +208,7 @@ else
|
|||||||
else
|
else
|
||||||
dmg2img "BaseSystem.dmg" "BaseSystem.img"
|
dmg2img "BaseSystem.dmg" "BaseSystem.img"
|
||||||
fi
|
fi
|
||||||
VBoxManage convertfromraw --format VDI "${wsl_home}BaseSystem.img" "${wsl_home}BaseSystem.vdi"
|
VBoxManage convertfromraw --format VDI "${windows_home}BaseSystem.img" "${windows_home}BaseSystem.vdi"
|
||||||
if [ -s BaseSystem.vdi ]; then
|
if [ -s BaseSystem.vdi ]; then
|
||||||
rm "BaseSystem.dmg" "BaseSystem.img" 2>/dev/null
|
rm "BaseSystem.dmg" "BaseSystem.img" 2>/dev/null
|
||||||
fi
|
fi
|
||||||
@@ -225,7 +226,7 @@ elif [ "${storagesize}" -lt 22000 ]; then
|
|||||||
else
|
else
|
||||||
echo "Creating ${vmname} target system virtual disk image."
|
echo "Creating ${vmname} target system virtual disk image."
|
||||||
VBoxManage createmedium --size="${storagesize}" \
|
VBoxManage createmedium --size="${storagesize}" \
|
||||||
--filename "${wsl_home}${vmname}.vdi" \
|
--filename "${windows_home}${vmname}.vdi" \
|
||||||
--variant standard 2>/dev/tty
|
--variant standard 2>/dev/tty
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -237,7 +238,7 @@ if [ -w "Install_${vmname}.vdi" ]; then
|
|||||||
else
|
else
|
||||||
echo "Creating ${vmname} installation media virtual disk image."
|
echo "Creating ${vmname} installation media virtual disk image."
|
||||||
VBoxManage createmedium --size=8000 \
|
VBoxManage createmedium --size=8000 \
|
||||||
--filename "${wsl_home}Install_${vmname}.vdi" \
|
--filename "${windows_home}Install_${vmname}.vdi" \
|
||||||
--variant fixed 2>/dev/tty
|
--variant fixed 2>/dev/tty
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -247,11 +248,11 @@ fi
|
|||||||
function attach_initial_storage() {
|
function attach_initial_storage() {
|
||||||
VBoxManage storagectl "${vmname}" --add sata --name SATA --hostiocache on
|
VBoxManage storagectl "${vmname}" --add sata --name SATA --hostiocache on
|
||||||
VBoxManage storageattach "${vmname}" --storagectl SATA --port 0 \
|
VBoxManage storageattach "${vmname}" --storagectl SATA --port 0 \
|
||||||
--type hdd --nonrotational on --medium "${wsl_home}${vmname}.vdi"
|
--type hdd --nonrotational on --medium "${windows_home}${vmname}.vdi"
|
||||||
VBoxManage storageattach "${vmname}" --storagectl SATA --port 1 \
|
VBoxManage storageattach "${vmname}" --storagectl SATA --port 1 \
|
||||||
--type hdd --nonrotational on --medium "${wsl_home}Install_${vmname}.vdi"
|
--type hdd --nonrotational on --medium "${windows_home}Install_${vmname}.vdi"
|
||||||
VBoxManage storageattach "${vmname}" --storagectl SATA --port 2 \
|
VBoxManage storageattach "${vmname}" --storagectl SATA --port 2 \
|
||||||
--type hdd --nonrotational on --medium "${wsl_home}BaseSystem.vdi"
|
--type hdd --nonrotational on --medium "${windows_home}BaseSystem.vdi"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Configure the VM
|
# Configure the VM
|
||||||
@@ -665,8 +666,8 @@ read -n 1 -p " [y/n] " delete 2>/dev/tty
|
|||||||
echo ""
|
echo ""
|
||||||
if [ "${delete}" == "y" ]; then
|
if [ "${delete}" == "y" ]; then
|
||||||
# temporary files cleanup
|
# temporary files cleanup
|
||||||
VBoxManage closemedium "${wsl_home}BaseSystem.vdi"
|
VBoxManage closemedium "${windows_home}BaseSystem.vdi"
|
||||||
VBoxManage closemedium "${wsl_home}Install_${vmname}.vdi"
|
VBoxManage closemedium "${windows_home}Install_${vmname}.vdi"
|
||||||
rm "BaseSystem.vdi" "Install_${vmname}.vdi"
|
rm "BaseSystem.vdi" "Install_${vmname}.vdi"
|
||||||
rm "apple.sucatalog.tmp" "applecatalog.tmp.00" "applecatalog.tmp.01"
|
rm "apple.sucatalog.tmp" "applecatalog.tmp.00" "applecatalog.tmp.01"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user