-
Notifications
You must be signed in to change notification settings - Fork 2
/
prepare.bash
executable file
·116 lines (101 loc) · 4.86 KB
/
prepare.bash
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
#!/bin/bash
set -exo pipefail
unset HISTFILE
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $SCRIPT_DIR
. ./_helpers.bash
GETTING_STARTED_LOCATION="$HOME/getting-started"
# POPULATE .zshrc
[[ -z "$(grep "alias ll" $HOME/.zshrc)" ]] && echo "" >> $HOME/.zshrc && echo "alias ll=\"ls -laht\"" >> $HOME/.zshrc
source ~/.zshrc || true
# Ensure the query tool exists ; AWS has deprecated it
# [[ ! -e "/usr/local/bin/ec2-metadata" ]] && curl http://s3.amazonaws.com/ec2metadata/ec2-metadata -o /usr/local/bin/ec2-metadata && chmod +x /usr/local/bin/ec2-metadata
[[ -f "./${AMI_MACOS_TARGET_VERSION}.bash" ]] && ./"${AMI_MACOS_TARGET_VERSION}".bash
# Install resize disk plist
[[ ! -e "${RESIZE_DISK_PLIST_PATH}" ]] && sudo -E bash -c "pwd; ./resize-disk.bash"
# Install Anka
brew install jq # used for cloud-connect api parsing
pushd "${HOME}"
rm -rf getting-started
git clone https://github.com/veertuinc/getting-started.git
cd getting-started
ANKA_LICENSE=${ANKA_LICENSE:-""}
[[ -n "${ANKA_TARGET_VERSION}" ]] && export ANKA_VIRTUALIZATION_PACKAGE="Anka-${ANKA_TARGET_VERSION}.pkg"
./install-anka-virtualization-on-mac.bash
popd
# Disable indexing volumes
sudo defaults write ~/.Spotlight-V100/VolumeConfiguration.plist Exclusions -array "/Volumes" || true
sudo defaults write ~/.Spotlight-V100/VolumeConfiguration.plist Exclusions -array "/Network" || true
sudo killall mds || true
sleep 60
sudo mdutil -a -i off / || true
sudo mdutil -a -i off || true
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist || true
sudo rm -rf /.Spotlight-V100/*
rm -rf ~/Library/Metadata/CoreSpotlight/ || true
killall -KILL Spotlight spotlightd mds || true
sudo rm -rf /System/Volums/Data/.Spotlight-V100 || true
# Enable VNC
## Disabled as it now throws a warning and doesn't work.
## Screen recording might be disabled. Screen Sharing or Remote Management must be enabled from System Preferences or via MDM.
## Screen control might be disabled. Screen Sharing or Remote Management must be enabled from System Preferences or via MDM.
# sudo defaults write /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing -dict Disabled -bool false
# sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist
# old legacy ----
# pushd /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/
# sudo ./kickstart -configure -allowAccessFor -specifiedUsers
# sudo ./kickstart -configure -allowAccessFor -allUsers -privs -all
# sudo ./kickstart -activate
# popd
# Sleep settings ; MAY BE USELESS AS AMIS DON'T SAVE NVRAM SETTINGS
sudo systemsetup -setsleep Never
sudo systemsetup -setcomputersleep Off
systemsetup -setcomputersleep Off || true
sudo pmset -a standby 0
sudo pmset -a disksleep 0
sudo pmset -a hibernatemode 0
defaults write com.apple.screensaver idleTime 0
# Required to create necessary folders | No such file or directory: '/var/root/Library/Application Support/Veertu/Anka/img_lib/' from agent
anka create test && anka delete --yes test
sudo anka create test && sudo anka delete --yes test
# SSH will break with Broken pipe when doing anka create
sudo cat << EOF | sudo tee /etc/ssh/sshd_config.d/051-anka.conf
ClientAliveInterval 900
ClientAliveCountMax 220
EOF
# syslog spam com.apple.xpc.launchd[1] (com.apple.wifi.WiFiAgent): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.
launchctl unload -w /System/Library/LaunchAgents/com.apple.wifi.WiFiAgent.plist || true
# Performance related changes / DISABLED AS OF 2.5.5 due to it freezing anka create
# anka config block_nocache 0
# sudo anka config block_nocache 0
# Disable sleep and screensaver so we don't need to disable "Require password after sleep or screensaver begins"
if ! grep -q DisableScreenSaver /usr/local/aws/ec2-macos-init/init.toml; then
sudo cat << EOF | sudo tee -a /usr/local/aws/ec2-macos-init/init.toml
[[Module]]
Name = "DisableScreenSaver"
PriorityGroup = 4
RunPerBoot = true # Run every boot
FatalOnError = false # Best effort, don't fatal on error
[Module.Command]
Cmd = ["/bin/zsh", "-c", 'defaults write com.apple.screensaver idleTime 0']
EOF
fi
if ! grep -q DisableSleep /usr/local/aws/ec2-macos-init/init.toml; then
sudo cat << EOF | sudo tee -a /usr/local/aws/ec2-macos-init/init.toml
[[Module]]
Name = "DisableSleep"
PriorityGroup = 4
RunPerBoot = true # Run every boot
FatalOnError = false # Best effort, don't fatal on error
[Module.Command]
Cmd = ["/bin/zsh", "-c", 'sudo systemsetup -setsleep Never']
EOF
fi
unset HISTFILE
# Create plist for cloud connect # Should be last!
[[ ! -e $CLOUD_CONNECT_PLIST_PATH ]] && sudo -E bash -c "./cloud-connect.bash"
sudo chown -R $AWS_INSTANCE_USER:staff ~/aws-ec2-mac-amis
# error: cannot open '.git/FETCH_HEAD': Permission denied
sudo chown -R $AWS_INSTANCE_USER:staff ~/aws-ec2-mac-amis/.git/*
echo "done" > ~/prep
unset HISTFILE