-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from dinger1986/main
added linux update scripts
- Loading branch information
Showing
2 changed files
with
99 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
#!/bin/bash | ||
|
||
#Update script to run for most common linux distros | ||
# Synopsis: This script automates the process of updating software packages across multiple Linux distributions. | ||
# It checks for the available package manager (dnf, yum, apt, pacman, or zypper) and executes the appropriate commands to update the system. | ||
# Users can optionally allow the script to automatically reboot the system after updates by passing the --autoreboot flag. | ||
# | ||
# Usage: | ||
# Update with automatic reboot --autoreboot | ||
# | ||
# Note: The script is designed to be flexible, catering both to interactive use cases and automated workflows. | ||
|
||
if [[ `which yum` ]]; then | ||
AUTO_REBOOT=0 | ||
|
||
# Check for --autoreboot flag | ||
for arg in "$@"; do | ||
if [[ $arg == "--autoreboot" ]]; then | ||
AUTO_REBOOT=1 | ||
fi | ||
done | ||
|
||
# Update system based on package manager availability | ||
if command -v dnf &> /dev/null; then | ||
dnf -y update | ||
elif command -v yum &> /dev/null; then | ||
yum -y update | ||
elif [[ `which apt` ]]; then | ||
apt-get -y update | ||
apt-get -y upgrade | ||
elif [[ `which pacman` ]]; then | ||
elif command -v apt &> /dev/null; then | ||
apt-get -y update && apt-get -y upgrade | ||
elif command -v pacman &> /dev/null; then | ||
pacman -Syu | ||
elif [[ `which zypper` ]]; then | ||
elif command -v zypper &> /dev/null; then | ||
zypper update | ||
else | ||
echo "Unknown Platform" | ||
echo "Package manager not detected. Please update your system manually." | ||
exit 1 | ||
fi | ||
|
||
sleep 10 && reboot & | ||
# Handle auto-reboot | ||
if [ $AUTO_REBOOT -eq 1 ]; then | ||
echo "Rebooting in 10 seconds..." | ||
sleep 10 && reboot & | ||
else | ||
echo "Updates done, please reboot" | ||
fi |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash | ||
|
||
# Synopsis: | ||
# This script is designed to check for available package updates on Linux systems. It supports multiple package | ||
# managers, including apt-get (used by Debian-based distributions like Ubuntu), dnf (used by Fedora), and yum | ||
# (used by CentOS and RHEL). The script identifies which package manager is available on the system and uses it | ||
# to check for updates. If updates are available, it lists them and exits with code 1. If updates cannot be checked, | ||
# it exits with code 2. If there are no updates, it exits with code 0. | ||
|
||
# Exit Codes: | ||
# 0 - Success: No updates are available. | ||
# 1 - Error: Updates are available (this script treats the availability of updates as an actionable item, thus 'Error'). | ||
# 2 - Warning: The script was unable to check for updates, possibly due to an unsupported package manager or other issue. | ||
|
||
# The script provides a straightforward way for administrators and scripts to check for software updates across a | ||
# variety of Linux distributions using Tactical RMM, simplifying maintenance tasks and ensuring systems can be kept up to date with | ||
# minimal manual intervention. | ||
|
||
#!/bin/bash | ||
|
||
# Function to check for updates using apt-get | ||
check_apt_get() { | ||
apt-get update > /dev/null | ||
UPDATES=$(apt-get -s upgrade | awk '/^Inst/ { print $2 }') | ||
if [ -n "$UPDATES" ]; then | ||
echo "Updates available:" | ||
echo "$UPDATES" | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Function to check for updates using dnf | ||
check_dnf() { | ||
UPDATES=$(dnf check-update | awk '{if (NR!=1) {print $1}}') | ||
if [ -n "$UPDATES" ]; then | ||
echo "Updates available:" | ||
echo "$UPDATES" | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Function to check for updates using yum | ||
check_yum() { | ||
UPDATES=$(yum check-update | awk '{if (NR!=1 && !/Loaded plugins/) {print $1}}') | ||
if [ -n "$UPDATES" ]; then | ||
echo "Updates available:" | ||
echo "$UPDATES" | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Determine which package manager is available and check for updates | ||
if command -v apt-get &> /dev/null; then | ||
check_apt_get | ||
elif command -v dnf &> /dev/null; then | ||
check_dnf | ||
elif command -v yum &> /dev/null; then | ||
check_yum | ||
else | ||
echo "Unable to determine package manager or check updates." | ||
exit 2 | ||
fi | ||
|
||
echo "No updates available." | ||
exit 0 |