This repository has been archived by the owner on Oct 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgodot
executable file
·477 lines (404 loc) · 11.7 KB
/
godot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
#!/bin/bash
#--------------------------------------------------------------------------#
# A simple script to properly install the Godot game engine on Ubuntu and also
# provide version management.
# Copyright (C) 2015 Niklas Rosenqvist
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA
#--------------------------------------------------------------------------#
if [ -h "$0" ]; then
appdir="$(dirname "$(readlink -f "$0")")"
else
appdir="$(cd "$(dirname "$0")" && pwd)"
fi
prevpwd="$(pwd)"
cd "$appdir"
applauncher="$appdir/godot.desktop"
appscript="$appdir/$(basename "$0")"
repo="https://github.com/godotengine/godot.git"
json_releases=""
if [ "$(uname -m)" = "x86_64" ]; then
arch="x64"
else
arch="x86"
fi
function write_launcher() {
echo "$1" >> $applauncher
}
function pad_string() {
printf "%-${2}s" "$1"
}
function take_if_higher() {
local oldval=$1
local newval=$2
local saveto="$3"
if [ $newval -gt $oldval ]; then
eval "$saveto=$2"
fi
}
function install_dependencies() {
if [[ ! -z $(which dnf) ]]; then
dnf install -y scons pkgconfig libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel \
libXi-devel mesa-libGL-devel alsa-lib-devel pulseaudio-libs-devel freetype-devel openssl-devel \
libudev-devel mesa-libGLU-devel
elif [[ ! -z $(which apt-get) ]]; then
apt-get install -y build-essential scons pkg-config libx11-dev libxcursor-dev libxinerama-dev \
libgl1-mesa-dev libglu-dev libasound2-dev libpulse-dev libfreetype6-dev libssl-dev libudev-dev \
libxi-dev libxrandr-dev
elif [[ ! -z $(which pacman) ]]; then
pacman -S scons libxcursor libxinerama libxi libxrandr mesa glu alsa-lib pulseaudio freetype2
elif [[ ! -z $(which zypper) ]]; then
zypper install scons pkgconfig libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel \
libXi-devel Mesa-libGL-devel alsa-devel libpulse-devel freetype-devel openssl-devel \
libudev-devel libGLU1
elif [[ ! -z $(which eopkg) ]]; then
eopkg install -c system.devel scons libxcursor-devel libxinerama-devel libxi-devel \
libxrandr-devel mesalib-devel libglu alsa-lib pulseaudio freetype2-devel pulseaudio-devel
else
echo "Error! Unsupported package management system. Find how to install the dependencies on your distribution here: https://godot.readthedocs.io/en/latest/development/compiling/compiling_for_x11.html"
exit 1;
fi
return $?
}
function create_launcher() {
if [ ! -f "$applauncher" ]; then
touch "$applauncher"
write_launcher "[Desktop Entry]"
write_launcher "Name=Godot Engine"
write_launcher "Comment=Multi-platform 2D and 3D game engine with a feature rich editor"
write_launcher "GenericName=Libre game engine"
write_launcher "Exec=bash \"$appscript\""
write_launcher "Terminal=false"
write_launcher "X-MultipleArgs=false"
write_launcher "Type=Application"
write_launcher "Icon=$appdir/icon.png"
write_launcher "Categories=Development;IDE;"
write_launcher "StartupNotify=true"
fi
}
## Actions
function helptext() {
local padding=32
echo -e "\nGodot - Usage: ${0##*/} [action] [optional arguments]"
echo -e "Running Godot without any of the specified arguments will launch the GUI.\n"
echo "Actions:"
echo -e "\t$(pad_string "<dependencies>" $padding) Install dependencies"
echo -e "\t$(pad_string "<install> [version]" $padding) Install Godot"
echo -e "\t$(pad_string "<uninstall> [version]" $padding) Uninstall Godot"
echo -e "\t$(pad_string "<use> <version>" $padding) Set which version to use"
echo -e "\t$(pad_string "<update>" $padding) Update Godot to latest stable version"
echo -e "\t$(pad_string "<download|refresh>" $padding) Download or update Godot repository"
echo -e "\t$(pad_string "<help>" $padding) Bring up the help message"
echo -e "\t$(pad_string "<releases> [status] [local]" $padding) Lists all releases in a detailed table. \"local\" skips updating the git repo before showing the list."
echo -e "\t$(pad_string " - all [local]" $padding) Only outputs a list, and not a table."
echo -e "\t$(pad_string " - installed [local]" $padding) Only outputs installed releases."
echo -e "\t$(pad_string " - available [local]" $padding) Only outputs releases that haven't been installed yet."
echo -e "\t$(pad_string "<version>" $padding) Show current active release."
echo -e "\t$(pad_string "[*]" $padding) Launch Godot (unmatched arguments will be passed along to the Godot binary)"
return 0
}
function releases() {
local norefresh=1
local i
# Check whether to skip updating the Godot repo
if [ "${1,,}" != "local" ]; then
if [ "${2,,}" != "local" ]; then
download
fi
fi
case "${1,,}" in
# List all available versions
all)
for i in $(cd "$appdir/source" && git tag); do
echo "$i"
done
echo "master"
return 0
;;
# List all installed version
installed)
installed
return $?
;;
# List all not yet installed versions
available)
for i in $(releases "all" "local"); do
is_installed "$i"
if [ $? -ne 0 ]; then
echo "$i"
fi
done
return 0
;;
# Output a table showing detailed version information
*)
local maxlen=0
local installed=""
local active=""
local versions=($(cd "$appdir/source" && git tag))
versions+=("master")
for i in ${versions[@]}; do
take_if_higher $maxlen ${#i} "maxlen"
done
maxlen=$(($maxlen+4))
echo -n "$(pad_string "Version:" $maxlen)"
echo -n "$(pad_string "Installed:" 14)"
echo "$(pad_string "Active:" 11)"
for i in "${versions[@]}"; do
# Version
echo -n "$(pad_string "$i" $maxlen)"
# Installed
is_installed "$i"
if [ $? -eq 0 ]; then
installed="yes"
else
installed=""
fi
echo -n "$(pad_string "$installed" 14)"
# Active
is_active "$i"
if [ $? -eq 0 ]; then
active="yes"
else
active=""
fi
echo "$(pad_string "$active" 11)"
done
;;
esac
return 0
}
function version() {
if [ -h "godot-engine" ]; then
local filename="$(basename "$(readlink -f "$appdir/godot-engine")")"
echo "${filename#*_}"
fi
}
function download() {
if [ ! -d "$appdir/source" ]; then
git clone "$repo" "$appdir/source"
chmod -R 755 "$appdir"
else
cd "$appdir/source" && git stash save --quiet && git stash drop &>/dev/null && git pull --quiet && cd "$appdir"
fi
}
function is_installed() {
local i
for i in $(installed); do
if [ "$1" = "$i" ]; then
return 0
fi
done
return 1
}
function is_active() {
if [ "$(basename "$(readlink -f "$appdir/godot-engine")")" = "godot-engine_${1}" ]; then
return 0
fi
return 1
}
function installed() {
local file
for file in $(ls "$appdir/releases"); do
local filename="$(basename "$file")"
if [[ "$filename" == "godot-engine_"* ]]; then
local version="${filename#*_}"
echo "$version"
fi
done
}
function is_tag() {
local tag
if [ "$1" = "master" ] || [ "$1" = "dev" ]; then
return 0
fi
for tag in $(cd "$appdir/source" && git tag); do
if [ "$tag" = "$1" ]; then
return 0
fi
done
return 1
}
function get_latest_stable() {
local tags=($(cd "$appdir/source" && git tag))
local latest_stable="1.0-stable"
local idx
for (( idx=${#tags[@]}-1 ; idx>=0 ; idx-- )) ; do
if [[ $string == *"stable"* ]]; then
latest_stable="${tags[idx]}"
break
fi
done
echo "$latest_stable"
}
function get_tag() {
if [ "$1" = "dev" ] || [ "$1" = "master" ]; then
echo "master"
else
# Check that it's a tag
is_tag "$1"
if [ $? -eq 0 ]; then
echo "$1"
fi
# Return latest stable
echo "$(get_latest_stable)"
fi
}
function install() {
# Make sure repo is up to date
download
# Get version to install
local tag="$(get_tag "$1")"
is_installed "$tag"
if [ $? -eq 0 ]; then
echo "$tag is already installed."
return 1
fi
# Start installation
echo "Installing Godot $tag..."
# Build Godot
cd "$appdir/source" && git checkout $1 && scons platform=x11
local result=$?
cd "$appdir"
if [ $result -ne 0 ]; then
echo "Error while building!"
return 1
fi
mv "$appdir/source/bin/godot.x11.tools.64" "$appdir/releases/godot-engine_${tag}"
chmod -R 755 "$appdir/releases"
chmod +x "$appdir/releases/"*
use "$tag"
chmod +x "$appscript"
# Launcher
if [ ! -f "$applauncher" ]; then
create_launcher
fi
if [ ! -h /usr/share/applications/godot.desktop ]; then
sudo ln -s "$applauncher" /usr/share/applications/godot.desktop
fi
# Executable
if [ ! -h /usr/local/bin/godot ]; then
sudo ln -s "$appscript" /usr/local/bin/godot
fi
# Bash completion
if [ ! -h /etc/bash_completion.d/godot ]; then
sudo ln -s "$appdir/bash_completion.d/godot" /etc/bash_completion.d/godot
fi
chmod -R 755 "$appdir"
return 0
}
function use() {
if [ -f "$appdir/releases/godot-engine_${1}" ]; then
if [ -h "godot-engine" ]; then
rm godot-engine
fi
ln -s "$appdir/releases/godot-engine_${1}" "$appdir/godot-engine"
chmod +x "$appdir/godot-engine"
else
echo "Error! Version $1 is not installed. Install it with \"godot install $1\""
exit 1
fi
return 0
}
function update() {
if [ ! -d "$appdir/source" ]; then
echo "Error! You must install Godot first"
exit 1
fi
download
latest_stable="$(get_latest_stable)"
if [ ! -f "$appdir/releases/godot-engine_${latest_stable}" ]; then
echo "A new stable version was found: ${latest_stable}"
echo "Installing..."
install "${latest_stable}"
if [ $? -ne 0 ]; then
return 1
fi
else
echo "No new stable version was found (current: $(version))."
echo "See all available versions by running \"godot version list\""
fi
return 0
}
function uninstall() {
local uninstall=()
local in_use=1
local delete_all=1
local i
# Select which versions to uninstall
if [ "$1" = "all" ] || [ -z "$1" ]; then
for i in $(installed); do
uninstall+=("$i")
done
else
is_tag "$1"
if [ $? -eq 0 ]; then
uninstall+=("$1")
fi
fi
if [ -z "$(echo "${uninstall[@]}")" ]; then
echo "Nothing selected to uninstall."
return 0
fi
# Uninstall every selected version
for i in ${uninstall[@]}; do
if [ "$i" = "$(version)" ]; then
in_use=0
fi
rm "$appdir/releases/godot-engine_${i}"
# If it was the last version, remove the system integration
if [ -z "$(installed)" ]; then
rm "$appdir/godot-engine"
sudo rm /usr/local/bin/godot
sudo rm /usr/share/applications/godot.desktop
sudo rm /etc/bash_completion.d/godot
read -p "Do you want to remove the directory containing the Godot files as well? (y/n) " yn
case $yn in
[Yy]*) delete_all=0;;
esac
fi
done
# Delete containing dir
if [ $delete_all -eq 0 ]; then
rm -Rf "$appdir"
# Or ...
else
# Set anoother version as the current one if the previous one was in use
if [ -n "$(installed)" ] && [ $in_use -eq 0 ]; then
for i in $(installed); do
echo "Uninstalled current active version, changing to ${i}..."
use "$i"
break
done
fi
fi
return 0
}
## Main
case "${1,,}" in
install) install "$2";;
dependencies) install_dependencies;;
uninstall) uninstall "$2";;
update) update;;
download|refresh) download;;
use) use "$2";;
releases) releases "$2" "$3";;
version) version;;
help) helptext;;
*) $(readlink -f "$appdir/godot-engine") $*;;
esac
cd "$prevpwd"
exit $?