From 380ada85acda78cc2f3cd5bab577a5fb823da5d8 Mon Sep 17 00:00:00 2001 From: velvettear Date: Thu, 28 Nov 2024 14:02:31 +0100 Subject: [PATCH 1/2] add podman control script --- scripts/podman.sh | 100 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100755 scripts/podman.sh diff --git a/scripts/podman.sh b/scripts/podman.sh new file mode 100755 index 0000000..0abe61a --- /dev/null +++ b/scripts/podman.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env sh + +# author: Daniel Sommer +# license: MIT + +[[ "$(id -u)" != "0" ]] && printf ">> error: permission denied\n" >&2 && exit 1 + +[[ -z "$1" ]] && printf ">> error: action unspecified\n" >&2 && exit 1 + +printf ">> podman control script started!\n\n" + +current="$(pwd)" +what="podman-compose.yml" + +path="$2" +[[ -z "$path" ]] && path="$(dirname $0)" +path="$(realpath $path)" +printf "> looking for '"$what"' files in '"$path"'...\n" +stacks="$(find "$path" -name 'podman-compose.yml')" + +[[ -z "$stacks" ]] && printf ">> error: could not find any files\n" >&2 && exit 1 + +case "$1" in + up|down|restart|upgrade|update) + ;; + *) + printf "error: action '"$1"' unknown\n" >&2 && exit 1 + ;; +esac + +for stack in $stacks; do + dir="$(dirname "$stack")" + name="$(basename "$dir")" + cd "$dir" + case "$1" in + up) + printf "\n>> starting '"$name"'..." + podman-compose up -d &> /dev/null + if [[ "$?" == "0" ]]; then + printf " done!\n" + else + printf " error!\n" + fi + ;; + + down) + printf "\n>> stopping '"$name"'..." + podman-compose down &> /dev/null + if [[ "$?" == "0" ]]; then + printf " done!\n" + else + printf " error!\n" + fi + ;; + + restart) + printf "\n>> restarting '"$name"'..." + podman-compose restart &> /dev/null + if [[ "$?" == "0" ]]; then + printf " done!\n" + else + printf " error!\n" + fi + ;; + + + upgrade|update) + printf "\n>> upgrading '"$name"'...\n" + printf "> stopping '"$name"'..." + podman-compose down &> /dev/null + if [[ "$?" == "0" ]]; then + printf " done!\n" + else + printf " error!\n" + break + fi + printf "> removing image(s)..." + podman image prune -a -f &> /dev/null + if [[ "$?" == "0" ]]; then + printf " done!\n" + else + printf " error!\n" + break + fi + printf "> pulling new image(s) and restarting '"$name"'..." + podman-compose up -d &> /dev/null + if [[ "$?" == "0" ]]; then + printf " done!\n" + else + printf " error!\n" + fi + ;; + esac +done + +cd "$current" + +msg="\n>> podman control script finished" +[[ "$SECONDS" ]] && msg="$msg after "$SECONDS" seconds" +printf "$msg!\n" From a745f5f98f518abef0f3cc9edb64a09e5729de77 Mon Sep 17 00:00:00 2001 From: velvettear Date: Thu, 28 Nov 2024 16:54:14 +0100 Subject: [PATCH 2/2] move podman control script to repository 'compose-stacks' --- scripts/podman.sh | 100 ---------------------------------------------- 1 file changed, 100 deletions(-) delete mode 100755 scripts/podman.sh diff --git a/scripts/podman.sh b/scripts/podman.sh deleted file mode 100755 index 0abe61a..0000000 --- a/scripts/podman.sh +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env sh - -# author: Daniel Sommer -# license: MIT - -[[ "$(id -u)" != "0" ]] && printf ">> error: permission denied\n" >&2 && exit 1 - -[[ -z "$1" ]] && printf ">> error: action unspecified\n" >&2 && exit 1 - -printf ">> podman control script started!\n\n" - -current="$(pwd)" -what="podman-compose.yml" - -path="$2" -[[ -z "$path" ]] && path="$(dirname $0)" -path="$(realpath $path)" -printf "> looking for '"$what"' files in '"$path"'...\n" -stacks="$(find "$path" -name 'podman-compose.yml')" - -[[ -z "$stacks" ]] && printf ">> error: could not find any files\n" >&2 && exit 1 - -case "$1" in - up|down|restart|upgrade|update) - ;; - *) - printf "error: action '"$1"' unknown\n" >&2 && exit 1 - ;; -esac - -for stack in $stacks; do - dir="$(dirname "$stack")" - name="$(basename "$dir")" - cd "$dir" - case "$1" in - up) - printf "\n>> starting '"$name"'..." - podman-compose up -d &> /dev/null - if [[ "$?" == "0" ]]; then - printf " done!\n" - else - printf " error!\n" - fi - ;; - - down) - printf "\n>> stopping '"$name"'..." - podman-compose down &> /dev/null - if [[ "$?" == "0" ]]; then - printf " done!\n" - else - printf " error!\n" - fi - ;; - - restart) - printf "\n>> restarting '"$name"'..." - podman-compose restart &> /dev/null - if [[ "$?" == "0" ]]; then - printf " done!\n" - else - printf " error!\n" - fi - ;; - - - upgrade|update) - printf "\n>> upgrading '"$name"'...\n" - printf "> stopping '"$name"'..." - podman-compose down &> /dev/null - if [[ "$?" == "0" ]]; then - printf " done!\n" - else - printf " error!\n" - break - fi - printf "> removing image(s)..." - podman image prune -a -f &> /dev/null - if [[ "$?" == "0" ]]; then - printf " done!\n" - else - printf " error!\n" - break - fi - printf "> pulling new image(s) and restarting '"$name"'..." - podman-compose up -d &> /dev/null - if [[ "$?" == "0" ]]; then - printf " done!\n" - else - printf " error!\n" - fi - ;; - esac -done - -cd "$current" - -msg="\n>> podman control script finished" -[[ "$SECONDS" ]] && msg="$msg after "$SECONDS" seconds" -printf "$msg!\n"