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

By neokrates, written on July 19, 2010

bash   snippet

  • Join date: 11-30-99
  • Posts: 224
View Counter:
  • 306 views
Rate it
Ad
Poll
  • What new build tool would you consider as Ant replacement?

    View Results

    Loading ... Loading ...
Feeds:
  • bodytext bodytext bodytext

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"
Be Sociable, Share!
 
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
SOCIAL
Be Sociable, Share!

Leave a Reply