+#!/bin/bash
+
+# builds a Godot project with all its native export config options
+################################################################################
+# get project
+
+URI_PROJECT_SNAPSHOT=$1
+
+[[ -z "$URI_PROJECT_SNAPSHOT" ]] && echo No URI_PROJECT_SNAPSHOT, exiting && exit 1
+
+echo --------------------------------------------------------------------------------
+echo Getting project - $URI_PROJECT_SNAPSHOT
+
+DIR_BUILD=/build
+DIR_PROJECT_ROOT=/project
+
+# clean project root
+rm -rf $DIR_PROJECT_ROOT/* && \
+ wget $URI_PROJECT_SNAPSHOT && \
+ tar -xf *.tar.gz -C $DIR_PROJECT_ROOT && \
+ rm *.tar.gz
+
+DIR_PROJECT=$(find $DIR_PROJECT_ROOT -type f -name project.godot | sed 's|/project.godot||')
+PROJECT_ID=$(echo $DIR_PROJECT | awk -F/ '{print $NF}')
+
+echo Project directory - $DIR_PROJECT
+
+################################################################################
+# execute project build
+
+DIR_DEBUG=$DIR_BUILD/$PROJECT_ID/debug
+DIR_RELEASE=$DIR_BUILD/$PROJECT_ID/release
+
+GODOT="godot --headless --path $DIR_PROJECT"
+EXPORT_PRESETS_CFG="$DIR_PROJECT/export_presets.cfg"
+
+echo --------------------------------------------------------------------------------
+echo Godot version - $($GODOT --headless --version)
+
+# iterate through all build types present in config file
+# if arg is given, override automated export discovery
+if [[ -n "$2" ]]
+then
+ EXPORT_NAMES=$2
+else
+ EXPORT_NAMES=$(awk -F= '$1=="name"{print $2}' $EXPORT_PRESETS_CFG | sed 's/"//g')
+fi
+
+for EXPORT_NAME in $EXPORT_NAMES
+do
+ echo --------------------------------------------------------------------------------
+ echo Starting project build for export $EXPORT_NAME
+
+ # create build folders
+ [[ -d $DIR_RELEASE/$EXPORT_NAME ]] || mkdir -p $DIR_RELEASE/$EXPORT_NAME
+ [[ -d $DIR_DEBUG/$EXPORT_NAME ]] || mkdir -p $DIR_DEBUG/$EXPORT_NAME
+
+ # get export name from config file
+ EXPORT_FNAME=$(awk -vname=${EXPORT_NAME} -F= \
+ '$1=="name" && $2~name{f=1} f==1 && $1=="export_path"{print $2;exit}' \
+ $EXPORT_PRESETS_CFG | sed -e 's|^.*/||' -e 's/"//g')
+
+ DEBUG_BUILD_PATH=$DIR_DEBUG/$EXPORT_NAME/$EXPORT_FNAME
+ RELEASE_BUILD_PATH=$DIR_RELEASE/$EXPORT_NAME/$EXPORT_FNAME
+
+ ######
+ # do debug and release builds!
+ echo $GODOT --export-debug "$EXPORT_NAME" $DEBUG_BUILD_PATH
+ $GODOT --export-debug "$EXPORT_NAME" $DEBUG_BUILD_PATH
+
+ echo $GODOT --export-release "$EXPORT_NAME" $RELEASE_BUILD_PATH
+ $GODOT --export-release "$EXPORT_NAME" $RELEASE_BUILD_PATH
+
+ ######
+ # zip debug and release builds and shasum them
+ for DIR in $DIR_DEBUG $DIR_RELEASE
+ do
+ ZIP_PATH=$DIR/$EXPORT_NAME
+ echo
+ echo Zipping $ZIP_PATH
+ zip -r $EXPORT_NAME $ZIP_PATH && mv *.zip $DIR
+ done
+done
+
+echo --------------------------------------------------------------------------------
+echo Computing shasums for zip files
+
+for DIR in $DIR_DEBUG $DIR_RELEASE
+do
+ $(cd $DIR && sha1sum *.zip >shasum.txt)
+
+ echo
+ echo SHASUM from $DIR -
+
+ find $DIR -type f -name shasum.txt | xargs cat
+done
+