]> git.meshlink.io Git - meshlink/blob - test/blackbox/util/install_packages.sh
Update the blackbox test infrastructure.
[meshlink] / test / blackbox / util / install_packages.sh
1 #!/bin/bash
2
3 #    nat.sh - Script to create a NAT using LXC Container
4 #                 Designed to work on unprivileged Containers
5 #    Copyright (C) 2019  Guus Sliepen <guus@meshlink.io>
6 #
7 #    This program is free software; you can redistribute it and/or modify
8 #    it under the terms of the GNU General Public License as published by
9 #    the Free Software Foundation; either version 2 of the License, or
10 #    (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU General Public License for more details.
16 #
17 #    You should have received a copy of the GNU General Public License along
18 #    with this program; if not, write to the Free Software Foundation, Inc.,
19 #    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 # Read command-line arguments
22
23 if [ $# -le 1 ] 
24         then
25         echo "enter valid arguments"
26         exit 1
27 fi
28
29 container=$1    
30 update_cmd="apt-get update -y >> /dev/null"
31 echo "${update_cmd}" | lxc-attach -n ${container} -- 
32
33 while test $# -gt 1
34 do
35     shift
36     pkg_name=$1
37                 install_cmd="apt-get install ${pkg_name} -y >> /dev/null"
38                 echo "${install_cmd}" | lxc-attach -n ${container} -- 
39                 if [ $? -ne 0 ] 
40                 then
41                          echo "${pkg_name} installation failed in ${container} retrying to install again"
42                          sleep 1
43                          echo "${update_cmd}" | lxc-attach -n ${container} -- 
44                          sleep 1
45                          echo "${install_cmd}" | lxc-attach -n ${container} --
46                          if [ $? -ne 0 ] 
47                          then
48                                 echo "${pkg_name} installation failed in ${container} container"
49                                 exit 1
50                          fi
51                 fi
52                 echo "Installed ${pkg_name} in container ${container}"
53 done
54
55 exit 0