-
Notifications
You must be signed in to change notification settings - Fork 28
/
macos.sh
executable file
·175 lines (142 loc) · 6.46 KB
/
macos.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
#**************************************************************************************************
# WebPageTest agent installation script for MacOS systems.
echo "Installing and configuring WebPageTest agent. Please make sure that Xcode is installed before running..."
echo
#**************************************************************************************************
# Configure Defaults
#**************************************************************************************************
set -eu
: ${WPT_SERVER:=''}
: ${WPT_LOCATION:=''}
: ${WPT_KEY:=''}
: ${AGENT_MODE:='desktop'}
: ${WPT_UPDATE_OS:='y'}
: ${WPT_UPDATE_OS_NOW:='y'}
: ${WPT_UPDATE_AGENT:='y'}
# Pre-prompt for the sudo authorization so it doesn't prompt later
echo "May prompt for sudo password..."
sudo date
while [[ $WPT_SERVER == '' ]]
do
read -p "WebPageTest server (i.e. www.webpagetest.org): " WPT_SERVER
done
while [[ $WPT_LOCATION == '' ]]
do
read -p "Location ID (i.e. Dulles): " WPT_LOCATION
done
while [[ $WPT_KEY == '' ]]
do
read -p "Location Key (if required): " WPT_KEY
done
#**************************************************************************************************
# System Update
#**************************************************************************************************
if [ $WPT_UPDATE_OS_NOW == 'y' ]; then
softwareupdate --install --recommended
fi
#**************************************************************************************************
# Agent code
#**************************************************************************************************
cd ~
rm -rf wptagent
until git clone --depth 1 --branch=release https://github.com/WPO-Foundation/wptagent.git
do
sleep 1
done
#**************************************************************************************************
# Software Install
#**************************************************************************************************
# Grant sudo permission without prompting
echo "${USER} ALL=(ALL:ALL) NOPASSWD:ALL" | sudo tee "/etc/sudoers.d/wptagent"
# Install homebrew
CI=1 arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install the cli libraries
arch -x86_64 brew install libvpx ffmpeg imagemagick geckodriver ios-webkit-debug-proxy node git
# Install the python dependencies
pip3 install PyObjC ujson dnspython monotonic pillow psutil requests tornado wsaccel brotli fonttools selenium future usbmuxwrapper pytz tzlocal
# Install lighthouse
npm -g install lighthouse
#**************************************************************************************************
# Install Browsers
#**************************************************************************************************
echo "Installing Browsers..."
cd ~
git clone https://github.com/WPO-Foundation/browser-install.git
python3 ~/browser-install/browser_install_macos.py
#**************************************************************************************************
# Agent Script
#**************************************************************************************************
# build the agent script
KEY_OPTION=''
if [ $WPT_KEY != '' ]; then
KEY_OPTION="--key $WPT_KEY"
fi
echo '#!/bin/zsh' > ~/agent.sh
echo "cd $HOME" >> ~/agent.sh
# Wait for networking to become available and update the package list
echo 'sleep 10' >> ~/agent.sh
# Update the browsers
echo "cd $HOME/browser-install" >> ~/agent.sh
echo "git pull origin master" >> ~/agent.sh
echo "python3 browser_install_macos.py" >> ~/agent.sh
echo "cd $HOME" >> ~/agent.sh
# Lighthouse Update
if [ $WPT_UPDATE_AGENT == 'y' ]; then
echo 'sudo npm i -g lighthouse' >> ~/agent.sh
fi
echo 'for i in `seq 1 24`' >> ~/agent.sh
echo 'do' >> ~/agent.sh
if [ $WPT_UPDATE_AGENT == 'y' ]; then
echo " cd $HOME/wptagent" >> ~/agent.sh
echo ' git pull origin release' >> ~/agent.sh
echo " cd $HOME" >> ~/agent.sh
fi
# Agent invocation (depending on config)
if [ $AGENT_MODE == 'android' ]; then
echo " python3 $HOME/wptagent/wptagent.py -vvvv --location $WPT_LOCATION $KEY_OPTION --server \"http://$WPT_SERVER/work/\" --android --exit 60 --alive /tmp/wptagent" >> ~/agent.sh
fi
if [ $AGENT_MODE == 'ios' ]; then
echo " python3 $HOME/wptagent/wptagent.py -vvvv --location $WPT_LOCATION $KEY_OPTION --server \"http://$WPT_SERVER/work/\" --iOS --exit 60 --alive /tmp/wptagent" >> ~/agent.sh
fi
if [ $AGENT_MODE == 'desktop' ]; then
echo " python3 $HOME/wptagent/wptagent.py -vvvv --location $WPT_LOCATION $KEY_OPTION --server \"http://$WPT_SERVER/work/\" --exit 60 --alive /tmp/wptagent" >> ~/agent.sh
fi
echo ' echo "Exited, restarting"' >> ~/agent.sh
echo ' sleep 10' >> ~/agent.sh
echo 'done' >> ~/agent.sh
# OS Update
#if [ $WPT_UPDATE_OS == 'y' ]; then
# echo 'echo "Updating OS"' >> ~/agent.sh
# echo 'sudo softwareupdate --install --recommended --restart' >> ~/agent.sh
#fi
echo 'sudo reboot' >> ~/agent.sh
chmod +x ~/agent.sh
#**************************************************************************************************
# Startup and watchdog scripts
#**************************************************************************************************
cd ~
git clone https://github.com/WPO-Foundation/wptagent-install.git
#**************************************************************************************************
# Permission prompts
#**************************************************************************************************
echo "The install script is now going to trigger the permissions prompts for the various permissions needed by the agent."
echo "This includes Automation permissions for the scripts to move the simulator window and screen capture permissions to capture video."
echo
echo "****** Press enter to continue ******"
read
echo "Triggering permissions prompts."
echo "you will likely need to grant the permissions under 'Screen Capture' and 'Accessibility' under privacy manually."
python3 ~/wptagent/scripts/macos_prompts.py
touch /tmp/wptagent
open ~/wptagent-install/macos/Watchdog.app
sleep 10
open ~/wptagent-install/macos/Agent.app
sleep 10
killall Python || true
#**************************************************************************************************
# Done
#**************************************************************************************************
echo "Please configure ~/wptagent-install/macos/Agent.app and Watchdog.app to start automatically as login items."
echo "This is done in System Preferences->Users and Groups->Login Items."
echo "Then reboot"