'local result=$(cmd)' resets $? to 0 (the local builtin's own exit), so the
following checkSuccess always saw success regardless of cmd's real exit — the
mechanism that masked the de-sudo write failures. Split declaration from
assignment ('local result; result=$(cmd)') across all 235 active-code sites
(84 files) so the command's exit reaches checkSuccess. No behaviour change
beyond $? now being accurate (no set -e in runtime code; multi-line
assignments transform safely).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
69 lines
2.4 KiB
Bash
Executable File
69 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
installUFW()
|
|
{
|
|
if [[ "$CFG_REQUIREMENT_UFW" == "true" ]]; then
|
|
ISUFW=$( (runSystem ufw status ) 2>&1 )
|
|
if [[ "$ISUFW" == *"command not found"* ]]; then
|
|
isHeader "Install UFW Firewall"
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Installing using linux package installer"
|
|
echo ""
|
|
|
|
local result; result=$(yes | runSystem apt-get install ufw )
|
|
checkSuccess "Installing UFW package"
|
|
|
|
# ((menu_number++))
|
|
# echo ""
|
|
# echo "---- $menu_number. Updating Firewall Rules"
|
|
# echo ""
|
|
|
|
# # Detect SSH port if not provided
|
|
# if [[ -z "$ssh_port" ]]; then
|
|
# SSH_CONFIG="/etc/ssh/sshd_config"
|
|
# ssh_port=$(grep "^Port" "$SSH_CONFIG" 2>/dev/null | awk '{print $2}' | head -n1)
|
|
# ssh_port=${ssh_port:-22} # Default to 22 if not found
|
|
# fi
|
|
|
|
# local result; result=$(runSystem ufw allow $ssh_port)
|
|
# checkSuccess "Enabling Port $ssh_port through the firewall"
|
|
# local result; result=$(runSystem ufw allow ssh)
|
|
# checkSuccess "Enabling SSH through the firewall"
|
|
|
|
# while true; do
|
|
# isQuestion "Do you want to keep port $ssh_port (SSH) open? (y/n): "
|
|
# read -rp "" UFWSSH
|
|
# if [[ "$UFWSSH" =~ ^[yYnN]$ ]]; then
|
|
# break
|
|
# fi
|
|
# isNotice "Please provide a valid input (y/n)."
|
|
# done
|
|
|
|
# if [[ "$UFWSSH" == [nN] ]]; then
|
|
# local result; result=$(runSystem ufw deny $ssh_port)
|
|
# checkSuccess "Blocking Port $ssh_port through the firewall"
|
|
# local result; result=$(runSystem ufw deny ssh)
|
|
# checkSuccess "Blocking SSH through the firewall"
|
|
# fi
|
|
|
|
local result; result=$(runSystem ufw --force enable)
|
|
checkSuccess "Enabling UFW Firewall"
|
|
|
|
((menu_number++))
|
|
echo ""
|
|
echo "---- $menu_number. Changing logging options"
|
|
echo ""
|
|
|
|
local result; result=$(yes | runSystem ufw logging $CFG_UFW_LOGGING)
|
|
checkSuccess "Disabling UFW Firewall Logging"
|
|
|
|
isSuccessful "UFW Firewall has been installed, you can use ufw status to see the status"
|
|
|
|
menu_number=0
|
|
cd
|
|
fi
|
|
fi
|
|
}
|