Created
June 7, 2018 11:47
-
-
Save aursu/1cc3dba0419e99fa9209477e1e1eb54d to your computer and use it in GitHub Desktop.
GitLab postuninstall scriptlet (using /bin/sh):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# WARNING: REQUIRES /bin/sh | |
# | |
# - must run on /bin/sh on solaris 9 | |
# - must run on /bin/sh on AIX 6.x | |
# - if you think you are a bash wizard, you probably do not understand | |
# this programming language. do not touch. | |
# - if you are under 40, get peer review from your elders. | |
is_smartos() { | |
uname -v | grep "^joyent" 2>&1 >/dev/null | |
} | |
if is_smartos; then | |
PREFIX="/opt/local" | |
else | |
PREFIX="/usr" | |
fi | |
cleanup_symlinks() { | |
binaries="gitlab-ctl gitlab-rake gitlab-rails gitlab-psql" | |
for binary in $binaries; do | |
rm -f $PREFIX/bin/$binary | |
done | |
} | |
# Clean up binary symlinks if they exist | |
# see: http://tickets.opscode.com/browse/CHEF-3022 | |
if [ ! -f /etc/redhat-release -a ! -f /etc/fedora-release -a ! -f /etc/system-release ]; then | |
# not a redhat-ish RPM-based system | |
cleanup_symlinks | |
elif [ "x$1" = "x0" ]; then | |
# RPM-based system and we're deinstalling rather than upgrading | |
cleanup_symlinks | |
fi | |
posttrans scriptlet (using /bin/sh): | |
#!/bin/sh | |
# GitLab post-transition script | |
# RPM only | |
DEST_DIR=/opt/gitlab | |
if [ -e /etc/gitlab/gitlab.rb ] ; then | |
EXTERNAL_URL=$(awk '/^external_url/ { print $2 }' /etc/gitlab/gitlab.rb | tr -d "'\"") | |
fi | |
check_if_ec2() | |
{ | |
if [ -f /sys/hypervisor/uuid ] && [ `head -c 3 /sys/hypervisor/uuid` = 'ec2' ]; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
get_ec2_address() | |
{ | |
url=$1 | |
# Try collecting fqdn if it is set correctly | |
fqdn=$(/opt/gitlab/embedded/bin/curl -s ${url}) | |
if [ -n "${fqdn}" ]; then | |
# Checking if curl returned an XML message | |
word="<?xml" | |
if ! $(test "${fqdn#*$word}" != "$fqdn"); then | |
EXTERNAL_URL="http://${fqdn}" | |
fi | |
fi | |
} | |
get_details_from_ec2() | |
{ | |
get_ec2_address "http://169.254.169.254/latest/meta-data/public-hostname" | |
if [ -z "${EXTERNAL_URL}" ]; then | |
get_ec2_address "http://169.254.169.254/latest/meta-data/public-ipv4" | |
fi | |
} | |
set_protocol() | |
{ | |
# Checking if EXTERNAL_URL starts with http:// or https:// | |
if ! $(echo ${EXTERNAL_URL} | awk '$0 !~ /^http[s]?:\/\// {exit 1}'); then | |
EXTERNAL_URL="http://${EXTERNAL_URL}" | |
fi | |
} | |
if [ -z "${EXTERNAL_URL}" ]; then | |
check_if_ec2 | |
if [ $? -eq 0 ] ; then | |
get_details_from_ec2 | |
fi | |
else | |
set_protocol | |
fi | |
if [ -z "${EXTERNAL_URL}" ]; then | |
EXTERNAL_URL="http://gitlab.example.com" | |
fi | |
case "$1" in | |
0) | |
# RPM install/upgrade | |
${DEST_DIR}/embedded/bin/symlink_ctl_cmds ${DEST_DIR} | |
EXTERNAL_URL=${EXTERNAL_URL} ${DEST_DIR}/bin/gitlab-ctl upgrade | |
;; | |
*) | |
# Noop. | |
;; | |
esace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment