RangHo / dotfiles

My personal configuration and bootstrap files
GNU General Public License v3.0
23 stars 0 forks source link

Questions/Help #8

Closed rafamadriz closed 3 years ago

rafamadriz commented 3 years ago

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.

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.

RangHo commented 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.

How to install stuff without typing password a gazillion times

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.

How to put everything in a single file

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:

  1. Provide a list of necessary dependencies in pkginfo file. In that file, use depends command to add a package to the dependency list.
  2. The main 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. (haha recursive call go brrr)
  3. The actual installation function will read the list of packages and install them. Inside the functions I use 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.

What are those debug stuffs

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!

rafamadriz commented 3 years ago

Thanks I appreciate it!