Skip to content

Instantly share code, notes, and snippets.

@diath
Last active August 31, 2017 16:29
Show Gist options
  • Save diath/c00cf141931a9a444f765f52da0018a2 to your computer and use it in GitHub Desktop.
Save diath/c00cf141931a9a444f765f52da0018a2 to your computer and use it in GitHub Desktop.
Tibia 11 client updater for Linux
#!/usr/bin/env bash
set -u
for i in "$@"; do
case $i in
-r|--resume)
RESUME=1
shift
;;
-p=*|--path=*)
CLIENT_PATH="${i#*=}"
shift
;;
esac
done
if [[ -z ${CLIENT_PATH+DUMMY} ]]; then
echo "Usage: update-tibia.sh [--resume] --path=/current/install/path"
exit 1
fi
REMOTE_PATH="http://download.tibia.com/tibia.x64.tar.gz"
LOCAL_PATH="/tmp/tibia.x64.tar.gz"
COLOR_RED="\033[0;31m"
COLOR_DEF="\033[0m"
print_error() {
if [[ ! -z "$1" ]]; then
echo -e "${COLOR_RED}$1${COLOR_DEF}"
fi
}
if [[ -z ${RESUME+DUMMY} ]]; then
echo "* Downloading the archive..."
RESULT=`/usr/bin/curl --write-out %{http_code} --progress-bar -o $LOCAL_PATH $REMOTE_PATH`
if [[ "$RESULT" != "200" ]]; then
print_error " * Failed to download the archive."
exit 1
fi
echo "* Done."
echo "* Extracting the archive..."
tar -zxf "$LOCAL_PATH" -C /tmp 2> /dev/null
if [[ "$?" != "0" ]]; then
print_error " * Failed to extract the archive."
exit 1
fi
echo "* Done."
fi
cd /tmp/tibia-11*
echo "* Checking default OpenSSL version..."
OPENSSL_VER=`openssl version | grep --color=never -o "^OpenSSL [0-9]\+\.[0-9]\+" | cut -d' ' -f2`
if [[ "$OPENSSL_VER" == "1.0" ]]; then
echo " * Compatible, nothing to do"
else
echo " * Incompatible, searching for compatible version..."
if [[ ! -x "/usr/bin/openssl-1.0" ]]; then
print_error " * Not found, please install OpenSSL 1.0 (e.g. pacman -S openssl-1.0 on Arch Linux)"
print_error " * You can resume the script afterwards without downloading the client again using $0 --path=$CLIENT_PATH --resume"
exit 1
else
echo " * Compatible version found, fixing the LD_LIBRARY_PATH string..."
sed -i "s/LD_LIBRARY_PATH=\"\$BIN_PATH\"/LD_LIBRARY_PATH=\"\$BIN_PATH:\/usr\/lib\/openssl-1.0\"/g" start-tibia.sh
echo " * Done."
fi
fi
echo "* Done."
echo "* Copying the config and minimap..."
cp -r "$CLIENT_PATH/minimap" "$PWD"
cp -r "$CLIENT_PATH/conf" "$PWD"
echo "* Done."
echo "* Finalizing..."
rm -rf "$CLIENT_PATH"
cd /tmp
mv /tmp/tibia-11* "$CLIENT_PATH"
cd "$CLIENT_PATH"
echo "* Done."
echo "* You can use $CLIENT_PATH/start-tibia.sh now :)."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment