<commit_before>#!/bin/bash

#**************************************************************************************************
# WebPageTest agent installation script for MacOS systems.

echo "Installing and configuring WebPageTest agent..."
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'}

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

# Pre-prompt for the sudo authorization so it doesn't prompt later
sudo date

#**************************************************************************************************
# 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
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

# Install lighthouse
npm -g install lighthouse

#**************************************************************************************************
# 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

# OS Update
if [ "${WPT_UPDATE_OS,,}" == 'y' ]; then
    echo 'echo "Updating OS"' >> ~/agent.sh
    echo 'sudo softwareupdate --install --recommended --restart' >> ~/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 '    git pull origin release' >> ~/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
echo 'sudo reboot' >> ~/agent.sh
chmod +x ~/agent.sh

#**************************************************************************************************
# Startup Script
#**************************************************************************************************<commit_msg>Fixed shome bash issues<commit_after>#!/bin/bash

#**************************************************************************************************
# WebPageTest agent installation script for MacOS systems.

echo "Installing and configuring WebPageTest agent..."
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'}

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

# Pre-prompt for the sudo authorization so it doesn't prompt later
sudo date

#**************************************************************************************************
# 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
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

# Install lighthouse
npm -g install lighthouse

#**************************************************************************************************
# 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

# OS Update
if [ $WPT_UPDATE_OS == 'y' ]; then
    echo 'echo "Updating OS"' >> ~/agent.sh
    echo 'sudo softwareupdate --install --recommended --restart' >> ~/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 '    git pull origin release' >> ~/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
echo 'sudo reboot' >> ~/agent.sh
chmod +x ~/agent.sh

#**************************************************************************************************
# Startup Script
#**************************************************************************************************
{'fraction_non_alphanumeric': 0.4, 'fraction_numerical': 0.00598669623059867, 'mean_word_length': 5.613636363636363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 65, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1802757', 'n_tokens_mistral': 2678, 'n_tokens_neox': 2450, 'n_words': 675}