#Update package data
sudo apt-get -y update
#Make aptitude be fully non-interactive, so we don't get the issues with Grub trying to
#configure itself.
sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
#Get the public key for Perforce package repo
sudo wget -qO - https://package.perforce.com/perforce.pubkey | sudo apt-key add -
#Update sources list with the Perforce Package repo.
sudo echo "deb http://package.perforce.com/apt/ubuntu xenial release" >> /etc/apt/sources.list
#Install java
sudo apt-get -y install default-jre default-jdk
java -version
#Install Jenkins
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list
sudo apt-get update
sudo apt-get -y install jenkins
sudo systemctl jenkins start
#Install and configure P4D
sudo apt-get -y install helix-p4d helix-cli
sudo /opt/perforce/sbin/configure-helix-p4d.sh -n perforce1 -p ssl:1666 -r /opt/perforce/servers/perforce1 -u super -P REinforce --unicode
#Replace the SSL fingerprint of P4D with a pre-existing one from credentials.xml
#This should not be done in production
p4 trust -f -i 1E:5C:36:91:E0:11:B7:3D:D8:F2:68:DB:9B:41:67:B2:8F:D2:81:9D
#Setup Jenkins
sudo cp hws/config/config.xml /var/lib/jenkins/
sudo mkdir /var/lib/jenkins/users/admin/
sudo cp /home/vagrant/hws/config/users/admin/config.xml /var/lib/jenkins/users/admin/
sudo cp /home/vagrant/hws/config/users/users.xml /var/lib/jenkins/users/
sudo rm -rf /var/lib/jenkins/users/admin_*
sudo cp /home/vagrant/hws/config/credentials.xml /var/lib/jenkins/credentials.xml
sudo cp -r /home/vagrant/hws/config/jobs/ /var/lib/jenkins/
sudo chown -R jenkins:jenkins /var/lib/jenkins/
#Install bcrypt so we can use it to generate hashed passwords
sudo apt-get -y install bcrypt
#Restart Jenkins so our changes in the XML files are picked up.
sudo systemctl restart jenkins
#Setup the Jenkins cli, so we can install the plugins without needing the GUI
sleep 10
wget http://192.168.2.74:8080/jnlpJars/jenkins-cli.jar
java -jar jenkins-cli.jar -s http://localhost:8080/ -auth admin:Test@123 install-plugin p4
#Restart Jenkins
java -jar jenkins-cli.jar -s http://192.168.2.74:8080/ -auth admin:Test@123 restart