78 lines
2.7 KiB
Bash
78 lines
2.7 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
##
|
|
# description: pulls the specified docker-compose.yml from the defined git-repo
|
|
# usage: pullpod <pod-name>
|
|
##
|
|
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 -ne "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)) ]] && ${GREEN} Running ${RESET} || ${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 <pod-name>
|
|
##
|
|
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 <pod-name>
|
|
##
|
|
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
|
|
}
|