Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check dependency with non-sudo #338

Open
FranklinYu opened this issue Mar 14, 2019 · 9 comments
Open

Check dependency with non-sudo #338

FranklinYu opened this issue Mar 14, 2019 · 9 comments

Comments

@FranklinYu
Copy link

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.

@FranklinYu
Copy link
Author

FranklinYu commented Mar 19, 2019

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)) ]

@FranklinYu
Copy link
Author

FranklinYu commented May 30, 2019

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

@FranklinYu
Copy link
Author

FranklinYu commented Jan 8, 2020

Bump. Again, I can make PR.

@havenwood
Copy link
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.

@FranklinYu
Copy link
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“.

@bloerwald
Copy link

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).

@postmodern
Copy link
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.

@eloyesp
Copy link

eloyesp commented Mar 21, 2022

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.

@FranklinYu
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants