0

I'm trying to write a bash function which checks if a package is installed and installs it if needed. Right now it always installs regardless.

install() { echo "checking if $1 is already installed" if [[ ! $(equery -q l $1 | grep -q "$1") ]] then emerge -v $1 else echo "$1 is already installed" fi } install "oracle-jdk-bin" 
  • the output of equery -q l $1 is dev-java/oracle-jdk-bin-1.8.0.45
  • grep should find oracle-jdk-bin and return 1

1 Answer 1

1

What about using the "noreplace" option of emerge?

Description: "Skips the packages specified on the command-line that have already been installed. Without this option, any package atoms or package sets you specify on the command-line will cause Portage to remerge the package, even if it is already installed. Note that Portage will not remerge dependencies by default. This option can be used to update the world file without rebuilding the packages.", taken from https://dev.gentoo.org/~zmedico/portage/doc/man/emerge.1.html

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.