pms-cli/utils/start
2024-01-05 23:13:10 +01:00

49 lines
1.8 KiB
Bash

#!/usr/bin/env bash
function start() {
if [[ ! -d "$(getValueByKey 'PODMAN_DIRECTORY')/${1}" ]]; then
log e "Directory '${1}' does not exist"
exit 1
fi
if [[ -z "$2" ]]; then
log e "You have to specify a port, on which the server listens!"
exit 1
fi
local dir="$(getValueByKey 'PODMAN_DIRECTORY')/${1}"
local software="$(getLocalConfValue $dir 'software')"
local version="$(getLocalConfValue $dir 'version')"
local build="$(getLocalConfValue $dir 'build')"
case "$(getLocalConfValue $dir 'type')" in
"server")
local software_url="$(getValueByKey SERVERRUNNERS.${software})"
;;
"proxy")
local software_url="$(getValueByKey PROXYRUNNERS.${software})"
;;
esac
if [[ $(checkImage "$software" "$version" "$build") == false ]]; then
log i "Building image '$version/$software:$build'"
buildImage "$software" "$version" "$build" "$software_url/versions/$version/builds/$build"
else
if [[ "$(getLocalConfValue $dir 'release')" == "latest" ]]; then
if [[ $(checkUpdate "$software" "$version" "$build" "$(getLocalConfValue $dir 'type')") == true ]]; then
log w "Update for '$software/$version:$build' is available."
updateBuild "$software" "$version" "$dir" "$(getLocalConfValue $dir 'type')"
local oldbuild="$build"
build="$(getLocalConfValue $dir 'build')"
if [[ $(checkImage "$software" "$version" "$build") == false ]]; then
log i "Updating image '$version/$software:$oldbuild' => '$version/$software:$build'"
buildImage "$software" "$version" "$build" "$software_url/versions/$version/builds/$build"
fi
fi
fi
fi
log i "Starting container '$1' with image '$version/$software:$build' on port '$2'"
startContainer "$1" "$version/$software:$build" "$2"
}