HarshKapadia2 / HarshKapadia2/dotfiles

Specify Dotfile Installation Location

Open
#3 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Shell
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

There are three options that I can think of right now. Not completely sure which one to choose.

# First Option

- [ ] Add a `sudo` prompt to check if the user really intended to run the script as `sudo`, because doing this leads to the scripts being installed for the root user instead of the current user running the setup script.
- This happens because the
- Package installations and things will require `sudo` permissions, but the OS will prompt for that when required.
- [ ] Print a note/warning on why `sudo` might not be what the user wants (also talk about how to prevent this prompt with the flag mentioned below) and then wait for input.
- [ ] Add a flag to prevent this check.
- The name of this flag can be `--sudo`, but maybe there is a better name. Another idea is `--no-usr-chk`.
- [ ] Document this behaviour in the README and in the setup script's tool help
- [ ] Add a note on the `sudo` issue and why it can cause unwanted actions
- [ ] Do additionally mention that the script will require `sudo` permissions to install packages, but the OS will ask for those permissions when required. If the script needs to be run in an unattended fashion to install packages (using `--install-pkg`), then the script has to run in a privileged environment to not ask for `sudo` permissions.
- [ ] Document the new flag and when it actually does something and is not ignored

# Second Option

The above way is one direction. The other option is to allow `sudo` and instead ask the user for the intended home directory where the dotfiles want to be installed in, using a `--user-home` flag.

The advantage with this option is that one can install the dotfiles for any user on the system (if the user running the script has admin permissions), without having to login as them.

The downsides
- Writing out the logic
- Remembering an extra flag
- Having to write logic so that automated dotfile installers (like what GitHub Codespaces and Gitpod have) that automatically pick up the `setup` script are still able to install the files for the current user without any flags.

TODO: Does installing with `sudo` permissions mean that the packages are not available to the current user? That seems wrong and I think that the packages are available to all users on the system, but maybe that's not what happens. In any case, please confirm package installation behaviour/location when the script is run with `sudo` permissions (with the `--install-pkg` flag) and when the script is not run with `sudo` permissions, but the OS itself asks for `sudo` permissions to install packages. That should mean the same thing, but I just want to confirm that.

# Third Option

Detect the original user even if `sudo` is used. This only works for one level deeper.

This is automated, so it doesn't matter if the script is run with or without `sudo` permissions, because files will only be installed for the current user running the setup script. No need to maintain logic for two situations (with and without the `--user-home` flag).

Example:

```bash
HOME_DIR=""
USER_NAME=""

# Set home directory
if [[ -z "${HOME:+str}" ]]; then
echo ""
echo "ERROR: Environment variable 'HOME' not set."
echo ""
exit 1
else
if [[ -z "${SUDO_USER:+str}" ]]; then
HOME_DIR="$HOME"
else
HOME_DIR=$(getent passwd "$SUDO_USER" | cut -d : -f 6)
fi
fi

# Set user name
if [[ -z "${USER:+str}" ]]; then
echo ""
echo "ERROR: Environment variable 'USER' not set."
echo ""
echo ""

exit 1
else
if [[ -z "${SUDO_USER:+str}" ]]; then
USER_NAME="$USER"
else
USER_NAME="$SUDO_USER"
fi
fi

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.