From 5d064ae00bba4eb688c244db1bcc1bf9867a8a81 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 31 May 2020 18:31:58 -0500 Subject: [PATCH] updated script descriptions --- bin/pdm-build | 13 +++++++------ bin/pdm-launch | 39 +++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/bin/pdm-build b/bin/pdm-build index 41976b8..e2a34d6 100755 --- a/bin/pdm-build +++ b/bin/pdm-build @@ -1,5 +1,5 @@ #!/bin/bash - +################################################################################ # Functions/variables quit() { if [[ $1 == 0 || $FLAGS_debug == $FLAGS_FALSE ]]; then @@ -16,12 +16,13 @@ source shflags DEFINE_boolean 'squash' false 'squash newly built layers into a single new layer' 's' DEFINE_boolean 'debug' false "Don't delete temporary container on build fail" 'd' DEFINE_string 'tag' 'latest' 'Tag (other than date) to assign to the image' 't' -FLAGS_HELP="Usage: $0 [-s] [-d] [-t tag] [directory] [name] -Builds an image from the Containerfile and (optionally) Systemdfile in a -directory passed as the first argument, and names the image after the second -argument. If no first argument is given, the current working directory is -used. If no second argument is given, the image is named after the directory. +FLAGS_HELP="Usage: $0 [-sd] [-t tag] [directory] [name] + +Builds an image from the Containerfile and (optionally) Systemdfile in the +specified directory, and tags the image with the given name. If no directory +argument is given, the current working directory is used. If no name argument +is given, the image is named after the directory. " FLAGS "$@" || exit $? eval set -- "${FLAGS_ARGV}" diff --git a/bin/pdm-launch b/bin/pdm-launch index fad92fd..f88bba9 100755 --- a/bin/pdm-launch +++ b/bin/pdm-launch @@ -1,28 +1,36 @@ #!/bin/bash - +################################################################################ # Handle flags source shflags DEFINE_boolean 'overwrite' false 'Overwrite container if one with same name already exists.' 'o' -DEFINE_boolean 'config' false "Automatically configure container with deploy options stored in image metadata." 'c' -DEFINE_string 'deployopts' 'deployopts' 'Image metadata label from which to get the deploy options.' 'd' -FLAGS_HELP="Usage: $0 [-o] [-d label] image [name] +DEFINE_boolean 'config' false 'Automatically configure container with deploy options stored in image metadata.' 'c' +DEFINE_string 'label' 'deployopts' 'Image metadata label from which to get the deploy options.' 'l' + +FLAGS_HELP="Usage: $0 [-oc] [-d label] [image] [name] -Creates and starts a container from the specified image. If a second -argument is given, the container name is set to that string. Otherwise, the -container is given the same name as the image. +Creates and starts a container from the specified image, and assigns it the +specified name. If no image argument is given, uses the current working +directory as the name of the image. If no name argument is given, the container +is given the same name as the image. " FLAGS "$@" || exit $? eval set -- "${FLAGS_ARGV}" -if [[ -n $1 ]]; then - image=$1 -else - echo "Error: need image name" +# Handle errors/arguments/cases +if [[ $# -gt 2 ]]; then + echo "Error: too many arguments" echo "" flags_help exit 1 fi +if [[ -n $1 ]]; then + image=$1 +else + echo "Warning: No image name given. Assuming image name from current working directory." + image=$(basename $(pwd)) +fi + if [[ -n $2 ]]; then name=$2 else @@ -30,10 +38,10 @@ else fi if [[ $FLAGS_config == $FLAGS_TRUE ]]; then - echo "Getting deploy options from image metadata label \"$FLAGS_deployopts\" ..." - deployopts=$(podman image inspect -f "{{ .Config.Labels.${FLAGS_deployopts} }}" $image) + echo "Getting deploy options from image metadata label \"$FLAGS_label\" ..." + deployopts=$(podman image inspect -f "{{ .Config.Labels.${FLAGS_label} }}" $image) if [[ $deployopts == "" ]]; then - echo "Error: image metadata label \"$FLAGS_deployopts\" is empty or nonexistent." + echo "Error: image metadata label \"$FLAGS_label\" is empty or nonexistent." exit 2 fi else @@ -44,6 +52,5 @@ if [[ $FLAGS_overwrite ]]; then podman rm -i -f $name fi -podman create --name $name $deployopts $image -podman start $name +podman run -itd --name $name --hostname $name $deployopts $image echo "Done!"