Created
October 21, 2020 19:10
-
-
Save udoyen/33052407c536650599c26cc8fae1cd84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# start the gcloud command | |
# change the case of the command option | |
task=$(echo $1 | tr '[:upper:]' '[:lower:]') | |
# catch user input and check for validity | |
if [ $# -ne 2 ] | |
then | |
echo " " | |
echo "Two command line arguments are required ... " | |
echo " " | |
echo "The COMMAND (start or stop) and the name of the CONTAINER" | |
echo " " | |
echo "Command format ... pd-gcloud (COMMAND CONTAINER_NAME) ..." | |
exit 1 | |
else | |
if [[ $1 == "stop" ]] || [[ $1 == "start" ]]; | |
then | |
# check that such a container exists | |
if [ -z $(podman container inspect "$2" --format "{{.Name}}" 2> /dev/null) ]; | |
then | |
echo " " | |
echo "A container with that name does not exist!"; | |
echo " " | |
echo "Please create the container first!" | |
exit 1 | |
else | |
if [[ $1 =~ start ]] | |
then | |
# check if the container is not running | |
if [[ ! running =~ $(podman container inspect $2 --format "{{.State.Status}}") ]] | |
then | |
# start the container and open an interactive session | |
# with the container | |
podman container start "$2" && podman exec -it "$2" bash | |
else | |
# If container is already running inform the user | |
echo "The container is already running ..." | |
echo " " | |
podman exec -it "$2" bash | |
fi | |
fi | |
if [[ $1 =~ stop ]] | |
then | |
# check if the container is running | |
if [[ running =~ $(podman container inspect $2 --format "{{.State.Status}}") ]] | |
then | |
# stop the container | |
podman container stop "$2" | |
else | |
echo " " | |
echo "The container isn't running ..." | |
echo " " | |
echo "To start run 'pd-gcloud start' ..." | |
exit 1 | |
fi | |
fi | |
fi | |
else | |
echo " " | |
echo "Two command line arguments are required ... " | |
echo " " | |
echo "The COMMAND (start or stop) and the name of the CONTAINER" | |
echo " " | |
echo "Command format ... pd-gcloud (COMMAND CONTAINER_NAME) ..." | |
exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment