diff --git a/build.sh b/build.sh index 96f5687..a4d7ad9 100755 --- a/build.sh +++ b/build.sh @@ -95,6 +95,7 @@ get_parameters() { if [[ -z $FOUNDRY_URL ]]; then echo "Need the foundry URL, please try again..." + latest_stable_foundry exit 1 fi @@ -125,7 +126,7 @@ get_parameters() { fi if [[ -z $OPT_VERSION ]]; then - OPT_VERSION="12.331" + OPT_VERSION="latest" fi if [[ "${OPT_SCHEDULED}" == "TRUE" ]]; then @@ -143,6 +144,9 @@ TAG="$OPT_VERSION" # Build Functions container_initialize() { + if [[ "$OPT_VERSION" == "latest" ]]; then + OPT_VERSION="${STABLE[0]}" + fi echo "Initializing container build..." podman login ${REGISTRY} podman build -f ${OPT_CONTAINERFILE} -t ${REGISTRY}/${REGISTRY_NAMESPACE}:${TAG} -t ${REGISTRY}/${REGISTRY_NAMESPACE}:latest --build-arg foundry_url=${FOUNDRY_URL} --build-arg nodejs_version=${NODEJS_VERSION} @@ -154,7 +158,7 @@ container_initialize() { container_scheduled_build() { echo "Scheduled build starting..." - if [[ "${CADDY_IMAGE_VERSION}" != "${CUSTOM_CADDY_IMAGE_VERSION}" ]]; then + if [[ "${CADDY_IMAGE_VERSION}" != "${STABLE[0]}" ]]; then podman login ${REGISTRY} podman build -f ${OPT_CONTAINERFILE} -t ${REGISTRY}/${REGISTRY_NAMESPACE}:${TAG} -t ${REGISTRY}/${REGISTRY_NAMESPACE}:latest --build-arg foundry_url=${FOUNDRY_URL} podman push ${REGISTRY}/${REGISTRY_NAMESPACE}:${TAG} @@ -177,11 +181,23 @@ container_rebuild() { echo "Rebuild complete!" } +latest_stable_foundry() { + RELEASES=" $(curl https://foundryvtt.com/releases/)" + for i in $( echo "${RELEASES}" | cut -d "=" -f 3 | grep Release | cut -d " " -f 2 | grep -v class | sort -nr); do + if [[ $(echo "${RELEASES}" | grep -A 6 "${i}" | grep -i stable) ]]; then + STABLE+=(${i}) + fi + done + echo "Latest stable is: ${STABLE[0]}" +} + ############################################################################################################################### # Main Script ############################################################################################################################### get_parameters "$@" +latest_stable_foundry + if [[ "$OPT_SCHEDULED" == "TRUE" ]]; then container_scheduled_build fi