HI All,
I would like to make my script generic so I could share it but it requires su status to run and as a result it does not see ~/ as the users home but as the root home. My original version simply used a typed out path name referring to my home directory. I've also tried $HOME with the same result. Asking the user to edit the script for their preferred path would be one possibility but I'm hoping to make it plug-n-play straight out of the can with editing as an option. It's a fairly complex script.
So to put in other words, I need a way to generically refer to the users home directory while running a sudo command. Any ideas?
Thanks for looking.
Best regards
Bob G.
SOLVED: How do I generic refer to a user HOME if the script is sudo
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
-
- Level 3
- Posts: 110
- Joined: Tue Nov 15, 2016 4:32 pm
SOLVED: How do I generic refer to a user HOME if the script is sudo
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: How do I generic refer to a user HOME if the script is sudo
Hi,
According to this you can use $SUDO_USER if the script was called by
So, a user's home path should be
I hope I understand you correctly.
Good luck!
(Edit: i replaced the
According to this you can use $SUDO_USER if the script was called by
sudo
command.So, a user's home path should be
/home/$SUDO_USER/
.I hope I understand you correctly.
Good luck!
(Edit: i replaced the
``
(I am used to MarkDown) to [c]
, as I was asked to)
Last edited by dvirberlo on Thu Dec 02, 2021 8:27 am, edited 1 time in total.
If your issue was solved please edit the title and add [SOLVED]. It can be very useful for others as well.
-
- Level 3
- Posts: 110
- Joined: Tue Nov 15, 2016 4:32 pm
Re: How do I generic refer to a user HOME if the script is sudo
Thank you so much. I hope to have a complete set of files ready to go demonstrating building and using a container made solely from bash commands. The container is fully tested. It can run Blender at native speeds and is totally isolated from the host except for using the host xwindow display for outputting graphics. It is encrypted and when not in use it is unreadable. I just needed to solve this home reference problem so the scripts behave generically. The only thing left is to find out if I can post the whole shebang since it's two bash scripts and a lengthy README.txt describing creating the container space. The scripts serve to open or close the container. One script is 922bytes, the other 2.3k. The README is 6.7K but has indispensable instructions for creating the container space using bash command and standard utilities of course.
I don't know what the forum policy is on post sizes but the best way to do this would be to simply post everything as readable code. It should be very informative and makes containers far less mysterious.
Thanks again for your help.
Best regards,
Bob G.
I don't know what the forum policy is on post sizes but the best way to do this would be to simply post everything as readable code. It should be very informative and makes containers far less mysterious.
Thanks again for your help.
Best regards,
Bob G.
Re: How do I generic refer to a user HOME if the script is sudo
A
systemd-nspawn
container? Anycase, if that was a question I'd say there's little set policy: yes, pasting in scripts in [code]...[/code]
blocks is best for reading and I'd quite doubt that anyone would object to then also attaching, as to be best for saving them.Re: How do I generic refer to a user HOME if the script is sudo
Why not try defining a polkit to enable your script to run with admin privileges instead of sudo, I think $HOME will still refer the the user's home folder. Not tried it.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0