Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
# Update Gitlab CE 8.5 to CE 8.13.3 on Karoshi-Server.
# More info at: http://www.linuxschools.com/forum/viewtopic.php?f=6&t=622
# TODO:
# - Format echo statements in HTML5 style
# - Change the backup directory to the correct place
# 05/11/2016 (DD/MM/YYYY)
SERVERNAME=$(hostname -f)
if [ -f "/opt/karoshi/server_network/servers/${SERVERNAME}/gitlab" ]; then
source /opt/karoshi/serversetup/variables/distro
echo "Updating Gitlab CE 8.5 (trusty) to Gitlab CE 8.13.3-ce.0 (xenial)"
echo "Stopping Gitlab."
/opt/karoshi/serversetup/distro/$DISTROCHOICE/scripts/control_services/gitlab_stop
echo "Backing up /etc/gitlab (config and secrets)"
#TODO: Suitable backup dir
[ -d "/home/gitlab_backup" ] || mkdir -p "/home/gitlab_backup"
[ -d "/home/gitlab_backup/etc/gitlab" ] || mkdir -p "/home/gitlab_backup/etc/gitlab"
[ -d "/home/gitlab_backup/home/gitlab" ] || mkdir -p "/home/gitlab_backup/home/gitlab"
cp -r /etc/gitlab /home/gitlab_backup/etc/gitlab #TODO: Suitable backup dir
echo "Backing up /home/gitlab (user repos and data)"
cp -r /home/gitlab /home/gitlab_backup/home/gitlab #TODO: Suitable backup dir
echo "Removing existing Gitlab installation."
rm -rf /opt/gitlab
# Download Gitlab
# MD5sum: 8614aa27c0ff83ac209538a5bb762412
[ -d "/opt/karoshi/.tempdata/gitlab_temp" ] && rm -r "/opt/karoshi/.tempdata/gitlab_temp"
mkdir /opt/karoshi/.tempdata/gitlab_temp
WGET_URL="https://packages.gitlab.com/gitlab/gitlab-ce/packages/ubuntu/xenial/gitlab-ce_8.13.3-ce.0_amd64.deb/download"
[ ! -f /opt/karoshi/serversetup/modules/gitlab/gitlab.deb ] && echo -e "" >> /opt/karoshi/serversetup/modules/gitlab/gitlab.deb
checksum=$(md5sum "/opt/karoshi/serversetup/modules/gitlab/gitlab.deb" | cut -d ' ' -f 1)
if [ "$checksum" != "8614aa27c0ff83ac209538a5bb762412" ]; then
# The package does not exit and/or it is not valid
# Download Gitlab-CE 8.13.3-ce.0 (Omnibus, Ubuntu Xenial amd64) Package from https://packages.gitlab.com/gitlab/gitlab-ce
rm -f /opt/karoshi/serversetup/modules/gitlab/gitlab.deb
echo '<ul><li>'$"Downloading Gitlab package from https://packages.gitlab.com/gitlab/gitlab-ce"'</li></ul>'
echo '<div style="height: 180px;width:70%;font-size: 100%;overflow:scroll;"><pre style="font-size: 10pt; font-family:Arial, Times, Georgia, serif">'
wget --progress=dot:mega --timeout=10 -O /opt/karoshi/serversetup/modules/gitlab/gitlab.deb $WGET_URL 2>&1
wgetOut=$?
echo "</pre></div>"
if [ $wgetOut != 0 ]; then
#We failed so bail out.
echo '<ul><li>'$"There was a problem downloading the archive."'</li></ul>'
sleep 5
exit 101
fi
# Verify that the file is complete and that the correct file was downloaded
checksum=$(md5sum "/opt/karoshi/serversetup/modules/gitlab/gitlab.deb" | cut -d ' ' -f 1)
if [ "$checksum" != "8614aa27c0ff83ac209538a5bb762412" ]; then
echo '<ul><li>'$"There was a problem verifying the downloaded archive."'</li></ul>'
sleep 5
exit 101
else
echo '<ul><li>'$"Downloaded archive verified!"'</li></ul>'
fi
else
echo '<ul><li>'$"Existing .deb archive validated, skipping download."'</li></ul>'
fi
# Extract Gitlab
cd /opt/karoshi/.tempdata/
echo '<ul><li>'$"Extracting Gitlab"'</li></ul>'
dpkg -x /opt/karoshi/serversetup/modules/gitlab/gitlab.deb /opt/karoshi/.tempdata/gitlab_temp 1>/dev/null 2>/dev/null
# Copy files into place
echo '<ul><li>'$"Copying Gitlab files into place - This may take a while"'</li></ul>'
echo '<div style="height: 180px;width:70%;font-size: 100%;overflow:scroll;"><pre style="font-size: 10pt; font-family:Arial, Times, Georgia, serif">'
rsync -a --no-i-r --info=progress2 /opt/karoshi/.tempdata/gitlab_temp/opt/gitlab /opt/
# Symlink gitlab-ctl
/opt/gitlab/embedded/bin/symlink_ctl_cmds /opt/gitlab
# Delete temp extracted files (they total ~1GB)
rm -rf /opt/karoshi/.tempdata/gitlab_temp
echo '</pre></div>'
echo '<ul><li>'$"Reconfiguring and restarting Gitlab - This may take a while."'</li></ul>'
echo '<div style="height: 180px;width:70%;font-size: 100%;overflow:scroll;"><pre style="font-size: 10pt; font-family:Arial, Times, Georgia, serif">'
gitlab-ctl reconfigure
# Restart gitlab
/opt/karoshi/serversetup/distro/$DISTROCHOICE/scripts/control_services/gitlab_stop 1>/dev/null
/opt/karoshi/serversetup/distro/$DISTROCHOICE/scripts/control_services/gitlab_start 1>/dev/null
echo '</pre></div>'
echo "Gitlab has been updated and restarted, all exisitng configurations and user data should still be in place."
echo "Backups of Gitlab data have been made at: /home/gitlab_backup" #TODO: Suitable backup dir
else
echo "Gitlab could not be found on this server, skipping patch."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.