From c4f773d323ea84034a0793ed80a52fc4db07608e Mon Sep 17 00:00:00 2001 From: vhaudiquet Date: Wed, 20 Aug 2025 18:11:58 +0200 Subject: [PATCH] No sudoers edit if not needed --- mymachine.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mymachine.sh b/mymachine.sh index 722f42d..d99f641 100755 --- a/mymachine.sh +++ b/mymachine.sh @@ -95,11 +95,13 @@ source ${script_dir}/distribution/${ID}/initial_config.sh # Change directory to user home cd /home/${USERNAME}/ -# Authorize members of group ${WHEEL_GROUP} to sudo, without password -echo "%${WHEEL_GROUP} ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers -if [ $? -ne 0 ]; then - echo "Failed to edit /etc/sudoers" - return 1 2>/dev/null || exit 1 +# Authorize members of group ${WHEEL_GROUP} to sudo, without password (if needed) +if ! [[ "$(tail -n 1 /etc/sudoers)" = "%${WHEEL_GROUP} ALL=(ALL:ALL) NOPASSWD: ALL" ]]; then + echo "%${WHEEL_GROUP} ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers + if [ $? -ne 0 ]; then + echo -e "${BRed}Failed to edit /etc/sudoers. Terminating.${NC}" + exit 1 + fi fi # Install packages @@ -209,4 +211,4 @@ if [ "$MICROCODE_INSTALLED" == "false" ]; then fi echo "To use WireGuard, don't forget to add this client on VPN server (your private key is under ~/.wireguard/privatekey)" echo "To use GitHub, you need to use 'gh auth login' to connect to GitHub" -echo -e "${BNC}Goodbye !${NC}" +echo -e "${BNC}Goodbye ! Make sure to ${BGreen}reboot${BNC} to apply all changes !${NC}"