Closed rafamadriz closed 3 years ago
I took a quick peek at your code. It seems like you are calling the script with sudo privilege. Apparently this is considered a bad practice as it makes you numb to calling whatever script with sudo but idk... Anyways, here are the answers.
Regardless of whether using sudo
to call program is a good practice or not, in this case I would recommend actually calling the script as the user you want to install the script. When I take a look at your code, I see you are executing the script with sudo
and within that script you sudo
back to the current user. What you are doing is basically using sudo
to actually switch user, instead of running a command with root privilege. In this case, sudo
timeout is ineffective. So, I recommend calling the script itself as the regular user and use sudo
when absolutely necessary. This way, you don't have to build AUR packages by going back to regular user within a sudo
environment.
Do not call the entire script as root
unless absolutely necessary. sudo
timeout allows you to run sudo
multiple times without having to input a password multiple times, and being root
all the time becomes more of a hassle when you have some commands to run as a regular user.
The second question can be solved by the first solution as well. This is the case where having root
privilege becomes a hassle. If the script is not called with sudo
, you can just cp
and the file permission and ownership would be fine and dandy. For me, I delegate "installing" files to GNU stow
, as explained in the README file.
So this is how I implemented my installer:
pkginfo
file. In that file, use depends
command to add a package to the dependency list.dotfile
script will source
the pkginfo
definition file. It will execute all the depends
command where each call will construct a list of depending packages. sudo
command if necessary.Since most of them don't take very long time, in most cases I don't have to provide sudo
password more than one time. If you have massive AUR packages built (like linux kernel) you can use the sudo
keepalive script I showed in the original Reddit post.
The debug
shenanigan is basically a debug output that you can enable by setting DEBUG
environment variable to non-null. Check this line and these logging function definitions.
If this answer your question, please close the issue. Or you can ask a follow-up question, if you have more!
Thanks I appreciate it!
I saw you post on reddit, I asked a few questions and you were open to answer more of my questions regarding the script if I opened an issue here, so here I am.
But that seems very hacky. The second solution I thought to have everything in one single script was using a complete path in this line for copying everything to $HOME, so I use
/home/$user/
instead and that would install everything in the user's home folder instead of the root user. But what it's your ideal solution for this ?Anyway these are the two main questions I have, doing
makepkg -si --noconfirm
without asking for password, and finding some way of having everything in one script file without installing things where they don't go. This is my script, I know it's going to be kinda cringe to look at it, what you're doing seems more complex, elegant and better engineered overall, but hey, mine is getting the job done I just want to improve it and hopefully someday have something similar to yours, so I'm open to any suggestions if you want to see it and tell me ways to improve it.In advance, thanks for your time and good luck in the military.