This is my bash script into init.d:
#!/bin/bash
case "$1" in
'start')
# mount
bindfs -n /home/my_user/.local/share/Cryptomator/mnt /home/my_user/drivefolder
;;
'stop')
fusermount -u /home/my_user/drivefolder
;;
*)
echo "Usage: $0 { start | stop }"
;;
esac
so i run it from root account:
/etc/init.d/drivemount.sh start
/etc/init.d/drivemount.sh stop
What I want is to mount/umount /home/my_user/drivefolder from root account to my_user account without privileges (so that the mounted folder can be manipulated without privileges).
is there any way to do this? (without having to run the script in my_user account without privileges and from another location)
Clarification: The script does not run automatically. What I want is to run the script manually, either from root or from my_user with sudo only from /etc/init.d location (for reasons unrelated to the question)
PD: I have read that with eval it can be done but I don't know.
bindfsasmy_user? Doesn'tsudo -u my_user bindfs …work? – Kamil Maciorowski Jul 10 '21 at 17:27sudo -u my_user bindfs bla bla. But it would be necessary to correct the command for umount – acgbox Jul 10 '21 at 17:50/etc/init.d/so it runs automatically.Therefore I don't understand "if I run the script withsudo". Why do you want to run it withsudo? Doesn't it run as root automatically? And I totally don't get this "eval" idea. As for unmounting, I think root canfusermount -uanything withoutsudo. – Kamil Maciorowski Jul 10 '21 at 17:55/etc/init.d/is misleading. – Kamil Maciorowski Jul 10 '21 at 18:02my_userwithsudo" -- Why withsudo? The whole point seems to be you want to do something asmy_userwithout elevated privileges. My solution in the first comment is simple and (IMO) so obvious. For this reason I did not post an answer, it seemed too easy, I suspected there was something more. And now it seems there is something more, but frankly I don't understand what it is. If you putsudo -u my_userbeforebindfsin the script, then what exactly is the problem when you run the script as root or the user (with or withoutsudo)? – Kamil Maciorowski Jul 10 '21 at 18:30sudo -u my_userto mount and umount commands). The problem with your answer is that it is a bash script that is run fromrootor withsudo ./script.shso there is duplicatesudo– acgbox Jul 10 '21 at 18:45sudois the right tool to "change identity". If you need to change it twice then you need twosudos. – Kamil Maciorowski Jul 10 '21 at 18:48sudoin a script orsudoan entire script? I assumed you know what you want. If you really want to runsudo ./script.shand then drop privileges inside the script then you needsudoor something similar in the script. – Kamil Maciorowski Jul 10 '21 at 18:57