#!/bin/zsh
if which git > /dev/null 2>/dev/null;then
sleep .01
else
echo Please install the git package, which is required to download brigadier, which downloads and extracts BootCamp drivers from Apple Servers. If this package is already installed, the command \"git\" should be located somewhere in the following directories: $PATH". "
export missingreqs=$missingreqs" git "
fi
if which 7z > /dev/null 2>/dev/null;then
sleep .01
else
echo Please install the p7zip package, which is used to extract the bootcamp dmg from the xar payload. If this package is already installed, the command \"7z\" should be located somewhere in the following directories: $PATH". "
export missingreqs=$missingreqs" 7z "
fi
if which dmg2img > /dev/null 2>/dev/null;then
sleep .01
else
echo Please install the dmg2img package, which is used to convert the bootcamp dmg into an image which can be extracted without root. If this package is already installed, the command \"dmg2img\" should be located somewhere in the following directories: $PATH". "
export missingreqs=$missingreqs" dmg2img "
fi
if which python2 > /dev/null 2>/dev/null;then
sleep .01
else
echo Please install the python2 package, which is used to run the brigadier program, which will be used to download apple drivers. If this package is already installed, the command \"python2\" should be located somewhere in the following directories: $PATH". "
export missingreqs=$missingreqs" python2 "
fi
if python2 -c "import requests"> /dev/null 2>/dev/null;then
sleep .01
else
echo Please install the python2-requests package, which is used to run the brigadier program, which will be used to download apple drivers. If this package is already installed, the command \"python2 -c \"import requests\"\" should return no output and exit with a 0 return status". "
export missingreqs=$missingreqs" python2-requests "
fi
if [ -z $missingreqs ];then
sleep .01
else
echo sorry, some requirements to run this script are missing. Please check the above output, install the missing requirements, and run the command again.
exit 2
fi
if [ -e WindowsSupport.img ];then
sleep .01
else
export model=$1
if [ -z $model ];then
echo please enter your mac model ID, such as MacBookAir7,2
read model
fi
git clone https://github.com/timsutton/brigadier
cd brigadier
mkdir drivers
python2 brigadier -m $model -o drivers
cd drivers
export payloadpath=`find /tmp 2>/dev/null|grep -i bootcamp|grep -i payload\~|tail -n 1`
if file $payloadpath|grep -iw cpio;then
cat $payloadpath|cpio -i
else
7z x $payloadpath
fi
dmg2img Library/Application\ Support/BootCamp/WindowsSupport.dmg ../../WindowsSupport.img
cd ../..
rm -rf brigadier /tmp/bootcamp*
fi
mkdir tmp
cd tmp
7z -y x ../WindowsSupport.img
mkdir -p drivers
cd BootCamp/Drivers
IFS=$(echo -en \\n\\b)
for f in `find .|grep -i .exe`;do
if file $f|grep -q RAR;then
export name=`echo $f|cut -f 3 -d /|cut -f 1 -d .`
mkdir ../../drivers/$name
cp $f ../../drivers/$name
cd ../../drivers/$name
7z -y x $name".exe"
rm *License* DPInst* $name".exe"
cd $OLDPWD
fi
done
for f in `find .|grep -i .inf|cut -f 2 -d /|sort|uniq`;do
cp -rf $f ../../drivers
done
cp -rf ../../\$WinPEDriver\$/* ../../drivers
cd ../../..
mv tmp/drivers .
rm -rf tmp
