Automatically install package with “apt-get install”, clean exit if it fails

By neokrates, written on July 19, 2010

bash   snippet

Rate it
  • 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
Ad
Poll
  • Your favorite way to manage packages is?

    • Something else (100%, 9 Votes)
    • Tarball command Line (0%, 0 Votes)
    • Debian Dpkg command Line (0%, 0 Votes)
    • Manually (0%, 0 Votes)
    • Synaptic (0%, 0 Votes)
    • Adept (0%, 0 Votes)
    • Apt-get command line (0%, 0 Votes)

    Total Voters: 9

    Vote

    Loading ... Loading ...
Feeds:
  • bodytext bodytext bodytext
Most popular search terms:

apt-get install with some options and scripting results in nice pattern for package installation. For example, this can help to make your script FAI – ready, because this tool is very sensitive to any ‘chaotic’ script output.

What we need:

  1. Function to check the last operation success or die quitOnError
  2. Suppress the apt-get user interaction --force-yes --yes
  3. Suppress any standard output (we only need to know if it worked or not) > /dev/null 2>&1 ;

 
Install the improved random number generator for Linux (rng-tools), clean quit if no install was possible.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/bash
 
function quitOnError {
   if [ $? -gt 0 ]
   then
     echo -e "\n\n $@ ...FAIL"
     exit 10
   else
     echo "$@ ...OK"
   fi
}
 
apt-get install --force-yes --yes rng-tools > /dev/null 2>&1 ;
quitOnError "Installing rng tools now"
 
echo "rng tools installed, /etc/init.d/rng-tools start to increase you
linux system entropy level"
 
Does that help to solve your problem?
VN:F [1.8.5_1061]
Rating: -3 (from 3 votes)
0 votes 'YES'  3 votes 'NO'
TAGS
RELATED
Pages
Posts
    nope :(
SOCIAL
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • BlinkList
  • Blogosphere News
  • E-mail this story to a friend!
  • Furl
  • LinkArena
  • Live
  • MisterWong
  • Print this article!
  • StumbleUpon
  • Technorati
  • Webnews.de
  • YahooMyWeb

Leave a Reply