echo "Installing GitLab CE"
sudo apt-get -y install aptitude
sudo aptitude update
sudo aptitude -y upgrade
#Install the dependencies
sudo aptitude -y install curl openssh-server ca-certificates sendmail
#Install GitLab CE
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo aptitude -y install gitlab-ce
#Replace default 'gitlab.rb' file with ours.
sudo cp /home/vagrant/hws/gitlab.rb /etc/gitlab/
sudo gitlab-ctl reconfigure
#Generate the self-signed certs, so https will work
sudo aptitude -y install openssl
sudo mkdir -p /etc/gitlab/ssl/
openssl req -x509 -subj '/C=US/ST=CA/L=Alameda/O=Perforce/OU=GCONN/CN=GCONN/E=gconn@perforce.com' -nodes -days 365 -newkey rsa:2048 -keyout /etc/gitlab/ssl/192.168.2.71.key -out /etc/gitlab/ssl/172.16.100.12.crt > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo 'Errors while creating self-signed certificates!'
exit 1
else
echo 'Self-signed certificates have been created'
fi
mkdir -p /etc/gitlab/trusted-certs
sudo cp /etc/gitlab/ssl/192.168.2.71.crt /etc/gitlab/trusted-certs/
#Reconfigure gitlab
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
sudo ufw allow https
echo "Now log in to GitLab, create the 'testrepo' project, then go to 'https://192.168.2.71/root/testrepo/settings/integrations' to setup the web hook"