Flux
Flux

Reputation: 10920

raco: How to install a package or update it if it already exists?

raco pkg install <package-name> installs a package if it does not yet exist, and fails if the package already exists. raco pkg update <package-name> updates a package, and fails if the package does not yet exist.

Is there a raco command that combines both commands? In other words, is there a command that can install a package if it does not exist, and also update the package if it already exists?

Rationale: This kind of command would be useful in shell scripting. For example, in Debian/Ubuntu, the apt-get install command has the exact required behaviour, and for python, pip install --upgrade has that too. Is there an equivalent for raco?

Racket version: 6.11

Upvotes: 1

Views: 613

Answers (1)

Metaxal
Metaxal

Reputation: 1113

You can use raco pkg show <package> to detect if a package is installed, for example with something like:

mypkg='memoize'
if [ " [none]" = "$(raco pkg show '$mypkg' | tail -1)" ]; then
  raco pkg install "$mypkg"
else
  raco pkg update "$mypkg"
fi

Upvotes: 0

Related Questions