Skip to content

Instantly share code, notes, and snippets.

@hieuns
Last active January 11, 2024 02:50
Show Gist options
  • Save hieuns/ac4f117492771a690fa06cfa47b24714 to your computer and use it in GitHub Desktop.
Save hieuns/ac4f117492771a690fa06cfa47b24714 to your computer and use it in GitHub Desktop.
Install Godot Engine and create its .desktop file
#!/bin/bash
TMP_PATH="/tmp/godot.zip"
GODOT_LINK=$1
GODOT_DEST="/usr/bin"
GODOT_PATH="/usr/bin/godot"
ICON_DIR="/usr/share/icons/hicolor/scalable/apps"
ICON_PATH="$ICON_DIR/godot.svg"
ICON_URL="https://upload.wikimedia.org/wikipedia/commons/6/6a/Godot_icon.svg"
DESKTOP_FILE_DIR="/usr/share/applications"
DESKTOP_FILEPATH="$DESKTOP_FILE_DIR/godot.desktop"
if [[ -z $GODOT_LINK ]]; then
echo "Download link is not specified."
exit 1
fi
echo "Downloading Godot"
wget -O $TMP_PATH $GODOT_LINK
godot_zipped_filepath=$(unzip -Z1 $TMP_PATH | grep Godot)
splitted_path=($(echo $godot_zipped_filepath | tr '/' '\n'))
godot_filename=${splitted_path[-1]}
unzip $TMP_PATH $godot_zipped_filepath -d $GODOT_DEST
echo "Delete old executable file"
rm $GODOT_PATH
echo "Rename executable file: $GODOT_DEST/$godot_filename -> $GODOT_PATH"
mv $GODOT_DEST/$godot_filename $GODOT_PATH
echo "Remove $TMP_PATH"
rm $TMP_PATH
if [[ -f $ICON_PATH ]]; then
echo "Icon already existed. Skip downloading."
else
echo "Create $ICON_DIR"
mkdir -p $ICON_DIR
wget -O $ICON_PATH $ICON_URL
fi
if [[ -f $DESKTOP_FILEPATH ]]; then
echo "Desktop file already existed. Skip creating."
else
echo "Create $DESKTOP_FILEPATH"
touch $DESKTOP_FILEPATH
echo "Allow execution permission for $DESKTOP_FILEPATH"
chmod +x $DESKTOP_FILEPATH
echo "Clear content of $DESKTOP_FILEPATH"
> $DESKTOP_FILEPATH
echo "Insert desktop file content"
cat > $DESKTOP_FILEPATH <<CONTENT
[Desktop Entry]
Version=1.0
Name=Godot Engine
Comment=Godot is a 2D and 3D, cross-platform, free and open-source game engine which can create games targeting the PC, mobile and web platforms.
Exec=$GODOT_PATH
Icon=$ICON_PATH
Terminal=false
Type=Application
Categories=Development;
Actions=NewWindow;
[Desktop Action NewWindow]
Name=New Window
Exec=$GODOT_PATH
CONTENT
echo "Update desktop database with $DESKTOP_FILE_DIR directory"
update-desktop-database $DESKTOP_FILE_DIR
fi
@hsandt
Copy link

hsandt commented Jan 10, 2024

I was unaware of this gist and wrote my own script: https://gist.github.com/hsandt/113d3c6698a54e378d44b5024140c2a0 but I find it interesting how you download the icon and embed the .desktop template in the same file. My script requires manually placing the icon and copying the .desktop template, so it's not completely plug-and-play. In counterpart, it is able to deduce the DL URL from the version and channel passed to the script.

@hieuns
Copy link
Author

hieuns commented Jan 11, 2024

@hsandt Yeah, my script is not flexible enough that it requires user to manually finds the download link and passes it to the script. The version/channel specification part in your script is very interesting, I could learn from that. Thank you!

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