4

I'm complete noobs in shell script what i want is shell script that determine a list of library/package currently installed if not install them without user permission

What I want is to determine the library/package is currently installed or not in system

I'm aware of aptitude search command but I looking for a better solution

e.g I have define(in shell script) check for readline library/package now how can I from inside the shell script (I want to create) know that readline package is currently installed or not.

Any idea or suggestion would certainly help

tripleee
  • 175,061
  • 34
  • 275
  • 318
Viren
  • 5,812
  • 6
  • 45
  • 98
  • What package manager? What shell? What language? You need to provide details in order to receive help. – Blender May 13 '12 at 03:24
  • Define "library/package". This covers a lot of territory. Also, installing things without user interaction requires root access. – Jim Garrison May 13 '12 at 03:25
  • Technically installing things the normal distribution way, ie, system wide would require root access. Grabbing a private copy from somewhere and storing it under the user's directory for use by a single user/application would not, though I'd personally be unhappy if I wasn't asked to confirm any fetches of remotely sourced binaries. But for something common like readline, I'd think it **much** better to trigger the distribution's packager to supply it. – Chris Stratton May 13 '12 at 04:02
  • @Blender sorry linux(ubuntu) bash shell hope this help – Viren May 13 '12 at 07:34
  • @JimGarrison library/package will be any thing but will be relevant to ruby language i.e compiling dependency for ruby e.g readline or openssl etc – Viren May 13 '12 at 07:41
  • "install them without user permission" -- unlikely, unless you're already root. – glenn jackman May 13 '12 at 13:37
  • @glennjackman that I can manage I have already written script for that for manage permission issue – Viren May 14 '12 at 11:26

4 Answers4

9

What I want is to determine the library/package is currently installed or not in system

dpkg -s does not require root permission, and will display package status details.

Example shell script:

#!/bin/sh

for P; do
    dpkg -s "$P" >/dev/null 2>&1 && {
        echo "$P is installed."
    } || {
        echo "$P is not installed."
    }
done

Usage is:

script.sh package1 package2 .... packageN

Rony
  • 1,674
  • 11
  • 10
  • 2
    **Be careful**: If `dpkg -s` returns `0`, it doesn't necessarily mean that the package is **fully/correctly** installed. `dpkg -s` also returns `0` if the package is in `half-configured` or in `config-files` state (and I guess also in `half-installed`, but I didn't check that). See [the man page of `dpkg`](http://manpages.ubuntu.com/manpages/oneiric/man1/dpkg.1.html) for further "incomplete" states. – Ignitor Jan 17 '14 at 15:12
2

For simply doing the test, it would seem that you could grep the output of a command such as ldconfig -p for your library of interest.

Or you could supply a tiny test program linked against the desired library, try running it, and test for non-failure.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
0

If you are trying to set up a dependency check, the proper solution is to create a dummy package which Depends: on the packages you need to have installed. There is a tool called equivs which somewhat helps with this. (However, it has been criticized as being "over-engineered"; certainly, if you are familiar with the format of Debian packages, you might not need a separate tool if your requirements are this simple.) Then you just install this package and it will pull in the packages which are specified as dependencies.

You still have to know that the library which provides libreadline.so is libreadline5-dev. Debian package search can help find the package names you need to put in Depends:

tripleee
  • 175,061
  • 34
  • 275
  • 318
-1

You can probably do what you want with dpkg

glenn jackman
  • 238,783
  • 38
  • 220
  • 352