user_manage.sh ran useradd/userdel/usermod with no privilege check at
all, so an ordinary user got "Failed to create user." with no hint that
root was the missing piece. Mutating subcommands now require root while
listusers/listgroups stay open, and the check runs *after* the
subcommand is recognised so a bare invocation still prints usage instead
of complaining about privileges. Account names are validated before
reaching useradd, and `deluser` -- which removes the home directory
irrecoverably -- prints what it will delete and confirms first.
zimbra_backup.sh reported success on failed backups. getRestURL can
write an HTTP error body and still exit zero, so a "✅ Backup completed"
could sit over a file containing an error page. Size and gzip -t checks
now gate that, and a suspect file is renamed .suspect rather than
deleted, so it can be looked at. zimbra_restore.sh likewise validates
the archive before starting a restore from it.
Both Zimbra scripts had `cmd` followed by `if [ $? -eq 0 ]`. Adding
set -e to those would have made the error branches unreachable -- set -e
exits before the check -- so the tests are inline instead. That would
have been a silent regression rather than a visible one.
update_system.sh gained strict mode, and a note on the pacman branch:
Arch has no supported partial-upgrade path, and --noconfirm answers away
the prompts that would otherwise warn.
Integrity checks verified against an error page, a truncated archive, a
non-gzip file and a real one.
59 lines
2.1 KiB
Bash
59 lines
2.1 KiB
Bash
#!/bin/bash
|
|
# update_system.sh - Apply system package updates
|
|
#
|
|
# Copyright (C) 2025 LINUXexpert.org
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by the
|
|
# Free Software Foundation, version 3 of the License.
|
|
#
|
|
# This program is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
# for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along
|
|
# with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
#
|
|
# Usage: update_system.sh (no arguments, run as root)
|
|
# Description: Detects the Linux distro's package manager and installs all updates.
|
|
#
|
|
# Unattended: every branch below passes -y or --noconfirm, so this will
|
|
# apply whatever the configured repositories offer without asking.
|
|
|
|
set -euo pipefail
|
|
|
|
# Ensure running as root
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "Please run as root to apply system updates."
|
|
exit 1
|
|
fi
|
|
|
|
if command -v apt-get &> /dev/null; then
|
|
echo "Updating with apt-get..."
|
|
apt-get update && apt-get upgrade -y
|
|
elif command -v apt &> /dev/null; then
|
|
echo "Updating with apt..."
|
|
apt update && apt upgrade -y
|
|
elif command -v dnf &> /dev/null; then
|
|
echo "Updating with dnf..."
|
|
dnf upgrade -y
|
|
elif command -v yum &> /dev/null; then
|
|
echo "Updating with yum..."
|
|
yum update -y
|
|
elif command -v zypper &> /dev/null; then
|
|
echo "Updating with zypper..."
|
|
zypper refresh && zypper update -y
|
|
elif command -v pacman &> /dev/null; then
|
|
echo "Updating with pacman..."
|
|
# Arch has no supported partial-upgrade path: -Syuu on a stale mirror
|
|
# list or a half-updated system can leave unbootable library mismatches,
|
|
# and --noconfirm answers away the prompts that would have warned. Kept
|
|
# for parity with the other package managers, but this is the branch to
|
|
# be most careful with.
|
|
pacman -Syuu --noconfirm
|
|
else
|
|
echo "Error: No supported package manager found on this system."
|
|
exit 1
|
|
fi
|