Second Commit

This commit is contained in:
Andrew Hurley 2023-02-26 20:40:31 +08:00
parent e5b04002a1
commit e58c78bae3
1 changed files with 107 additions and 96 deletions

View File

@ -6,20 +6,28 @@ set -u
set -e set -e
# --------------------------------------------------------- usage # --------------------------------------------------------- usage
COMMANDS="restore|backup|create|run|stop|remove|clean|start"
usage () { usage () {
printf "Usage: podmanctl [${COMMANDS}] [<options>] <project> [<project>...]\n" printf "Usage:\n"
printf " podmanctl [<options>] <project> [<project>...]\n"
printf " - command is assumed to be 'run'\n"
printf " podmanctl [${COMMANDS}] [<options>] <project> [<project>...]\n"
printf " Options:\n" printf " Options:\n"
printf " -e <additional_environment_vars>\n" printf " -e <additional_environment_vars>\n"
} }
# --------------------------------------------------------- command # --------------------------------------------------------- command
COMMANDS="restore|backup|create|run|stop|remove|clean|start" if [[ $# -lt 1 ]]; then
printf "Arguments missing\n"
usage
exit 2
fi
if [[ "$1" =~ ^(${COMMANDS})$ ]]; then if [[ "$1" =~ ^(${COMMANDS})$ ]]; then
COMMAND="${1}" COMMAND="${1}"
shift shift
else else
COMMAND="project" COMMAND="run"
fi fi
# --------------------------------------------------------- args # --------------------------------------------------------- args
@ -38,15 +46,15 @@ if [[ $# -lt 1 ]]; then
usage usage
exit 2 exit 2
fi fi
# --------------------------------------------------------- project loop
for PROJECT in $*; do for PROJECT in $*; do
echo $PROJECT
if [[ ! -r ${PROJECT} ]]; then if [[ ! -r ${PROJECT} ]]; then
printf "Project spec file '${PROJECT}' missing or not readable. Skipping\n" printf "Project spec file '${PROJECT}' missing or not readable. Skipping\n"
continue continue
fi fi
exit
# --------------------------------------------------------- project vars # --------------------------------------------------------- project vars
RUNTIME="podman" RUNTIME="podman"
ROOTDIR="$(realpath /root)" ROOTDIR="$(realpath /root)"
@ -67,6 +75,10 @@ if [[ ! "$(stat -L -c "%A" "${ROOTDIR}" |cut -c8-10 )" = "---" ]] then
exit 3; exit 3;
fi fi
printf -- \
"--------------------------------------------------------- \
${PROJECT} ${COMMAND}\n"
# --------------------------------------------------------- stop pod service # --------------------------------------------------------- stop pod service
systemctl list-units --full -all \ systemctl list-units --full -all \
|grep -Fq "podman-${PODNAME}.service" \ |grep -Fq "podman-${PODNAME}.service" \
@ -137,5 +149,4 @@ source ${PROJECT}
) && systemctl daemon-reload \ ) && systemctl daemon-reload \
&& systemctl enable podman-${PODNAME} && systemctl enable podman-${PODNAME}
done done