Dpkg: check that unix package is installed. Bash script: install package if not presentBy neokrates, written on May 21, 2010 |
howto |
- neokrates
- Email: uwarov@yahoo.com
- Website: http://www.thinkplexx.com
- Join date: 05-31-09
- Posts: 20
Rate it
Ad
Poll
Best shells (or command line language) are?
- Bash (47%, 9 Votes)
- Different shell (21%, 4 Votes)
- Zsh (21%, 4 Votes)
- Csh (11%, 2 Votes)
- Power shell (5%, 1 Votes)
- Ksh (5%, 1 Votes)
- Lush (0%, 0 Votes)
- Quicksilver (0%, 0 Votes)
- IPython (0%, 0 Votes)
- Rush (0%, 0 Votes)
- Pash (0%, 0 Votes)
- Dos cl (0%, 0 Votes)
- Fish shell (0%, 0 Votes)
Total Voters: 19
Loading ...
Most popular search terms:
Was the package already installed or it still needs to be?
Software:
Ubuntu *
dpkg -s can be used.
Example: is libasound installed?
> dpkg -s libasound2|grep installed
Here is some logic in bash script, like installing package if it is not there:
1 2 3 4 5 6 | problem=$(dpkg -s xulrunner-1.9|grep installed) echo Checking for libxul: $problem if [ "" == "$problem" ]; then echo "No libxul. Setting up libxul" sudo apt-get --force-yes --yes install xulrunner-1.9 fi |
|
LEARN MORE (amazon bookstore)
|
|
TAGS
|
|
SOCIAL
|
|
INCOMING SEARCH TERMS
|



















after some debugging and testing i’ve reached this function
<code>
function dpkgstatins {
echo "checking if $dpkgof is installed" 2>&1 if [[ $(dpkg-query -f'${Status}' --show $dpkgof 2>/dev/null) = *\ installed ]]; then echo "$dpkgof found!" else echo "$dpkgof was not found, installing..." 2>&1 apt-get --force-yes -yqq install $dpkgof 2>/dev/null fi}
</code>
this function needs $dpkgof defined as the package
Like or Dislike:
0
0
nice.
Like or Dislike:
0
0
[...] And one other method on package checking: http://www.thinkplexx.com/learn/howto/linux/packaging/dpkg-check-that-unix-package-is-installed-exam... [...]
Like or Dislike:
0
0
Isn’t your argument telling it to install the program if the program is already installed…? I think you mixed up the operators and want != instead of ==. To say if it’s NOT equal, to THEN install.
And why did you put it as a variable? Couldn’t it be better written this way?
echo “Checking for libxul…”
if ! dpkg -s xulrunner-1.9 | grep installed
then
echo “No libxul. Setting up libxul…”
sudo apt-get –force-yes –yes install xulrunner-1.9
fi
Like or Dislike:
0
0
problem=$(dpkg -s xulrunner-1.9|grep installed) will be “” if package is NOT installed, like:
Package: xulrunner-1.9
Essential: yes
Status: install ok installed
Priority: required
…
Then, if package is NOT installed, we proceed with installation:
if [ "" == "$problem" ]; then
fi
I don’t think that your form is much better, I would rather say it is alternative.
Both forms miss some readability I think. If it is harder to read, it s harder to maintain, especially by many peers.
I would prefer to rename $problem to $is_installed and use my form, because it is easy to read then:
is_installed=$(dpkg -s xulrunner-1.9|grep installed)
Like or Dislike:
0
0
I was searching for this today and found the following solution before reaching your blog:
dpgk-query will return 1 if the package is not found, and grep will also return 1 if the package is not installed
Like or Dislike:
0
0
Hi zimbatm,
thank you for posting. Gonna test your snippet.
Like or Dislike:
0
0
must check for less
Like or Dislike:
0
0