From 208acd25555350579299a8be9b73d57fe4e4c9cc Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Wed, 19 Jul 2023 16:09:05 +0200 Subject: [PATCH] updated: gitlab-upgrade --- gitlab-upgrade | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/gitlab-upgrade b/gitlab-upgrade index 4caad35..2327459 100755 --- a/gitlab-upgrade +++ b/gitlab-upgrade @@ -1,5 +1,31 @@ -#!/bin/sh +#!/bin/bash CURRENT_VERSION=$(dpkg -s gitlab-ce | grep Version | sed 's/Version: //') -AVAILABE_VERSION=$(apt-cache madison gitlab-ce) +MINOR_PREFIX=$(dpkg -s gitlab-ce | grep Version | sed 's/Version: //' | awk -F "." '{print $1 "." $2}') +UPDATE_TO=$(apt-cache madison gitlab-ce | grep $CURRENT_VERSION -B5 | awk -F "|" '{print $2}' | sed 's/ //' | grep $MINOR_PREFIX | head -n1) + +DATE=$(date +'%Y-%m-%d %H:%M:%S') + +UPDATE_LOG="/var/log/gitlab-auto-update.log" +ERROR_LOG="/var/log/gitlab-auto-update.error.log" + +# Remove leading/trailing whitespace and newlines from the strings +CURRENT_VERSION=$(echo "$CURRENT_VERSION" | tr -d '[:space:]') +UPDATE_TO=$(echo "$UPDATE_TO" | tr -d '[:space:]') + +if [[ "$CURRENT_VERSION" == "$UPDATE_TO" ]]; then + echo "$DATE | $CURRENT_VERSION | no new minor version is available" >> /var/log/gitlab-auto-update.log +else + echo "$DATE | $CURRENT_VERSION | updating to $UPDATE_TO" >> /var/log/gitlab-auto-update.log + sudo apt install -y "gitlab-ce-$UPDATE_TO" 2>"$ERROR_LOG" + + # Check if there were any errors + if [ -s "$ERROR_LOG" ]; then + echo "$DATE | $CURRENT_VERSION | error occurred while updating the package" >> $UPDATE_LOG + cat "$ERROR_LOG" + exit 1 + else + echo "$DATE | $CURRENT_VERSION | package updated successfully" >> $UPDATE_LOG + fi +fi