LibrePortal/scripts/install/install_swapfile.sh
librelad 6bb04533fa fix(desudo): manager->self sudo drops -> runAsManager (scoped-sudoers safe)
The scoped sudoers grants the manager (root) and (dockerinstall) but NOT
(itself), so the many 'sudo -u $sudo_user_name <cmd>' calls (crontab,
git/update, reinstall, swapfile, …) failed with 'a password is required'
once per CLI command. runAsManager runs the command plainly when already
the manager (the runtime case) and only sudo -u's when root (install
time), so it's correct in both contexts and needs no sudoers self-grant.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-24 18:40:19 +01:00

28 lines
984 B
Bash
Executable File

#!/bin/bash
installSwapfile()
{
if [[ "$CFG_REQUIREMENT_SWAPFILE" == "true" ]]; then
if [ ! -f "$swap_file" ]; then
isHeader "Increasing Swapfile"
ISSWAP=$( (runAsManager swapoff /swapfile) 2>&1 )
if [[ "$ISSWAP" != *"No such file or directory"* ]]; then
local result=$(runAsManager swapoff /swapfile)
isSuccessful "Turning off /swapfile (if needed)"
fi
local result=$(runAsManager fallocate -l $CFG_SWAPFILE_SIZE /swapfile)
checkSuccess "Allocating $CFG_SWAPFILE_SIZE to the /swapfile"
local result=$(sudo chmod 0600 /swapfile)
checkSuccess "Adding permissions to the /swapfile"
local result=$(runAsManager mkswap /swapfile)
checkSuccess "Swapping to the new /swapfile"
local result=$(runAsManager swapon /swapfile)
checkSuccess "Enabling the new /swapfile"
fi
fi
}