1

i got idea form the link (How do I write an application install shell script?) and started to wrtie script for installing software in ubunt automatically. But in case if the software does not install properly, I want my script should exit saying it does not install properly or at last it should give summary that which software does not install properly. How can I achive this?

Below is my script that I started to write:

apt-get update
apt-get install -f 
for software in vim linphone linphone-common linphone-nox git dpkg-dev
do 
    apt-get install $software -y
done
ramkrishna
  • 115
  • 6

1 Answers1

0

APT returns a non-zero value when the installation fails.
The return value of the apt is stored in the global variable $? We can use that variable to detect installation failures. Eg:

sudo apt-get update

for software in vim linphone linphone-common linphone-nox git dpkg-dev
do 
   sudo apt-get install $software -y

   if [ $? -ne 0 ]  #If apt returns an error, do the following...
   then
       echo "ERROR($?):Failed to install $software"
       echo "Exiting installation..."
       break
   fi 
done
Naveen
  • 9,365
  • 11
  • 43
  • 70