Skip to content

Instantly share code, notes, and snippets.

@hsandt
Last active January 10, 2024 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsandt/113d3c6698a54e378d44b5024140c2a0 to your computer and use it in GitHub Desktop.
Save hsandt/113d3c6698a54e378d44b5024140c2a0 to your computer and use it in GitHub Desktop.
Install Godot 3 stable or 4 beta, rc or stable and create desktop entry for Linux
[Desktop Entry]
Name=Godot Engine $VERSION $CHANNEL
GenericName=Libre game engine
Comment=Multi-platform 2D and 3D game engine with a feature-rich editor
Exec=godot$VERSION_$CHANNEL %f
Icon=$HOME/.local/share/applications/godot.png
Terminal=false
Type=Application
MimeType=application/x-godot-project;
Categories=Development;IDE;
Name[en_US]=Godot $VERSION $CHANNEL.desktop
#!/usr/bin/env bash
# Gist: https://gist.github.com/hsandt/113d3c6698a54e378d44b5024140c2a0
usage() {
echo "Usage: install_godot_and_create_desktop_entry.sh version channel
Install a non-mono version of Godot for Linux.
Requirements:
- perl installed
- \"Godot template.desktop\" placed in the same directory as this script
- Godot icon placed at ~/.local/share/applications/godot.png
ARGUMENTS
version Version of godot to download. Do not include channel like 'beta' here. Ex: '4.0.1'.
channel Channel of godot to download, including number. Ex: 'beta14', 'rc1', 'stable'
"
}
if ! [[ $# -eq 2 ]]; then
echo "Wrong number of positional arguments: found $#, expected 2."
echo "Passed positional arguments: $@"
usage
exit 1
fi
version="$1"
channel="$2"
shift 2
parent_dir_path="$(dirname "$0")"
if [[ "$version" == 3* ]]; then
# Godot 3 was naming "X11" the Linux build
linux_suffix="x11.64"
else
linux_suffix="linux.x86_64"
fi
godot_bin_name="Godot_v${version}-${channel}_${linux_suffix}"
godot_bin_zip="${godot_bin_name}.zip"
# Remove existing archive if any (in case it was previously incorrectly downloaded)
rm -f "$godot_bin_zip"
if [[ "$channel" == "stable"* ]]; then
# Stable releases are on GitHub
download_url="https://github.com/godotengine/godot/releases/download/${version}-${channel}/Godot_v${version}-stable_${linux_suffix}.zip"
else
# Release candidates are on Tux Family
download_url="https://downloads.tuxfamily.org/godotengine/${version}/${channel}/${godot_bin_zip}"
fi
# Download archive for passed version in current folder
wget "$download_url"
# Unzip it
unzip "$godot_bin_zip"
# Remove archive to clean up current folder
rm "$godot_bin_zip"
install_folder="${HOME}/Applications/Game Engines/Godot"
install_path="${install_folder}/${godot_bin_name}"
symlink_path="${HOME}/.local/bin/godot${version}_${channel}"
# It should have extracted a file named "$godot_bin_name", so move it to the target folder (overwrites any existing file)
mv "$godot_bin_name" "$install_folder"
echo "Installed in ${install_path}"
# Create symbolic link for terminal and future Desktop entry (overwrites any existing link)
ln -sf "${install_path}" "${symlink_path}"
echo "Created symbolic link in ${symlink_path}"
# Create Desktop entry from template (overwrites any existing file)
desktop_entry_path="${HOME}/.local/share/applications/Godot ${version} ${channel}.desktop"
cp "${parent_dir_path}/Godot template.desktop" "$desktop_entry_path"
# https://stackoverflow.com/questions/6994947/how-to-replace-a-string-in-an-existing-file-in-perl
perl -pi -e "s/\\\$VERSION/${version}/g" "$desktop_entry_path"
perl -pi -e "s/\\\$CHANNEL/${channel}/g" "$desktop_entry_path"
# https://stackoverflow.com/questions/26080096/installed-desktop-file-to-have-users-home-directory-path-inserted
# mind the comma separator since we deal with paths containing slashes
# we could also convert "~" but in this case, the template contains "$HOME"
# (which doesn't work per se, it needs path expansion)
perl -pi -e "s,\\\$HOME,${HOME},g" "$desktop_entry_path"
echo "Created desktop entry in ${desktop_entry_path}"
@hsandt
Copy link
Author

hsandt commented Jan 10, 2024

I also found another script that does a similar thing but is self-contained: https://gist.github.com/hieuns/ac4f117492771a690fa06cfa47b24714

It auto-downloads the icon svg from Wikimedia and embeds the .desktop template content in the same script.

However, it takes the Godot URL argument, making it more flexible but unable to retrieve the correct URL from version+channel automatically.

It may be worth merging both methods (download icon and deduce URL, possibly embed the template too) for a simple script the user can run without extra setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment