Skip to content

Instantly share code, notes, and snippets.

@RobThree
Last active November 21, 2023 18:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobThree/34a92d8db7a2e357897517a3de50fa7f to your computer and use it in GitHub Desktop.
Save RobThree/34a92d8db7a2e357897517a3de50fa7f to your computer and use it in GitHub Desktop.
gitlab version checker & notifier
#!/bin/bash
#mail recipient
RCPT=someone@gmail.com
#args: $rcpt $subject $text
sendnotification() {
echo -e "$3" | mail -s "$2" -t $1
}
echo -n "Checking version: "
RESULT=`gitlab-checkversion`
echo ${RESULT}
if [ "${RESULT}" == "up-to-date" ]
then
echo -e "\e[32mOK\e[39m"
else
sendnotification "$RCPT" "New version for Gitlab available: ${RESULT}" "New version for Gitlab available: ${RESULT}"
exit 1
fi
#!/bin/bash
# Path to gitlab
GLPATH='/opt/gitlab/'
# Extract the version from the version-manifest
VERSION=`cat ${GLPATH}/version-manifest.txt | head -n 1 | grep -Po "[\d\.]*"`
# Create a Base64-encoded JSON string
VERSIONB64=`echo "{\"version\":\"$VERSION\"}" | base64`
# Request SVG
URL="https://version.gitlab.com/check.svg?gitlab_info=${VERSIONB64}"
# Extract content from SVG; we need a referrer otherwise we won't be served an image...
RESULT=`wget -q -O- --header="Referer: https://google.com" ${URL} | grep -oPm1 "(?<=\">)(.*)<\/text>" | grep -oP ".+?(?=<\/text>)"`
# Return result to stdout
echo ${RESULT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment