0

I need to Bash script which will install few packages. For Example: I need install packages: Molecule and Ansible

Bash script should do it and I need it for Ubuntu/Debian:

If Molecule exist > print "Molecule Installed"
else
apt-get install Molecule
then
if Ansible exist > print "Ansible installed"
else
apt-get install Ansible

Can you tell me how will look script in bash, which will contain the above instructions?

Thank you in advance!

BElluu
  • 203

2 Answers2

3

You don't really need such script. Whenever, you attempt to install a package that is already installed, apt will output <pkg-name> is already the newest version. string. You can see an example of that here:

$ sudo apt-get install python3-numpy
[sudo] password for ubuntuadmin: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-numpy is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 323 not upgraded.
$

Thus your problem reduces to simply using apt command itself to install multiple packages

sudo apt-get install molecule ansible 
2

Open the terminal and type:

apt policy molecule ansible  

The output is self-explanatory. It will be similar to this example:

$ apt policy molecule ansible
ansible:
  Installed: 2.5.1+dfsg-1
  Candidate: 2.5.1+dfsg-1
  Version table:
 *** 2.5.1+dfsg-1 500
        500 http://archive.ubuntu.com/ubuntu/pub/ubuntu bionic/universe amd64 Packages
        500 http://archive.ubuntu.com/ubuntu/pub/ubuntu bionic/universe i386 Packages
        100 /var/lib/dpkg/status
N: Unable to locate package molecule
karel
  • 122,292
  • 133
  • 301
  • 332