#!/bin/bash
#
# Other fun things here which pre-determine this device needs to install 10.11.x
# If this machine doesn't the script will have exited by now.
#
dmgsha256=""
dmgcachefile="/Library/Managed Installs/Cache/file.dmg"
dmgmsuloc=""
speedtestloc=""
# We should probably check free disk space first, before trying to ram in 6GB.
diskutilfreediskline="$(diskutil info / | grep "Free Space")"
if [[ "$(echo "$diskutilfreediskline" |awk '{print $5}')" == "GB" ]] && [[ "$(echo "$diskutilfreediskline" |awk '{print $4}')" -gt "10" ]]; then
#echo "/ looks like it has at least 10GB of free space."
#echo "TODO: Take care of TB measurement?"
if [[ "$(shasum -a 256 "$dmgcachefile" |awk '{print $1}')" != "$dmgsha256" ]]; then
#echo "SHA256 doesnt match, so file is wrong in some way - size; corrupt; doesnt exist etc."
#echo "Lets run a speed test, as user could be outside of the client office, and 6GB could take awhile."
curlspeedtest="$(curl -w '%{speed_download}\n' -o /dev/null -s "$speedtestloc")"
curlspeedtest_bps="$(echo $curlspeedtest | awk '{print $1}' | sed 's/\..*//')"
if [[ "$(($curlspeedtest_bps / 125000))" -gt "100" ]]; then
#echo "$curlspeedtest_bps looks over 100Mbits. Fast enough to reasonably download 6GB."
curl -C - -o "$dmgcachefile" "$dmgmsuloc"
chown
chmod
#echo "Looks like we've pre-loaded the .dmg, exit telling MSC it can install."
#echo "TODO: Cater for loss of process; internet connections and cURL timeouts, needing us to loop - or give up."
exit 1
fi
fi
fi