X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Fblackbox%2Futil%2Finstall_packages.sh;fp=test%2Fblackbox%2Futil%2Finstall_packages.sh;h=f427b226262842fc88171f512370726927523dbc;hb=1c04402a6d2f3a85d0cb4a5b4a6db5b1f3a79511;hp=0000000000000000000000000000000000000000;hpb=6054182c9e208fd0b3f5c6c90f54cb5af75d3f5c;p=meshlink diff --git a/test/blackbox/util/install_packages.sh b/test/blackbox/util/install_packages.sh new file mode 100755 index 00000000..f427b226 --- /dev/null +++ b/test/blackbox/util/install_packages.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# nat.sh - Script to create a NAT using LXC Container +# Designed to work on unprivileged Containers +# Copyright (C) 2019 Guus Sliepen +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Read command-line arguments + +if [ $# -le 1 ] + then + echo "enter valid arguments" + exit 1 +fi + +container=$1 +update_cmd="apt-get update -y >> /dev/null" +echo "${update_cmd}" | lxc-attach -n ${container} -- + +while test $# -gt 1 +do + shift + pkg_name=$1 + install_cmd="apt-get install ${pkg_name} -y >> /dev/null" + echo "${install_cmd}" | lxc-attach -n ${container} -- + if [ $? -ne 0 ] + then + echo "${pkg_name} installation failed in ${container} retrying to install again" + sleep 1 + echo "${update_cmd}" | lxc-attach -n ${container} -- + sleep 1 + echo "${install_cmd}" | lxc-attach -n ${container} -- + if [ $? -ne 0 ] + then + echo "${pkg_name} installation failed in ${container} container" + exit 1 + fi + fi + echo "Installed ${pkg_name} in container ${container}" +done + +exit 0