Last active
May 2, 2025 07:41
-
-
Save ForwardFeed/ee7edbf5042c9aa4a06b1ba4ffbed9a8 to your computer and use it in GitHub Desktop.
Update the godot engine automatically with a bash script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/env bash | |
| # Please note that, this script is a bit useless | |
| # As you could simply install godot with packet manager | |
| # This script: | |
| # 1) Find the lastest stable version for linux of godot from the github repository | |
| # 2) Check if it has already been downloaded | |
| # 3) If not, it download and extract it | |
| # 4) Update the godot desktop, i have crafted mine so it's something one exept not to have. | |
| # 5) Set the binary of godot executable | |
| # 6) Delete Others Binary of godot automatically | |
| # Custom made file, but it's standart to find those like that | |
| DESKTOP_FILE="/usr/share/applications/godot.desktop" | |
| function get_latest_link(){ | |
| curl -s https://api.github.com/repos/godotengine/godot/releases/latest \ | |
| | grep "browser_download_url" \ | |
| | grep -Eo "http.*stable_linux.x86_64.zip" | |
| } | |
| function download(){ | |
| echo "downloading: ${version}" | |
| # (using stdin hence why bsdtar specifically) | |
| wget -qO- $version | bsdtar -xvf- | |
| } | |
| function update_desktop_shortcut(){ | |
| [ ! -f "$file_path" ] && echo "error can't find the file check the script" && exit 1 | |
| echo "File must be ${file_path}, replacing in the desktop file..." | |
| escaped_file_path=$(echo $file_path | sed -r 's/\//\\\//g') | |
| replace="s/Exec.*/Exec=${escaped_file_path}/" | |
| # requires sudo, at least normally | |
| sudo sed -i $replace $DESKTOP_FILE | |
| echo "replaced successfully" | |
| } | |
| function final_setup(){ | |
| # allows the usert to execute the binary | |
| chmod u+x $file_path | |
| echo "made the binary executable" | |
| # remove other godot binaries, of previous installation | |
| list_all=$(find . -maxdepth 1 -type f | grep -Eo "Godot.*stable_linux.*") | |
| read -r -a array <<< "$list_all" | |
| for file_found in "${array[@]}" | |
| do | |
| file_found_path="./${file_found}" | |
| # small security, not to delete files that have this odd nameing, but aren't executable | |
| if [ ! -x $file_found_path ] | |
| then | |
| echo "${file_found_path} wasn't an executable, have I made a mistake?, not deleting it" | |
| continue | |
| fi | |
| # if it's not our fresh godot binary, throw it away to the abyss | |
| if [[ $file_found != $file_name ]] | |
| then | |
| rm $file_found_path | |
| echo "deleted other version of godot ./${file_found}" | |
| fi | |
| done | |
| } | |
| version=$(get_latest_link) | |
| file_name=$(echo $version | grep -Eo "Godot.*stable_linux.x86_64") | |
| file_path="$(pwd)/${file_name}" | |
| if [ -f "$file_path" ] | |
| then | |
| echo "file ${file_name} already exist, skipping the downloading" | |
| else | |
| download | |
| fi | |
| update_desktop_shortcut | |
| final_setup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment