Last active
May 4, 2025 09:52
-
-
Save clvs7-gh/0b422fe22446506aa5064312e4f5dd2c to your computer and use it in GitHub Desktop.
DragonRuby Updater 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/sh | |
# This snippet (not dragonruby itself) is licensed under CC0. | |
DL_LINK_WINDOWS="https://dragonruby.org/api/download_pro_subscription_windows" | |
DL_LINK_MACOS="https://dragonruby.org/api/download_pro_subscription_mac" | |
DL_LINK_LINUX="https://dragonruby.org/api/download_pro_subscription_linux" | |
DL_DIR="/tmp/dragonruby" | |
DL_FILES_DIR="$DL_DIR/files" | |
DR_PROJECT_DIR=$(cd $(dirname $0);pwd) | |
CURRENT_PLATFORM=$(uname -s) | |
if [ ! -z "$DR_PLATFORM" ]; then | |
echo "Using platform: $DR_PLATFORM" | |
CURRENT_PLATFORM=$DR_PLATFORM | |
fi | |
echo "Current platform: $CURRENT_PLATFORM" | |
case "$CURRENT_PLATFORM" in | |
Linux*) DL_LINK=$DL_LINK_LINUX;; | |
Darwin*) DL_LINK=$DL_LINK_MACOS;; | |
CYGWIN*) DL_LINK=$DL_LINK_WINDOWS;; | |
MINGW*) DL_LINK=$DL_LINK_WINDOWS;; | |
Windows*) DL_LINK=$DL_LINK_WINDOWS;; | |
*) echo "Unsupported OS: $CURRENT_PLATFORM"; exit 1;; | |
esac | |
CURRENT_VERSION=$($DR_PROJECT_DIR/dragonruby --version) | |
echo "Current version: $CURRENT_VERSION" | |
LATEST_VERSION=$(curl -s https://docs.dragonruby.org/version.txt) | |
if [ "$(printf "$CURRENT_VERSION\n$LATEST_VERSION" | sort -V | head -n 1)" = "$LATEST_VERSION" ] && [ -z "$DR_FORCE_UPDATE" ]; then | |
echo "You are using the latest version." | |
exit | |
fi | |
echo "Update available: $LATEST_VERSION" | |
read -p "Do you want to update? (y/N) " ANSWER | |
case "$ANSWER" in | |
[yY]*) echo "OK";; | |
*) exit;; | |
esac | |
if [ -z "$DR_EMAIL" ]; then | |
read -p "Enter your email address: " DR_EMAIL | |
fi | |
if [ -z "$DR_PASS" ]; then | |
stty -echo | |
read -p "Enter your password: " DR_PASS | |
stty echo | |
fi | |
echo "Downloading..." | |
rm -rf $DL_DIR | |
mkdir -p $DL_DIR | |
mkdir -p $DL_FILES_DIR | |
curl -L -o $DL_DIR/dragonruby.zip $(curl -u $DR_EMAIL:$DR_PASS $DL_LINK) | |
if [ $? -ne 0 ]; then | |
echo "Download failed. Please check your email and password." | |
exit 1 | |
fi | |
echo "Unzipping..." | |
unzip -o $DL_DIR/dragonruby.zip -d $DL_FILES_DIR > $DL_DIR/unzip.log | |
if [ $? -ne 0 ]; then | |
echo "Unzip failed. Please check the downloaded file." | |
exit 1 | |
fi | |
DL_PROJECT_DIR="$DL_FILES_DIR/$(ls $DL_FILES_DIR | grep -E 'dragonruby-\w+')" | |
if [ -z "$DR_IGNORE_DIR" ]; then | |
DL_IGNORE_DIR=${DR_IGNORE_DIR:-"mygame"} | |
fi | |
echo "Ignoring directory: $DL_IGNORE_DIR" | |
echo "Copying files from $DL_PROJECT_DIR to $DR_PROJECT_DIR..." | |
rsync -av --exclude="$DL_IGNORE_DIR" $DL_PROJECT_DIR/ $DR_PROJECT_DIR/ > $DL_DIR/rsync.log | |
if [ $? -ne 0 ]; then | |
echo "Copy failed. Please check the rsync log." | |
exit 1 | |
fi | |
if [ "$CURRENT_PLATFORM" = "Darwin" ]; then | |
echo "Removing quarantine attribute..." | |
xattr -d com.apple.quarantine $DR_PROJECT_DIR/$(ls -F $DR_PROJECT_DIR | grep 'dragonruby') | |
fi | |
echo "Cleaning up..." | |
if [ -z "$DR_KEEP_DL_DIR" ]; then | |
rm -rf $DL_DIR | |
fi | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment