Skip to content

Check dependency with non-sudo #338

Open

Description

@FranklinYu

I know that I can skip dependency check with --no-install-deps, but I’m proposing the default behavior to be:

  1. Check whether dependencies are satisfied without super-user permission.
  2. If some dependency is missing, install with super-user permission.

This way we can skip unnecessary sudo without breaking any current behavior.

Activity

  1. FranklinYu commented on Mar 19, 2019

    @FranklinYu
    Author

    Affected function:

    function install_packages()
    {
    case "$package_manager" in
    apt) $sudo apt-get install -y "$@" || return $? ;;
    dnf|yum)$sudo $package_manager install -y "$@" || return $? ;;
    port) $sudo port install "$@" || return $? ;;
    pkg) $sudo pkg install -y "$@" || return $? ;;
    brew)
    local brew_owner="$(/usr/bin/stat -f %Su "$(command -v brew)")"
    sudo -u "$brew_owner" brew install "$@" ||
    sudo -u "$brew_owner" brew upgrade "$@" || return $?
    ;;
    pacman)
    local missing_pkgs=($(pacman -T "$@"))
    if (( ${#missing_pkgs[@]} > 0 )); then
    $sudo pacman -S "${missing_pkgs[@]}" || return $?
    fi
    ;;
    zypper) $sudo zypper -n in -l $* || return $? ;;
    "") warn "Could not determine Package Manager. Proceeding anyway." ;;
    esac
    }

    For example with APT we can have

    [ `dpkg -l "$@" | grep ii | wc -l` = $# ]

    In MacPorts

    [ `port installed active "$@" | wc -l` = $(($# + 1)) ]
  2. FranklinYu commented on May 30, 2019

    @FranklinYu
    Author

    Anyone interested in this? I can make PR if this will be reviewed and merged.

  3. FranklinYu commented on Jan 8, 2020

    @FranklinYu
    Author

    Bump. Again, I can make PR.

  4. havenwood commented on Jan 9, 2020

    @havenwood
    Collaborator

    I like the idea but I'm a bit worried about portability with the check for satisfied dependencies. If we could get those where they work reliably, it seems nice to me.

  5. FranklinYu commented on Jan 10, 2020

    @FranklinYu
    Author

    wc -l is POSIX. My use of grep is basic and also POSIX (because no option is used). Actually dpkg -l should only list installed packages, but uninstalled packages with configuration files left over are still counted as “installed packages“.

  6. bloerwald commented on Sep 9, 2020

    @bloerwald

    As a first time user a sudden sudo surely is not what I did expect, and not knowing what is executed feels dangerous. I would love this issue to be addressed (for rpms, you can use rpm -q "${@}" | wc -l).

  7. postmodern commented on Jan 7, 2022

    @postmodern
    Owner

    I think we would need to add a separate function that only checked whether one (or maybe more?) dependencies were already installed? The function would need a similar case/esac statement for each package manager. If we could use the simplest command possible to query whether the package was installed or not (avoiding complex grep/sed parsing) I think that would work.

  8. eloyesp commented on Mar 21, 2022

    @eloyesp

    An alternative would be to list the dependencies as "files", not packages, then checking will never require sudo, and will not depend on the package manager (and will work even with packages installed manually.

  9. FranklinYu commented on Apr 29, 2022

    @FranklinYu
    Author

    @eloyesp I think some dependencies (like libyaml and libffi) are libraries, not executables, so they cannot be searched in “path”. I feel that using package manager itself is still easier.

  10. todd-a-jacobs commented on Sep 18, 2024

    @todd-a-jacobs

    I know that I can skip dependency check with --no-install-deps, but I’m proposing the default behavior to be:

    1. Check whether dependencies are satisfied without super-user permission.
    2. If some dependency is missing, install with super-user permission.

    This way we can skip unnecessary sudo without breaking any current behavior.

    I’d feel better if this leveraged an explicit --use-sudo or --system-deps flag. As a Hombrew user I would rather see a failure without an explicit flag than bork my real system Ruby. For systems that need root privileges to install packages, snaps, or whatever that’s fine, but a silent switch to sudo, especially for those with NOPASSWD is their sudoers, seems like asking for trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions