Created
January 18, 2019 22:19
-
-
Save DiegoMagdaleno/1ce8d88f7b84597ce625bb8c80e59318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BOOT_MACOS_SH="boot-macOS.sh" | |
ENOCH_REV2839_BOOT="enoch_rev2839_boot" | |
BOOT_MACOS_SCRIPT="https://raw.githubusercontent.com/kholia/OSX-KVM/master/${BOOT_MACOS_SH}" | |
ENOCH_REV2839_BOOT_KERNEL="https://raw.githubusercontent.com/kholia/OSX-KVM/master/${ENOCH_REV2839_BOOT}" | |
IMAGE_HDD_NAME="${1}.img" | |
IMAGE_HDD_SIZE=$2 | |
ISO="$(pwd)/$3" | |
INSTALL_DIR=$4 | |
DL_BOOT_MACOS_RC="wget $BOOT_MACOS_SCRIPT" | |
DL_ENOCH_REV2839_BOOT_RC="wget $ENOCH_REV2839_BOOT_KERNEL" | |
PERM_RC="sudo sh boot-macOS.sh" | |
RAM_MB="4096" | |
echo | |
echo " ** THANKS TO ** " | |
echo " -> Dhiru Kholia : the man who did the hard work for us, not me" | |
echo " -> GitHub profile : https://github.com/kholia" | |
echo " -> Original OSX-KVM repository: https://github.com/kholia/OSX-KVM, be sure to star this!" | |
echo | |
if [[ $# < 4 ]]; then | |
echo "Usage: <$0> [target HDD name] [target HDD size(including unit: M,G,K,..)] [ISO file] [Install directory] (dedicated RAM memory) [in Megabytes]" | |
exit 1 | |
fi | |
if [[ $# == 5 ]] || [[ $# > 5 ]]; then | |
RAM_MB=$5 | |
echo "Dedicated RAM size: ${RAM_MB}MB" | |
fi | |
if [ ! -f $ISO ]; then | |
echo "Cannot find your iso file named: $ISO ... Aborting" | |
exit 5 | |
fi | |
if [ ! -d $INSTALL_DIR ]; then | |
echo "Creating $INSTALL_DIR for you..." | |
mkdir -p $INSTALL_DIR || exit 1 && echo "Done" | |
fi | |
if ! which wget 2>/dev/null >>/dev/null; then | |
echo "wget not found, trying curl..." | |
if ! which curl 2>/dev/null >>/dev/null; then | |
echo "Cannot find curl... Aborting" | |
exit 1 | |
else | |
DL_BOOT_MACOS_RC="curl -O $BOOT_MACOS_SCRIPT" | |
DL_ENOCH_REV2839_BOOT_RC="curl -O $ENOCH_REV2839_BOOT_SCRIPT" | |
fi | |
fi | |
if ! which sudo 2>/dev/null >>/dev/null; then | |
echo "Using su as privilege escalation method" | |
PERM_RC="su -c \"sh boot-macOS.sh\"" | |
fi | |
if ! which qemu-system-x86_64 2>/dev/null >>/dev/null; then | |
echo "Cannot find QEMU (x86_64)... Aborting" | |
exit 2 | |
fi | |
if ! which qemu-img 2>/dev/null >>/dev/null; then | |
echo "Cannot find QEMU IMG (needed to create image)... Aborting" | |
exit 3 | |
fi | |
echo "Changing directory to: $INSTALL_DIR" | |
cd $INSTALL_DIR || exit 1 | |
if [ -f $IMAGE_HDD_NAME ]; then | |
echo -n "$IMAGE_HDD_NAME already exists, continue[y/N] ? " | |
read CONTINUE | |
if [[ $CONTINUE == "y" ]] || [[ $CONTINUE == "Y" ]]; then | |
echo "Keep going..." | |
elif [[ $CONTINUE == "n" ]] || [[ $CONTINUE == "N" ]]; then | |
echo "Good choice..." | |
exit 1 | |
fi | |
fi | |
qemu-img create -f qcow2 $IMAGE_HDD_NAME $IMAGE_HDD_SIZE | |
if [ -f $BOOT_MACOS_SH ]; then | |
echo "$BOOT_MACOS_SH already exists" | |
else | |
echo "Getting boot-macOS.sh..." | |
$DL_BOOT_MACOS_RC >>/dev/null || exit 1 | |
sed -i "s:./mac_hdd.img:$IMAGE_HDD_NAME:" boot-macOS.sh | |
sed -i "s:./'Install_macOS_Sierra_(OS_X_10.12).iso':${ISO}:" boot-macOS.sh | |
sed -i "s:-m 8192:-m $RAM_MB:" boot-macOS.sh | |
fi | |
if [ -f $ENOCH_REV2839_BOOT ]; then | |
echo "$ENOCH_REV2839_BOOT already exists" | |
else | |
echo "Getting enoch_rev2839_boot..." | |
$DL_ENOCH_REV2839_BOOT_RC >>/dev/null || exit 1 | |
fi | |
echo "(Waiting 3 secs) Launching QEMU... Starting OSX ($ISO) installation..." | |
sleep 3 | |
echo "Here we go" | |
$PERM_RC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment