2020-10-23 17:59:08 +03:00
#!/bin/bash -e -o pipefail
2023-11-28 02:25:03 +01:00
################################################################################
## File: configure-machine.sh
## Desc: Configure guest OS settings
################################################################################
2020-09-10 14:34:08 +03:00
2021-05-05 18:23:21 +03:00
source ~/utils/utils.sh
2020-10-31 18:41:04 +03:00
echo "Enabling developer mode..."
sudo /usr/sbin/DevToolsSecurity --enable
2020-09-10 14:34:08 +03:00
# Turn off hibernation and get rid of the sleepimage
sudo pmset hibernatemode 0
sudo rm -f /var/vm/sleepimage
2021-07-21 14:11:34 +03:00
# Disable App Nap System Wide
defaults write NSGlobalDomain NSAppSleepDisabled -bool YES
2022-02-11 19:23:37 +03:00
# Disable Keyboard Setup Assistant window
2022-02-25 10:55:47 +03:00
if is_Veertu; then
2022-02-11 19:23:37 +03:00
sudo defaults write /Library/Preferences/com.apple.keyboardtype "keyboardtype" -dict-add "3-7582-0" -int 40
fi
2020-09-10 14:34:08 +03:00
# Change screen resolution to the maximum supported for 4Mb video memory
2024-01-09 14:47:31 +01:00
if [[ -d "/Library/Application Support/VMware Tools" ]] ; then
2021-09-27 09:03:26 +00:00
sudo "/Library/Application Support/VMware Tools/vmware-resolutionSet" 1176 885
fi
2020-09-21 10:53:56 +03:00
2022-01-11 10:40:14 +00:00
# Update VoiceOver Utility to allow VoiceOver to be controlled with AppleScript
# by creating a special Accessibility DB file (SIP must be disabled) and
# updating the user defaults system to reflect this change.
2021-12-27 18:17:25 +03:00
if csrutil status | grep -Eq "System Integrity Protection status: (disabled|unknown)" ; then
sudo bash -c 'echo -n "a" > /private/var/db/Accessibility/.VoiceOverAppleScriptEnabled'
fi
2022-01-11 10:40:14 +00:00
defaults write com.apple.VoiceOver4/default SCREnableAppleScript -bool YES
2021-12-27 18:17:25 +03:00
2020-09-21 10:53:56 +03:00
# https://developer.apple.com/support/expiration/
# Enterprise iOS Distribution Certificates generated between February 7 and September 1st, 2020 will expire on February 7, 2023.
# Rotate the certificate before expiration to ensure your apps are installed and signed with an active certificate.
# Confirm that the correct intermediate certificate is installed by verifying the expiration date is set to 2030.
# sudo security delete-certificate -Z FF6797793A3CD798DC5B2ABEF56F73EDC9F83A64 /Library/Keychains/System.keychain
2021-05-05 18:23:21 +03:00
# Big Sur requires user interaction to add a cert https://developer.apple.com/forums/thread/671582, we need to use a workaround with SecItemAdd swift method
2023-02-13 16:40:48 +01:00
2023-08-09 12:09:34 +02:00
swiftc -suppress-warnings " ${ HOME } /image-generation/add-certificate.swift"
2023-02-13 16:40:48 +01:00
2022-02-09 10:34:31 +03:00
certs =(
AppleWWDRCAG3.cer
DeveloperIDG2CA.cer
)
for cert in ${ certs [@] } ; do
echo "Adding ${ cert } certificate"
cert_path = " ${ HOME } / ${ cert } "
2023-08-01 15:42:44 +02:00
curl -fsSL "https://www.apple.com/certificateauthority/ ${ cert } " --output ${ cert_path }
2023-02-13 16:40:48 +01:00
sudo ./add-certificate ${ cert_path }
2022-02-09 10:34:31 +03:00
rm ${ cert_path }
done
rm -f ./add-certificate
2021-01-22 09:26:28 +03:00
2022-04-20 17:25:58 +02:00
# enable-automationmode-without-authentication
2023-05-24 15:34:44 +02:00
if ! is_BigSur; then
2022-04-20 17:25:58 +02:00
retry = 10
2024-01-09 14:47:31 +01:00
while [[ $retry -gt 0 ]] ; do
2022-04-20 17:25:58 +02:00
{
osascript <<EOF
tell application "Terminal"
activate
do script "automationmodetool enable-automationmode-without-authentication"
delay 2
tell application "System Events"
keystroke "${PASSWORD}"
keystroke return
end tell
end tell
delay 5
EOF
} && break
retry = $(( retry-1))
2024-01-09 14:47:31 +01:00
if [[ $retry -eq 0 ]] ; then
2022-04-20 17:25:58 +02:00
echo "No retry attempts left"
exit 1
fi
sleep 10
done
2022-06-22 07:46:22 +02:00
echo "Getting terminal windows"
2022-04-20 17:25:58 +02:00
term_service = $( launchctl list | grep -i terminal | cut -f3)
echo "Close terminal windows: gui/501/ ${ term_service } "
launchctl bootout gui/501/${ term_service } && sleep 5
# test enable-automationmode-without-authentication
if [[ ! " $( automationmodetool) " = ~ "DOES NOT REQUIRE" ]] ; then
echo "Failed to enable enable-automationmode-without-authentication option"
exit 1
fi
fi
2021-01-22 09:26:28 +03:00
# Create symlink for tests running
2024-01-09 14:47:31 +01:00
if [[ ! -d "/usr/local/bin" ]] ; then
2021-01-22 09:26:28 +03:00
sudo mkdir -p -m 775 /usr/local/bin
sudo chown $USER :admin /usr/local/bin
fi
chmod +x $HOME /utils/invoke-tests.sh
sudo ln -s $HOME /utils/invoke-tests.sh /usr/local/bin/invoke_tests