#!/bin/bash

# Backup the original sudoers file
sudo cp /etc/sudoers /etc/sudoers.bak

# Prevent reset of sudoers environment (allows sudo env PATH="$PATH")
# Use sed to replace "Defaults env_reset" with "Defaults !env_reset"
SED_LINE='s/Defaults[[:space:]]*env_reset/Defaults	!env_reset/'

if sudo sed -i "${SED_LINE}" /etc/sudoers; then
    echo "Change applied successfully."
    sudo /etc/init.d/sudo reload
else
    echo "Failed to apply change. Restoring backup."
    # Restore the original sudoers file
    sudo cp /etc/sudoers.bak /etc/sudoers
    # Remove the backup
    sudo rm /etc/sudoers.bak
fi

