Blame automation/open_container_shell.sh
|
Packit Service |
5e62f7 |
#! /bin/bash -e
|
|
Packit Service |
5e62f7 |
#
|
|
Packit Service |
5e62f7 |
# Copyright 2019 Red Hat, Inc.
|
|
Packit Service |
5e62f7 |
#
|
|
Packit Service |
5e62f7 |
# This file is part of nmstate
|
|
Packit Service |
5e62f7 |
#
|
|
Packit Service |
5e62f7 |
# This program is free software: you can redistribute it and/or modify
|
|
Packit Service |
5e62f7 |
# it under the terms of the GNU Lesser General Public License as published by
|
|
Packit Service |
5e62f7 |
# the Free Software Foundation, either version 2.1 of the License, or
|
|
Packit Service |
5e62f7 |
# (at your option) any later version.
|
|
Packit Service |
5e62f7 |
#
|
|
Packit Service |
5e62f7 |
# This program is distributed in the hope that it will be useful,
|
|
Packit Service |
5e62f7 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
5e62f7 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
5e62f7 |
# GNU Lesser General Public License for more details.
|
|
Packit Service |
5e62f7 |
#
|
|
Packit Service |
5e62f7 |
# You should have received a copy of the GNU Lesse General Public License
|
|
Packit Service |
5e62f7 |
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
Packit Service |
5e62f7 |
#
|
|
Packit Service |
5e62f7 |
|
|
Packit Service |
5e62f7 |
: ${CONTAINER_CMD:=podman}
|
|
Packit Service |
5e62f7 |
|
|
Packit Service |
5e62f7 |
|
|
Packit Service |
5e62f7 |
container_ps() {
|
|
Packit Service |
5e62f7 |
$CONTAINER_CMD ps --format '{{.ID}} {{.Image}}' | grep nmstate-dev
|
|
Packit Service |
5e62f7 |
}
|
|
Packit Service |
5e62f7 |
|
|
Packit Service |
5e62f7 |
number_of_containers="$(container_ps | wc -l)"
|
|
Packit Service |
5e62f7 |
|
|
Packit Service |
5e62f7 |
if [[ "${number_of_containers}" == "0" ]]
|
|
Packit Service |
5e62f7 |
then
|
|
Packit Service |
5e62f7 |
|
|
Packit Service |
5e62f7 |
echo >/dev/stderr \
|
|
Packit Service |
5e62f7 |
"ERROR: no containers found"
|
|
Packit Service |
5e62f7 |
exit 1
|
|
Packit Service |
5e62f7 |
elif [[ "${number_of_containers}" != "1" ]]
|
|
Packit Service |
5e62f7 |
then
|
|
Packit Service |
5e62f7 |
echo >/dev/stderr \
|
|
Packit Service |
5e62f7 |
"WARNING: ${number_of_containers} of containers found, using first"
|
|
Packit Service |
5e62f7 |
fi
|
|
Packit Service |
5e62f7 |
|
|
Packit Service |
5e62f7 |
container_id="$(container_ps \
|
|
Packit Service |
5e62f7 |
| head -n 1 | cut -d " " -f 1)"
|
|
Packit Service |
5e62f7 |
$CONTAINER_CMD exec -it "${container_id}" /bin/bash
|