The point is to disable presentation mode when manually put to sleep.
So I created a file /usr/lib/systemd/system-sleep/powermanage with 755 permission containing the lines:
#!/bin/sh
echo running powermanage: $1 run as $USER >> /var/log/suspend/suspend.log
case $1 in
pre)
xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -s false 2> /var/log/suspend/error.log
;;
esac
It didn’t work. It logged “permission denied” in error.log and "running powermanage: pre run as " in suspend.log. So the $USER variable was empty. The log files were owned by root:root.
#!/bin/sh
echo running powermanage: $1 run as $USER >> /var/log/suspend/suspend.log
case $1 in
pre)
sudo /scripts/powerreset.sh 2> /var/log/suspend/powerman-sudo.log
;;
esac
created the file /scripts/powerreset.sh with 755 permission
Because scripts executed by systemd context is very dangerous systemd is picky when it comes to scripts.
Due to various requirements and experience with various hosting services - linode and hetzner - I have found that for scripts to execute successfully using systemd and either services or timers benefit from being put in /etc/systemd/scripts folder and limit the executable permissions limited to root.
Moving the script from /scripts to /etc/systemd/scripts didn’t change anything. Neither did chmod 700.
The script that calls this script is still in /usr/lib/systemd/system-sleep/
Thats the only place I know where it will be triggered on sleep event. All the default scripts in these folders have 755 permissions. But it runs even with 700.
File is writeable by user only. But I’d be surprised if that is stopping root from running the script. After all, adding to the script echo > file writable by root only works.
Could an alternative solution be to let the script edit the xml file directly?