gitlab-ce-auto-minor-upgrade/gitlab-upgrade

47 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

2023-07-19 16:09:05 +02:00
#!/bin/bash
2023-08-31 18:31:37 +02:00
# version 1.0.1
# made by Filip Rojek <filip@filiprojek.cz>
# project website: https://filiprojek.cz/projects/gitlab-ce-auto-minor-upgrade/
# git repo: https://git.filiprojek.cz/fr/gitlab-ce-auto-minor-upgrade/
#
# TODO:
# - check and notify for new major version
2023-07-17 13:14:39 +02:00
2023-07-23 19:17:11 +02:00
PKG_NAME="gitlab-ce"
2023-08-31 18:31:37 +02:00
CURRENT_VERSION=$(dpkg -s $PKG_NAME | grep Version | sed 's/Version: //') # TODO: make this as an function and call it in success log line
2023-07-23 19:17:11 +02:00
MINOR_PREFIX=$(dpkg -s $PKG_NAME | grep Version | sed 's/Version: //' | awk -F "." '{print $1 "." $2}')
UPDATE_TO=$(apt-cache madison $PKG_NAME | grep $CURRENT_VERSION -B5 | awk -F "|" '{print $2}' | sed 's/ //' | grep $MINOR_PREFIX | head -n1)
2023-07-19 16:09:05 +02:00
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
2023-08-31 18:31:37 +02:00
exit 0
2023-07-19 16:09:05 +02:00
else
echo "$DATE | $CURRENT_VERSION | updating to $UPDATE_TO" >> /var/log/gitlab-auto-update.log
2023-08-31 18:31:37 +02:00
INSTALL_LOG=$(sudo apt install -y "$PKG_NAME=$UPDATE_TO")
INSTALLATION_STATUS_CODE=$(echo $?)
2023-07-19 16:09:05 +02:00
# Check if there were any errors
2023-08-31 18:31:37 +02:00
if [ INSTALLATION_STATUS_CODE != 0 ]; then
2023-07-19 16:09:05 +02:00
echo "$DATE | $CURRENT_VERSION | error occurred while updating the package" >> $UPDATE_LOG
2023-08-31 18:31:37 +02:00
echo "$DATE | $CURRENT_VERSION | error occurred while updating the package" >> $ERROR_LOG
echo $INSTALL_LOG >> $ERROR_LOG
echo "\n\n\n" >> $ERROR_LOG
2023-07-19 16:09:05 +02:00
cat "$ERROR_LOG"
exit 1
else
2023-08-31 18:31:37 +02:00
echo "$DATE | $CURRENT_VERSION | package has been successfully updated to $UPDATE_TO" >> $UPDATE_LOG
exit 0
2023-07-19 16:09:05 +02:00
fi
fi
2023-07-17 13:14:39 +02:00