update
This is an old revision of the document!
Update the software with one command
A big addition to this is to add an entry in /etc/sudoers.d/Update that lets the script below run without a password.
- Update
#!/bin/bash # /usr/local/bin/Update # This allows updating software by a single common command on all my machines. Logs=~/.Logs/$(date +"%Y/%m/%d") mkdir -p ${Logs} LogFile=${Logs}/$(hostname -s)-$(date +"%T.txt") ############################################################################# ### SRJ 2015-03-27 This script allows a user to update the local ### ### machine without further credentials, it requires that a file be ### ### created in /etc/sudoers.d/Update with the lines below; ### ### See; https://wiki.cyli.org/doku.php?id=auto_update_without_password ### ############################################################################# source /etc/os-release case ${PRETTY_NAME} in "NethServer 7.9.2009") System="RH" ;; "Linux Mint 21.3"|"Linux Mint 22"|"Linux Mint 22.1"|"Linux Mint 22.2"|"Linux Mint 22.3") System="Deb" ;; "Debian GNU/Linux 12 (bookworm)") System="Deb" ;; "Rocky Linux 9.7 (Blue Onyx)"|"Rocky Linux 9.8 (Blue Onyx)"|"Rocky Linux 10.0 (Red Quartz)") System="NewRH" ;; *) System="Unknown" echo "This system is unknown, please update this script and add a check" echo "for the pattern;" echo "${PRETTY_NAME}" echo "Then update https://wiki.cyli.org/doku.php?id=update" exit 127 ;; esac if [[ ${System} == "Deb" ]]; then echo "Updating ${PRETTY_NAME}" | tee -a ${LogFile} sudo apt-get update | tee -a ${LogFile} sudo apt-get upgrade -y | tee -a ${LogFile} sudo apt-get autoremove -y | tee -a ${LogFile} if [ -f /var/run/reboot-required ] ; then echo 'This system needs to be rebooted!' | tee -a ${LogFile} else echo "This system doesn't need rebooting." | tee -a ${LogFile} fi elif [[ ${System} == "RH" ]]; then echo "Updating ${PRETTY_NAME}" | tee -a ${LogFile} sudo /usr/bin/yum -y update | tee -a ${LogFile} sudo /usr/bin/yum -y autoremove | tee -a ${LogFile} Something='' Something=$(sudo /usr/bin/needs-restarting) if [[ ! -z $Something ]]; then echo 'This machine needs to be restarted!' | tee -a ${LogFile} else echo 'No restart is required.' | tee -a ${LogFile} fi elif [[ ${System} == "NewRH" ]]; then echo "Updating ${PRETTY_NAME}" | tee -a ${LogFile} sudo /usr/bin/dnf -y update | tee -a ${LogFile} sudo /usr/bin/dnf -y autoremove | tee -a ${LogFile} Something='' Something=$(sudo /usr/bin/needs-restarting) if [[ ! -z $Something ]]; then echo 'This machine needs to be restarted!' | tee -a ${LogFile} else echo 'No restart is required.' | tee -a ${LogFile} fi fi
The /etc/sudoers.d/Update script is Auto update without a password
update.1771430294.txt.gz · Last modified: by steve
