#!/bin/bash ###################################################################################### #### #### #### Version 2.21.020524 #### #### For questions or comments pconnor@ara.com #### #### Author : Phil Connor #### #### #### #### Notes : #### #### This script is a simple "helper" to configure Auto Updates on linux #### #### servers. #### #### #### ###################################################################################### ########################### #### System Variables #### ########################### if [ "$(command -v lsb_release)" ]; then OS=$(lsb_release -i | awk '{print $3}' | tr '[:upper:]' '[:lower:]') OSVER=$(lsb_release -r | awk '{print $2}' | awk -F. '{print $1}') else OS=$(grep PRETTY_NAME /etc/os-release | sed 's/PRETTY_NAME=//g' | tr -d '="' | awk '{print $1}' | tr '[:upper:]' '[:lower:]') OSVER=$(grep VERSION_ID /etc/os-release | sed 's/VERSION_ID=//g' | tr -d '="' | awk -F. '{print $1}') fi aptcnf="/etc/apt/apt.conf.d" dnfcnf="/etc/dnf/automatic.conf" yumcnf="/etc/yum/yum-cron.conf" ########################################################### #### Detect Package Manger from OS and OSVer Variables #### ########################################################### if [[ ${OS} = amazon || ${OS} = red ]]; then if [[ ${OSVER} = 2 || ${OSVER} = 7 ]]; then PAKMGR="yum -y" else PAKMGR="dnf -y" fi elif [ "${OS}" = ubuntu ]; then PAKMGR="apt -y" fi ##################################### #### Install Auto Update Service #### ##################################### if [[ ${OS} = amazon || ${OS} = red ]]; then if [[ ${OSVER} = 2 || ${OSVER} = 7 ]]; then ${PAKMGR} update ${PAKMGR} install yum-cron #sed -i 's/update_cmd = default/update_cmd = security/g' $yum7cnf #<-- comment this out for ALL available upgrades sed -i 's/apply_updates = no/apply_updates = yes/g' $yumcnf sed -i 's/download_updates = no/download_updates = yes/g' $yumcnf systemctl enable --now yum-cron fi if [[ ${OSVER} = 8 || ${OSVER} = 9 ]]; then ${PAKMGR} update ${PAKMGR} install dnf-automatic sed -i 's/upgrade_type = default/upgrade_type = security/g' $dnfcnf #<-- comment this out for ALL available upgrades sed -i 's/apply_updates = no/apply_updates = yes/g' $dnfcnf systemctl enable --now dnf-automatic.timer fi elif [ "${OS}" = ubuntu ]; then ${PAKMGR} upgrade ${PAKMGR} install unattended-upgrades dpkg-reconfigure --priority=medium unattended-upgrades touch $aptcnf/20auto-upgrades { echo 'APT::Periodic::Update-Package-Lists "1";' echo 'APT::Periodic::Download-Upgradeable-Packages "1";' echo 'APT::Periodic::AutocleanInterval "7";' echo 'APT::Periodic::Unattended-Upgrade "1";' } > $aptcnf/20auto-upgrades fi