From 028769faace8e53301ef1d2e603a57507324fb16 Mon Sep 17 00:00:00 2001 From: Mathieu Broillet Date: Mon, 1 Jan 2024 19:56:50 +0100 Subject: [PATCH] fix wrong user when using sudo in auto script --- .github/wiki/script-auto-config-linux.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/wiki/script-auto-config-linux.sh b/.github/wiki/script-auto-config-linux.sh index d4af9ad..de16f9f 100644 --- a/.github/wiki/script-auto-config-linux.sh +++ b/.github/wiki/script-auto-config-linux.sh @@ -1,5 +1,7 @@ #!/bin/bash +USER_BEHIND_SUDO=$(who am i | awk '{print $1}') + # Ask for HomeAssistant IP echo "Please enter your HomeAssistant IP address:" read -r HOMEASSISTANT_IP @@ -15,7 +17,7 @@ fi # Configure sudoers echo "Configuring sudoers..." echo -e "\n# Allow your user to execute specific commands without a password (for EasyComputerManager/HA)" | sudo tee -a /etc/sudoers -echo "$(whoami) ALL=(ALL) NOPASSWD: /sbin/shutdown, /sbin/init, /usr/bin/systemctl, /usr/sbin/pm-suspend, /usr/bin/awk, /usr/sbin/grub-reboot, /usr/sbin/grub2-reboot" | sudo tee -a /etc/sudoers +echo "$USER_BEHIND_SUDO ALL=(ALL) NOPASSWD: /sbin/shutdown, /sbin/init, /usr/bin/systemctl, /usr/sbin/pm-suspend, /usr/bin/awk, /usr/sbin/grub-reboot, /usr/sbin/grub2-reboot" | sudo tee -a /etc/sudoers # Firewall Configuration echo "Configuring firewall..." @@ -29,7 +31,7 @@ fi echo "Configuring persistent xhost for starting GUI apps (like Steam)..." COMMANDS="xhost +$HOMEASSISTANT_IP; xhost +localhost" DESKTOP_ENTRY_NAME="EasyComputerManager-AutoStart" -DESKTOP_ENTRY_PATH="$HOME/.config/autostart/$DESKTOP_ENTRY_NAME.desktop" +DESKTOP_ENTRY_PATH="/home/$USER_BEHIND_SUDO/.config/autostart/$DESKTOP_ENTRY_NAME.desktop" # Create the desktop entry file for the Desktop Environment to autostart at login every reboot cat > "$DESKTOP_ENTRY_PATH" <