#!/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 "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" 'container.hasEnvVars' ) == true ]]; then for i in $(getLocalConfValue "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" 'container.envVars[]'); do read -p "Please enter a value for '$i': " $(echo $i) export $(echo $i) sed -i "s/\b$(echo $i):\b/$(echo $i): $(printenv | grep $i | cut -d= -f2)/g" "$(getValueByKey 'PODMAN_DIRECTORY')/${1}/docker-compose.yml" done fi if [[ $(getLocalConfValue "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" 'container.hasServiceIPs') == true ]]; then local section=$(sed ''"$(cat $(getValueByKey 'PODMAN_DIRECTORY')/${1}/docker-compose.yml | nl -ba | grep %% $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} 'container.name') start %% | awk '{print $1}')"','"$(cat $(getValueByKey 'PODMAN_DIRECTORY')/${1}/docker-compose.yml | nl -ba | grep %% $(getLocalConfValue $(getValueByKey 'PODMAN_DIRECTORY')/${1} 'container.name') end %% | awk '{print $1}')"'!d' "$(getValueByKey 'PODMAN_DIRECTORY')/${1}/docker-compose.yml") local hasPorts=$(echo "$section" | grep "ports") if [[ -z "$hasPorts" ]]; then sed -i "/^$(echo "$section" | tail -n1)/i\ \ \ \ ports:" "$(getValueByKey 'PODMAN_DIRECTORY')/${1}/docker-compose.yml" fi for serviceIP in $(getLocalConfValue "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" 'container.serviceIPs[]'); do if [[ -z $(echo "$section" | grep "$serviceIP") ]]; then sed "/^$(echo "$section" | tail -n1)/i\ \ \ \ \ \ - $serviceIP" "$(getValueByKey 'PODMAN_DIRECTORY')/${1}/docker-compose.yml" fi done fi exit 0 fi cd "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" git pull }