Files
HamPack/sudo.sh
2026-03-25 14:28:14 -06:00

31 lines
837 B
Bash
Executable File

#!/bin/bash
#
# Purpose : Set up passwordless sudo for HamPack installer
SUDOERS_FILE="/etc/sudoers.d/hampack"
USERNAME=$(whoami)
echo "Setting up passwordless sudo for HamPack..."
echo "Please enter your sudo password once to continue:"
sudo -v
if [ $? -ne 0 ]; then
echo "Error: incorrect password or sudo not available."
exit 1
fi
sudo tee "$SUDOERS_FILE" > /dev/null << EOF
$USERNAME ALL=(ALL) NOPASSWD: /usr/bin/pacman, /usr/bin/cp, /usr/bin/udevadm, /usr/bin/systemctl, /usr/sbin/reboot, /usr/sbin/usermod
EOF
# Verify the file is valid
sudo visudo -c -f "$SUDOERS_FILE"
if [ $? -eq 0 ]; then
echo "Sudoers file created successfully for $USERNAME."
echo "Passwordless sudo is now configured for the HamPack installer."
else
echo "Error: sudoers file is invalid, removing..."
sudo rm -f "$SUDOERS_FILE"
exit 1
fi