-
Notifications
You must be signed in to change notification settings - Fork 21
/
bootstrap-clean-build-lab.sh
124 lines (105 loc) · 4.06 KB
/
bootstrap-clean-build-lab.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
set -euxo pipefail
###################################################################
#
# This script will perform a clean build of a machine running 10.13.>=4
#
# The variable BUILD_ID should be provided with, the build ID of the
# version of 10.13 to be used to initiate the build.
#
# The requested build version will be downloaded prior to being used
# for the clean build
#
# Date: @@DATE
# Version: @@VERSION
# Origin: @@ORIGIN
# Released by JSS User: @@USER
#
##################################################################
BUILD_ID="${4}" # Currently 17G65
DOWNLOADER="installinstallmacos.py"
DOWNLOADER_URL="https://raw.githubusercontent.com/UoE-macOS/tools/master/${DOWNLOADER}"
QUICKADD_PKG="/Library/MacSD/QuickAddLab-0.1-1.pkg" # Should have been installed before this script runs
tmpdir=$(mktemp -d /tmp/cleanbuild.XXXX)
function cleanup {
if mount | grep Install_macOS_10.13.6-${BUILD_ID}
then
diskutil unmountdisk /Volumes/Install_macOS_10.13.6-${BUILD_ID}
fi
rm -rf ${tmpdir}
pgrep jamfHelper && killall jamfHelper
echo "Cleaned up"
}
# Cleanup if anything goes wrong. If things go right we are
# going to reboot and wipe the disk, so no need to cleanup :-)
trap cleanup ERR
function os_version_ok {
# Now we can attempt the clean build. Check environment is sensible. We need:
# * 10.13.>4 already installed
# * An AFP formatted system volume
os_version=$(sw_vers -productVersion)
os_minor=$(echo ${os_version} | awk -F '.' '{print $2}')
os_micro=$(echo ${os_version} | awk -F '.' '{print $3}')
[ "${os_minor}" == "13" ] && [[ ${os_micro} -ge 4 ]]
}
function boot_vol_is_apfs {
[ "$(diskutil info / | grep Personality | awk '{print $NF}')" == 'APFS' ]
}
logged_in_user=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser;
import sys;
username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0];
username = [username,""][username in [u"loginwindow", None, u""]];
sys.stdout.write(username);')
if [ "$logged_in_user" != "_mbsetupuser" ]
then
echo "WARNING: This script has only been tested for use while the setupassustant is running"
# exit 1
elif ! os_version_ok
then
echo "OS version is not 10.13 >= 10.13.4"
exit 1
elif ! boot_vol_is_apfs
then
echo "Boot volume is not APFS"
exit 1
elif [ ! -f ${QUICKADD_PKG} ]
then
echo "Quickadd package not available at ${QUICKADD_PKG}"
exit 1
fi
pushd ${tmpdir}
# Kill any existing jamfHelper, and throw up our own
pgrep jamfHelper && killall jamfHelper
/Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper\
-windowType fs\
-title 'UoE Mac Supported Desktop'\
-heading 'Completing system installation.'\
-icon '/System/Library/CoreServices/Installer.app/Contents/Resources/Installer.icns'\
-description 'This machine is rebuilding, please use another computer.' &
# First, download the script that we will use to download 10.13 from Apple's servers
if curl -L "${DOWNLOADER_URL}" > "${DOWNLOADER}"
then
echo "Downloaded installinstallmacos.py"
else
echo "Failed to download installinstallmacos.py from ${DOWNLOADER_URL}"
exit 1
fi
# Now, download the reqested build of 10.13
python ./installinstallmacos.py --build ${BUILD_ID}
# That script leaves use with a disk image containing our installer
hdiutil attach "Install_macOS_10.13.6-${BUILD_ID}.sparseimage"
# If that succeeded we should now have an installer - let's take a look
if [ ! -x "/Volumes/Install_macOS_10.13.6-17G65/Applications/Install macOS High Sierra.app/Contents/Resources/startosinstall" ]
then
echo "Something went wrong - failed to find the installer!"
exit 1
else
# There is a bt of a delay after this returns, before we reboot.
# Hopefully enough for the policy to report success to the JSS.
/Volumes/Install_macOS_10.13.6-17G65/Applications/Install\ macOS\ High\ Sierra.app/Contents/Resources/startosinstall \
--eraseinstall \
--newvolumename "Macintosh HD" \
--agreetolicense \
--nointeraction \
--installpackage ${QUICKADD_PKG}
fi