From 53697da3050d64e9694d0e235b517b4ff01be413 Mon Sep 17 00:00:00 2001 From: LinuxSquare Date: Thu, 11 Jan 2024 19:41:43 +0100 Subject: [PATCH] Add envvar management --- poddoc | 2 +- utils/inspect | 13 +++++++++ utils/podman | 78 --------------------------------------------------- utils/pull | 28 ++++++++++++++++++ utils/start | 29 +++++++++++++++++++ utils/stop | 20 +++++++++++++ 6 files changed, 91 insertions(+), 79 deletions(-) create mode 100644 utils/inspect delete mode 100644 utils/podman create mode 100644 utils/pull create mode 100644 utils/start create mode 100644 utils/stop diff --git a/poddoc b/poddoc index aa43674..fb0d333 100755 --- a/poddoc +++ b/poddoc @@ -1,7 +1,7 @@ #!/usr/bin/env bash # CONSTANTS -readonly PKGVER="0.0.1" +readonly PKGVER="0.1.0" readonly LICENSE="GNU AGPLv3" readonly ROOTPATH="$(dirname $(readlink -f $0))" readonly CONFIG="/usr/local/noveria/etc/poddoc/poddoc.json" diff --git a/utils/inspect b/utils/inspect new file mode 100644 index 0000000..3921f38 --- /dev/null +++ b/utils/inspect @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +function inspectpod() { + if [[ ! -d "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" ]]; then + log e "Podman-directory of ${1} does not exist!" + exit 1 + fi + + echo -e "Container-Name: $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} container.name) +Network: $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} network.name) +Status: $([[ -n $(podman container ls | grep $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} container.name)) ]] && echo -e ${GREEN}Running${RESET} || echo -e ${RED}Stopped${RESET}) +Uptime: ${GREEN}$(podman container ls | grep ${1} | awk '{$1=$1};1' | cut -d' ' -f 7-8)${RESET}" +} diff --git a/utils/podman b/utils/podman deleted file mode 100644 index 84b92a3..0000000 --- a/utils/podman +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env bash - -## -# description: pulls the specified docker-compose.yml from the defined git-repo -# usage: pullpod -## -function pullpod() { - if [[ ! "$(curl -A "poddoc/$PKGVER" -so /dev/null -w %{http_code} $(getValueByKey 'GIT_REPOSITORY')/${1})" =~ 2[0-9]{2} ]]; then - log e "$1 does not exist in remote repository" - exit 1 - fi - - if [[ ! -d "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" ]]; then - git clone "$(getValueByKey 'GIT_REPOSITORY')/${1}.git" "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" - exit 0 - fi - cd "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" - git pull -} - -function inspectpod() { - if [[ ! -d "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" ]]; then - log e "Podman-directory of ${1} does not exist!" - exit 1 - fi - - echo -e "Container-Name: $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} container.name) -Network: $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} network.name) -Status: $([[ -n $(podman container ls | grep $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} container.name)) ]] && echo -e ${GREEN}Running${RESET} || echo -e ${RED}Stopped${RESET}) -Uptime: ${GREEN}$(podman container ls | grep ${1} | awk '{$1=$1};1' | cut -d' ' -f 7-8)${RESET}" -} - -## -# description: starts the defined podman container -# usage: startpod -## -function startpod() { - if [[ ! -d "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" ]]; then - log e "Podman-directory of ${1} does not exist!" - exit 1 - fi - - cd "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" - - # check if network is needed - if [[ -n $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} network.name) ]]; then - local network="$(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} network.name)" - if [[ -z $(podman network ls | grep "$network") ]]; then - podman network create "$network" - fi - fi - - if [[ -n $(podman container ls | grep $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} container.name)) ]]; then - log e "Container $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} container.name) is already running" - exit 1 - fi - - podman-compose up -d -} - -## -# description: stops and deletes the specified podman container -# usage: stoppod -## -function stoppod() { - if [[ ! -d "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" ]]; then - log e "Podman-directory of ${1} does not exist!" - exit 1 - fi - - if [[ -z $(podman container ls | grep $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} container.name)) ]]; then - log e "Container $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} container.name) does not exist!" - exit 1 - fi - - cd "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" - podman-compose down -} diff --git a/utils/pull b/utils/pull new file mode 100644 index 0000000..298edd7 --- /dev/null +++ b/utils/pull @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +## +# description: pulls the specified docker-compose.yml from the defined git-repo +# usage: pullpod +## +function pullpod() { + if [[ ! "$(curl -A "poddoc/$PKGVER" -so /dev/null -w %{http_code} $(getValueByKey 'GIT_REPOSITORY')/${1})" =~ 2[0-9]{2} ]]; then + log e "$1 does not exist in remote repository" + exit 1 + fi + + if [[ ! -d "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" ]]; then + git clone "$(getValueByKey 'GIT_REPOSITORY')/${1}.git" "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" + + if [[ $(getLocalConfValue 'hasEnvVars' ) == true ]]; then + for i in $(getLocalConfValue '.container.envVars[]'); do + read -p "Please enter a value for '$i': " $(echo $i) + export $(echo $i) + sed "s/$(echo $i)/$(echo $i): $(printenv | grep $i | cut -d= -f2)/g" + done + fi + + exit 0 + fi + cd "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" + git pull +} diff --git a/utils/start b/utils/start new file mode 100644 index 0000000..692789f --- /dev/null +++ b/utils/start @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +## +# description: starts the defined podman container +# usage: startpod +## +function startpod() { + if [[ ! -d "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" ]]; then + log e "Podman-directory of ${1} does not exist!" + exit 1 + fi + + cd "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" + + # check if network is needed + if [[ -n $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} network.name) ]]; then + local network="$(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} network.name)" + if [[ -z $(podman network ls | grep "$network") ]]; then + podman network create "$network" + fi + fi + + if [[ -n $(podman container ls | grep $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} container.name)) ]]; then + log e "Container $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} container.name) is already running" + exit 1 + fi + + podman-compose up -d +} diff --git a/utils/stop b/utils/stop new file mode 100644 index 0000000..0168e23 --- /dev/null +++ b/utils/stop @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +## +# description: stops and deletes the specified podman container +# usage: stoppod +## +function stoppod() { + if [[ ! -d "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" ]]; then + log e "Podman-directory of ${1} does not exist!" + exit 1 + fi + + if [[ -z $(podman container ls | grep $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} container.name)) ]]; then + log e "Container $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} container.name) does not exist!" + exit 1 + fi + + cd "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" + podman-compose down +}