Created
October 27, 2020 15:12
-
-
Save iversond/1bcc0ae85896d6438a90da44980bff0b to your computer and use it in GitHub Desktop.
Rundeck script to patch GitLab
This file contains hidden or 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
#!/usr/bin/env bash | |
# shellcheck disable=2059,2154,2034,2155,2046,2086 | |
#=============================================================================== | |
# vim: softtabstop=2 shiftwidth=2 expandtab fenc=utf-8 spelllang=en ft=sh | |
#=============================================================================== | |
# | |
# DESCRIPTION: Apply security and bug fixes to GitLab. | |
# | |
#=============================================================================== | |
set -e # Exit immediately on error | |
set -u # Treat unset variables as an error | |
set -o pipefail # Prevent errors in a pipeline from being masked | |
IFS=$'\n\t' # Set the internal field separator to a tab and newline | |
############### | |
# Variables # | |
############### | |
#export DEBUG=true | |
declare -A timings | |
############### | |
# Functions # | |
############### | |
function echoinfo() { | |
local GC="\033[1;32m" | |
local EC="\033[0m" | |
printf "${GC} ☆ INFO${EC}: %s${GC}\n" "$@"; | |
} | |
function echodebug() { | |
local BC="\033[1;34m" | |
local EC="\033[0m" | |
local GC="\033[1;32m" | |
if [[ -n ${DEBUG+x} ]]; then | |
printf "${BC} ★ DEBUG${EC}: %s${GC}\n" "$@"; | |
fi | |
} | |
function echoerror() { | |
local RC="\033[1;31m" | |
local EC="\033[0m" | |
printf "${RC} ✖ ERROR${EC}: %s\n" "$@" 1>&2; | |
} | |
function display_timings_summary() { | |
local divider='==============================' | |
divider=$divider$divider | |
local header="\n %-28s %s\n" | |
local format=" %-28s %s\n" | |
local width=40 | |
local total_duration=0 | |
for duration in "${timings[@]}"; do | |
total_duration=$((duration + total_duration)) | |
done | |
printf "$header" "TASK" "DURATION" | |
printf "%$width.${width}s\n" "$divider" | |
for key in "${!timings[@]}"; do | |
local converted_timing=$(date -u -d @${timings[$key]} +"%T") | |
printf "$format" "$key" "${converted_timing}" | |
done | |
printf "%$width.${width}s\n" "$divider" | |
printf "$format" "TOTAL TIME:" $(date -u -d @${total_duration} +"%T") | |
printf "\n" | |
} | |
function backup_gitlab() { | |
local begin=$(date +%s) | |
echoinfo "Backing up GitLab database" | |
sudo gitlab-rake gitlab:backup:create STRATEGY=copy | |
local end=$(date +%s) | |
local tottime="$((end - begin))" | |
timings[backup_gitlab]=$tottime | |
} | |
function update_gitlab() { | |
local begin=$(date +%s) | |
echoinfo "Applying GitLab updates" | |
sudo yum install -y gitlab-ee | |
local end=$(date +%s) | |
local tottime="$((end - begin))" | |
timings[update_gitlab]=$tottime | |
} | |
######## | |
# Main # | |
######## | |
backup_gitlab | |
update_gitlab | |
display_timings_summary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment