Skip to content

Instantly share code, notes, and snippets.

@binsky08
Last active July 20, 2020 13:35
Show Gist options
  • Save binsky08/7b724c5ed4956babe36e6462f9c74101 to your computer and use it in GitHub Desktop.
Save binsky08/7b724c5ed4956babe36e6462f9c74101 to your computer and use it in GitHub Desktop.
#!/bin/bash
############### configuration
minFreeSpaceGB=5
betterFreeSpaceGB=7
enableLog=1
#irgnore root rights and mysql configuration file
testing=0
############## initialization
declare -a oks
declare -a warnings
declare -a errors
declare -a hints
okCount=0
hintCount=0
warningCount=0
errorCount=0
okSign=$'\U2713'
warningSign=$'\U26A0'
errorSign=$'\U2718'
hintSign='>'
Red=$'\e[1;31m'
Green=$'\e[1;32m'
Yellow=$'\e[1;33m'
Blue=$'\e[1;34m'
Cyan=$'\e[1;96m'
BgBlack=$'\e[40m';
Reset=$'\e[0m';
isAptWorking=0
satellitesCount=0
satellitesEntries=""
. /etc/os-release
############# helping methods
if [[ "$(id -u)" != "0" && $testing == 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
debug_log(){
if [ $enableLog == 1 ]; then
echo "${Blue}${1}" | tr '___' ' '
fi
}
check_free_disk_space(){
pathToCheckForFreeSpace=$1
debug_log $(echo "Checking free disk space of: ${pathToCheckForFreeSpace} ..." | tr ' ' '___')
FREE=`df -k --output=avail "$pathToCheckForFreeSpace" | tail -n1`
minFreeSpaceByte=$(expr $minFreeSpaceGB \* 1024 \* 1024);
betterFreeSpaceByte=$(expr $betterFreeSpaceGB \* 1024 \* 1024);
freeGb=$(expr $FREE / 1024 / 1024);
betterFreeSpaceGBMsg=$(expr $betterFreeSpaceGB - $freeGb);
if [[ $FREE -lt $minFreeSpaceByte ]]; then
# less than (minimum) required space is free!
errors+=($(echo "Not enough free space: less than ${minFreeSpaceGB} GB free on ${pathToCheckForFreeSpace} !" | tr ' ' '___'))
((errorCount++))
elif [[ $FREE -lt $betterFreeSpaceByte ]]; then
# less than (better) required space is free!
warnings+=($(echo "Free space of ${freeGb} GB could be enough, but ${betterFreeSpaceGBMsg} GB more on ${pathToCheckForFreeSpace} would be better!" | tr ' ' '___'))
((warningCount++))
else
oks+=($(echo "More than ${betterFreeSpaceGB} GB free space on ${pathToCheckForFreeSpace}" | tr ' ' '___'))
((okCount++))
fi
}
check_aptget_working(){
debug_log $(echo "Checking apt-get ..." | tr ' ' '___')
aptResult=$( (apt-get update >/dev/null) 2>&1)
if [ $? != 0 ]; then
errors+=($(echo "'apt-get update' may not work properly:" | tr ' ' '___'))
errors+=($(echo "$aptResult" | tr ' ' '___'))
((errorCount++))
else
oks+=($(echo "'apt-get update' is working fine" | tr ' ' '___'))
isAptWorking=1
((okCount++))
fi
}
check_package_installed_sat_frontend(){
if dpkg -s "openitcockpit-satellite-frontend" >/dev/null 2>&1; then
echo "mkdir -p /opt/openitc/etc/frontend && touch /opt/openitc/etc/frontend/enable_web_interface"
else
echo "# If you want to use the new Satellite frontend run these commands after you have done the upgrade:"
echo "mkdir -p /opt/openitc/etc/frontend && touch /opt/openitc/etc/frontend/enable_web_interface"
echo "apt-get install openitcockpit-satellite-frontend"
fi
}
print_logo(){
echo -e "\033[38;5;068m
///
///////////////////////
///////////////////////////////
///////////////////////////////////
/////////////////////////////////////////
///////////////////////////////////////////
//////////////// .//////////////////// ,
////////// ////// .
//////// ////// / ///////.
/////// ///////////. /////// ////////////
/////// ///////////// / /////////////
/////// /////////////* /* / /////////////
/////// ///////////// /* /////////////
//////// ////////// /* //////////
////////// //
///////////// ////////
/////////////////////////////////////////////
///////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////"
echo ""
echo " openITCOCKPIT Version 4 Satellite checklist"
echo ""
echo -e "\033[0m"
}
################## run checks
print_logo
check_free_disk_space "/"
check_free_disk_space "/var"
check_free_disk_space "/opt"
check_aptget_working
if [ "$VERSION_CODENAME" == "bionic" ]; then
openitcockpit_upd=$(apt-mark showmanual | grep openitcockpit | grep -v -e 'openitcockpit-statusengine3-oitc-mysql' -e 'openitcockpit-nagios-sat' -e 'openitcockpit-naemon-sat' -e 'openitcockpit-checkmk-sat' -e 'openitcockpit-statusengine3-broker-sat-nagios' -e 'openitcockpit-statusengine3-broker-sat-naemon' | xargs echo)
openitcockpit_rem=$(while read pkg; do echo "$pkg-"; done< <(dpkg -l | awk '$2 ~ /openitcockpit-/ {print $2}' | grep -e 'openitcockpit-statusengine3-oitc-mysql' -e 'openitcockpit-nagios-sat' -e 'openitcockpit-naemon-sat' -e 'openitcockpit-checkmk-sat' -e 'openitcockpit-statusengine3-broker-sat-nagios' -e 'openitcockpit-statusengine3-broker-sat-naemon') | xargs echo)
always="openitcockpit-satellite openitcockpit-naemon"
if [ ! -z "$(dpkg -l | awk '$2 ~ /openitcockpit-checkmk-sat/')" ]; then
always="$always openitcockpit-checkmk"
fi
echo "${BgBlack}${Cyan}"
echo "###############################################################################"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "You can run the upgrade with the following commands:"
echo ""
echo "# Add openITCOCKPIT 4 sources (you have to insert your custom openITCOCKPIT license!)"
echo "mkdir -p /etc/apt/auth.conf.d"
echo "echo 'machine packages.openitcockpit.io login secret password {LICENSE}' > /etc/apt/auth.conf.d/openitcockpit.conf"
echo "echo 'deb https://packages.openitcockpit.io/openitcockpit/bionic/stable bionic main' > /etc/apt/sources.list.d/openitcockpit.list"
echo "curl https://packages.openitcockpit.io/repokey.txt | apt-key add -"
echo ""
check_package_installed_sat_frontend
echo ""
echo "# Upgrade the distribution and openITCOCKPIT"
echo "apt-get update"
echo "apt-get dist-upgrade $openitcockpit_upd $openitcockpit_rem $always"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "###############################################################################"
echo "${Reset}"
fi
tput sgr0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment