Skip to content

Instantly share code, notes, and snippets.

@AntumDeluge AntumDeluge/stendhal.sh
Last active Feb 18, 2019

Embed
What would you like to do?
A script for installing/updating Stendhal on a Linux/Unix system.
#!/bin/bash
# A script for installing/updating Stendhal on a Linux/Unix system.
#
# LICENSE: CC0
# script to run/update Stendhal
JAVA=$(which java)
if [ -z "${JAVA}" ]; then
echo -e "\nERROR: Java is required to run Stendhal. Could not find a Java executable."
exit 1
fi
URL_VER="https://raw.githubusercontent.com/arianne/stendhal/master/build.ant.properties"
URL_DL="https://arianne-project.org/download/stendhal.zip"
DIR_BASE="/opt/games/stendhal"
DIR_DL="/tmp"
JAR="${DIR_BASE}/stendhal-starter.jar"
DIR_MENU="/usr/local/share/applications"
MENU="${DIR_MENU}/stendhal.desktop"
if [ "$1" == "update" ] || [ "$1" == "install" ]; then
if [ "${EUID}" -ne "0" ]; then
echo -e "\nERROR: You need root permissions to update this software"
else
echo -e "\nChecking version ..."
VER="$(wget -qO - "${URL_VER}" | grep "version\.old" | sed -e 's|version\.old = ||')"
if [ -z "${VER}" ]; then
echo -e "\nERROR: Could not determine latest version"
exit 1
else
FILE_BASE="stendhal-${VER}.zip"
FILE_FULL="${DIR_DL}/${FILE_BASE}"
echo "Current version: ${VER}"
echo "Downloading to ${FILE_FULL}"
if [ ! -d "${DIR_DL}" ]; then
if [ -e "${DIR_DL}" ]; then
echo -e "\nERROR: ${DIR_DL} exists but is not a directory"
exit 1
fi
mkdir -p "${DIR_DL}"
fi
if [ ! -f "${FILE_FULL}" ]; then
wget --show-progress -qO "${FILE_FULL}" "${URL_DL}"
if [ ! -f "${FILE_FULL}" ]; then
echo -e "\nERROR: Could not download current Stendhal package"
exit 1
fi
else
echo "Extracting from previously downloaded package ..."
fi
# clean target directory
if [ -d "${DIR_BASE}" ]; then
find "${DIR_BASE}" -mindepth 1 -type f -delete
find "${DIR_BASE}" -mindepth 1 -type d -empty -delete
else
mkdir -p "${DIR_BASE}"
fi
# extract package contents
unzip -q "${FILE_FULL}" -d "${DIR_BASE}"
chmod +x "${JAR}"
# menu entry
if [ ! -d "${DIR_MENU}" ]; then
mkdir -p "${DIR_MENU}"
fi
echo -e "[Desktop Entry]\n\
Version=1.0\n\
Encoding=UTF-8\n\
Name=Stendhal\n\
Comment=Multiplayer Online RPG\n\
Exec=java -jar \"${JAR}\"\n\
Icon=${DIR_BASE}/icon.ico\n\
Type=Application\n\
Terminal=false\n\
Category=Game;\n" > "${MENU}"
echo -e "\nUpdate finished"
# update desktop menu cache
xdg-desktop-menu forceupdate
# LXDE
LXPANEL=$(which lxpanelctl)
if [ ! -z "${LXPANEL}" ]; then
echo "Updating LXDE system menu ..."
rm -f “${HOME}/.config/menus/lxde-applications.menu” “${HOME}/.config/menus/debian-menu.menu”
# FIXME: need to update current user lxpanel
#lxpanelctl restart
echo -e "\nYou may need to run 'lxpanelctl restart. If that does not work, try restarting your system."
fi
fi
fi
elif [ "$1" == "uninstall" ]; then
if [ "${EUID}" -ne "0" ]; then
echo -e "\nERROR: You need root permissions to uninstall this software"
exit 1
fi
if [ ! -d "${DIR_BASE}" ]; then
echo -e "\nStendhal is not installed"
exit 0
fi
find "${DIR_BASE}" -type f -delete
find "${DIR_BASE}" -type d -empty -delete
# remove menu file
rm -f "${MENU}"
xdg-desktop-menu forceupdate
echo -e "\nUninstall complete"
else
if [ ! -f "${JAR}" ]; then
echo -e "\nERROR: Stendhal does not appear to be installed. Run 'stendhal install'."
exit 1
fi
java -jar "${JAR}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.