Harden user_manage, update_system, and the Zimbra pair
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.
This commit is contained in:
+11
-1
@@ -17,7 +17,12 @@
|
||||
#
|
||||
# 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."
|
||||
@@ -41,6 +46,11 @@ elif command -v zypper &> /dev/null; then
|
||||
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."
|
||||
|
||||
Reference in New Issue
Block a user