]> Untitled Git - godot.git/blob - script.sh
Added arg override for export name
[godot.git] / script.sh
1 #!/bin/bash
2
3 # gets a Godot release, fetches export templates, 
4 # and builds a project with its native export options
5
6 ################################################################################
7 PWD=`pwd`
8 DIR_DOWNLOAD=$PWD/download
9 DIR_TEMPLATES=$DIR_DOWNLOAD/templates
10 DIR_DEBUG=$PWD/debug
11 DIR_RELEASE=$PWD/release
12 DIR_PROJECT=$PWD/project
13
14 GODOT_VERSION=4.4-stable
15 GODOT_ZIP=Godot_v${GODOT_VERSION}_linux.x86_64.zip
16 GODOT_EXE=Godot_v${GODOT_VERSION}_linux.x86_64
17 GODOT_URI=https://github.com/godotengine/godot/releases/download/$GODOT_VERSION/$GODOT_ZIP
18
19 GODOT_EXPORT_TEMPLATES=Godot_v${GODOT_VERSION}_export_templates.tpz
20 GODOT_TEMPLATE_URI=https://github.com/godotengine/godot/releases/download/$GODOT_VERSION/$GODOT_EXPORT_TEMPLATES
21
22 GODOT=$DIR_DOWNLOAD/$GODOT_EXE
23
24 ################################################################################
25 # get Godot
26
27 [[ -d $DIR_DOWNLOAD ]] || mkpath -p $DIR_DOWNLOAD 
28 [[ -f $DIR_DOWNLOAD/$GODOT_ZIP ]] || wget -P $DIR_DOWNLOAD $GODOT_URI
29 [[ -f $DIR_DOWNLOAD/$GODOT_EXE ]] || unzip $DIR_DOWNLOAD/$GODOT_ZIP -d $DIR_DOWNLOAD
30
31 echo Godot version - $($GODOT --headless --version)
32
33 ################################################################################
34 # get export templates
35
36 [[ -f $DIR_DOWNLOAD/$GODOT_EXPORT_TEMPLATES ]] || wget -P $DIR_DOWNLOAD $GODOT_TEMPLATE_URI
37 [[ -d $DIR_TEMPLATES ]] || unzip -d $DIR_DOWNLOAD $DIR_DOWNLOAD/$GODOT_EXPORT_TEMPLATES
38
39 GODOT_TEMPLATE_VERSION=$(cat $DIR_TEMPLATES/version.txt)
40 LOCAL_TEMPLATES=$HOME/.local/share/godot/export_templates/$GODOT_TEMPLATE_VERSION
41 if [[ ! -d $LOCAL_TEMPLATES ]]
42 then
43     mkdir -p $LOCAL_TEMPLATES
44     cp $DIR_TEMPLATES/* $LOCAL_TEMPLATES
45     # TODO: leaves extra copy of templates
46 fi
47
48 echo Godot export template version - $GODOT_TEMPLATE_VERSION
49 echo Local templates - $LOCAL_TEMPLATES
50
51 ################################################################################
52 # execute project build
53
54 # iterate through all build types present in config file
55 EXPORT_PRESETS_CFG=$DIR_PROJECT/export_presets.cfg
56 GODOT_OPTS="--headless --path $DIR_PROJECT"
57
58 # if arg is given, override automated export discovery
59 if [[ -n "$1" ]]
60 then
61     EXPORT_NAMES=$1
62 else
63     EXPORT_NAMES=$(awk -F= '$1=="name"{print $2}' $EXPORT_PRESETS_CFG | sed 's/"//g')
64 fi
65
66 for EXPORT_NAME in $EXPORT_NAMES
67 do
68     echo
69     echo Starting project build for export $EXPORT_NAME
70
71     # create build folders
72     [[ -d $DIR_RELEASE/$EXPORT_NAME ]] || mkdir -p $DIR_RELEASE/$EXPORT_NAME
73     [[ -d $DIR_DEBUG/$EXPORT_NAME ]] || mkdir -p $DIR_DEBUG/$EXPORT_NAME
74
75     # get export name from config file
76     EXPORT_FNAME=$(awk -vname=${EXPORT_NAME} -F= \
77         '$1=="name" && $2~name{f=1} f==1 && $1=="export_path"{print $2;exit}' \
78         $EXPORT_PRESETS_CFG | sed -e 's|^.*/||' -e 's/"//g')
79
80     # do build!
81     echo $GODOT $GODOT_OPTS --export-debug "$EXPORT_NAME" $DIR_DEBUG/$EXPORT_NAME/$EXPORT_FNAME
82     $GODOT $GODOT_OPTS --export-debug "$EXPORT_NAME" $DIR_DEBUG/$EXPORT_NAME/$EXPORT_FNAME
83     echo $GODOT $GODOT_OPTS --export-release "$EXPORT_NAME" $DIR_RELEASE/$EXPORT_NAME/$EXPORT_FNAME
84     $GODOT $GODOT_OPTS --export-release "$EXPORT_NAME" $DIR_RELEASE/$EXPORT_NAME/$EXPORT_FNAME
85 done