Skip to content

Commit 8d397a4

Browse files
committed
macos13: initial pre-automation setup script (#3)
1 parent 314b01d commit 8d397a4

File tree

5 files changed

+167
-0
lines changed

5 files changed

+167
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ To build the base vm, first build a clean image:
178178
- Quit the **Keyboard Setup Assistant**
179179
- Once installed, shut down the guest: `virsh shutdown servo-macos13.clean`
180180
- Take another snapshot: `zfs snapshot tank/base/servo-macos13.clean@oobe`
181+
- Start the base guest: `virsh start servo-macos13.clean`
182+
- Log in with the password above
183+
- Press **Cmd**+**Space**, type `full disk access`, press **Enter**
184+
- Click the plus, type the password above, select **Applications** > **Utilities** > **Terminal**
185+
- Press **Cmd**+**Space**, type `terminal`, press **Enter**
186+
- Type `curl https://ci0.servo.org/static/macos13.sh | sudo sh` and press **Enter**
187+
- Shut down the guest: `virsh shutdown servo-macos13.clean`
188+
- Take another snapshot: `zfs snapshot tank/base/servo-macos13.clean@automated`
181189

182190
Baking new images after deployment
183191
----------------------------------

server/nixos/configuration.nix

+3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@
140140
locations."/" = proxy // {
141141
proxyPass = "http://[::1]:8000";
142142
};
143+
locations."/static/" = {
144+
root = "/config";
145+
};
143146
} // ssl;
144147
"intermittent-tracker.servo.org" = {
145148
locations."/" = proxy // {

static/macos13.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
# Enable SSH
5+
systemsetup -setremotelogin on
6+
7+
# Enable automatic login
8+
curl -fsSO https://ci0.servo.org/static/macos13/setAutoLogin.sh
9+
chmod +x setAutoLogin.sh
10+
./setAutoLogin.sh servo 'servo2024!'
11+
12+
# Allow servo to elevate to root without password
13+
echo 'servo ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/servo
14+
15+
# Install a LaunchAgent to run our code on boot
16+
# <https://superuser.com/a/229792>
17+
curl -fsSO https://ci0.servo.org/static/macos13/org.servo.ci.plist
18+
mv -v org.servo.ci.plist /Library/LaunchAgents

static/macos13/org.servo.ci.plist

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>Label</key>
6+
<string>org.servo.ci</string>
7+
8+
<key>OnDemand</key>
9+
<false/>
10+
11+
<key>UserName</key>
12+
<string>root</string>
13+
14+
<key>GroupName</key>
15+
<string>wheel</string>
16+
17+
<key>ProgramArguments</key>
18+
<array>
19+
<string>open</string>
20+
<string>-Wa</string><!-- wait, application -->
21+
<string>/System/Applications/Utilities/Terminal.app</string>
22+
<string>/Volumes/a/init/boot.sh</string>
23+
</array>
24+
</dict>
25+
</plist>

static/macos13/setAutoLogin.sh

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
: <<-LICENSE_BLOCK
3+
setAutoLogin (20220731) - Copyright (c) 2021 Joel Bruner (https://github.com/brunerd)
4+
Licensed under the MIT License
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
LICENSE_BLOCK
10+
11+
#############
12+
# VARIABLES #
13+
#############
14+
15+
USERNAME="${1}"
16+
17+
#this can be blank if that is the password
18+
PW="${2}"
19+
20+
#############
21+
# FUNCTIONS #
22+
#############
23+
24+
#given a string creates data for /etc/kcpassword
25+
function kcpasswordEncode () (
26+
27+
#ascii string
28+
thisString="${1}"
29+
30+
#macOS cipher hex ascii representation array
31+
cipherHex_array=( 7D 89 52 23 D2 BC DD EA A3 B9 1F )
32+
33+
#converted to hex representation with spaces
34+
thisStringHex_array=( $(/bin/echo -n "${thisString}" | xxd -p -u | sed 's/../& /g') )
35+
36+
#get padding by subtraction if under 12
37+
if [ "${#thisStringHex_array[@]}" -lt 12 ]; then
38+
padding=$(( 12 - ${#thisStringHex_array[@]} ))
39+
#get padding by subtracting remainder of modulo 12 if over 12
40+
elif [ "$(( ${#thisStringHex_array[@]} % 12 ))" -ne 0 ]; then
41+
padding=$(( (12 - ${#thisStringHex_array[@]} % 12) ))
42+
#otherwise even multiples of 12 still need 12 padding
43+
else
44+
padding=12
45+
fi
46+
47+
#cycle through each element of the array + padding
48+
for ((i=0; i < $(( ${#thisStringHex_array[@]} + ${padding})); i++)); do
49+
#use modulus to loop through the cipher array elements
50+
charHex_cipher=${cipherHex_array[$(( $i % 11 ))]}
51+
52+
#get the current hex representation element
53+
charHex=${thisStringHex_array[$i]}
54+
55+
#use $(( shell Aritmethic )) to ^ XOR the two 0x## values (extra padding is 0x00)
56+
#take decimal value and printf convert to two char hex value
57+
#use xxd to convert hex to actual value and send to stdout (to avoid NULL issue in bash strings)
58+
printf "%02X" "$(( 0x${charHex_cipher} ^ 0x${charHex:-00} ))" | xxd -r -p > /dev/stdout
59+
done
60+
)
61+
62+
########
63+
# MAIN #
64+
########
65+
66+
#quit if not root
67+
if [ "${UID}" != 0 ]; then
68+
echo "Please run as root, exiting."
69+
exit 1
70+
fi
71+
72+
#special case for Guest account (case SENSITIVE)
73+
if [ "${USERNAME}" = "Guest" ]; then
74+
#turn on Guest account
75+
sysadminctl -guestAccount on
76+
#set auto-login
77+
defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser Guest
78+
79+
echo "Auto login enabled for Guest"
80+
#if we have any other USERNAME
81+
elif [ -n "${USERNAME}" ]; then
82+
83+
#check if user exists
84+
if ! id "${USERNAME}" &> /dev/null; then
85+
echo "User '${USERNAME}' not found, exiting."
86+
exit 1
87+
fi
88+
89+
#check that the supplied password is valid
90+
if ! /usr/bin/dscl /Search -authonly "${USERNAME}" "${PW}" &> /dev/null; then
91+
echo "Invalid password for '${USERNAME}', exiting."
92+
exit 1
93+
fi
94+
95+
#encode password and write file
96+
kcpasswordEncode "${PW}" > /etc/kcpassword
97+
98+
#ensure ownership and permissions are correct (600)
99+
chown root:wheel /etc/kcpassword
100+
chmod u=rw,go= /etc/kcpassword
101+
102+
#turn on auto login for the user
103+
/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser -string "${USERNAME}"
104+
echo "Auto login enabled for '${USERNAME}'"
105+
106+
#if no USERNAME, turn auto-login OFF
107+
else
108+
[ -f /etc/kcpassword ] && rm -f /etc/kcpassword
109+
/usr/bin/defaults delete /Library/Preferences/com.apple.loginwindow autoLoginUser &> /dev/null
110+
echo "Auto login disabled"
111+
fi
112+
113+
exit 0

0 commit comments

Comments
 (0)