#File for setting up git-p4 correctly
#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
sudo apt-get update
sudo apt-get -y install helix-cli helix-p4d
sudo /opt/perforce/sbin/configure-helix-p4d.sh -n perforce1 -p ssl:1666 -r /opt/perforce/servers/perforce1 -u super -P REinforce --unicode
sudo chown -R vagrant /home/vagrant/*
export P4CONFIG=.p4config
git clone http://github.com/ermshiperete/git-p4.git
sudo cp git-p4/git-p4 /usr/bin
echo '[alias]
p4 = !//usr/bin/git-p4' > /home/vagrant/.gitconfig
cd /home/vagrant
mkdir git_ws
cd git_ws
echo P4USER=jen > .p4config
echo P4PORT=ssl:1666 >> .p4config
echo P4CLIENT=git_ws >> .p4config
#Add some data to the Helix server for test purposes
mkdir ../ws
cd ../ws
echo P4USER=super > .p4config
echo P4PORT=ssl:1666 >> .p4config
echo P4CLIENT=ws >> .p4config
p4 -u super login < ../hws/passwd
p4 --field "View=//depot/... //ws/..." client -o | p4 client -i
#Create the 'jen' user
p4 configure set security=1
p4 --field User=jen user -o | p4 user -f -i
p4 -u jen passwd -P REinforce
p4 -u jen login < ../hws/passwd
#Add some data to Helix
git clone https://github.com/GNOME/orca.git
cd orca
#Remove Git data, as this causes issues if you then try to clone it
rm -rf .git/
p4 reconcile
p4 submit -d "Adding data to P4D"
cd ../../git_ws
p4 --field "View=//depot/... //git_ws/..." client -o | p4 client -i
git p4 clone //depot/orca ./
sudo chown -R vagrant /home/vagrant/*