2013-12-23 01:23:35 +05:30
#!/bin/bash
2021-10-13 05:29:25 +05:30
# Basic start script for running the launcher with the libs packaged with it.
2013-02-12 21:44:23 +05:30
2013-12-21 14:06:12 +05:30
function printerror {
2018-07-15 18:21:05 +05:30
printf "$1"
if which zenity >/dev/null; then zenity --error --text="$1" &>/dev/null;
elif which kdialog >/dev/null; then kdialog --error "$1" &>/dev/null;
fi
2013-12-21 14:06:12 +05:30
}
if [[ $EUID -eq 0 ]]; then
2013-12-25 19:13:51 +05:30
printerror "This program should not be run using sudo or as the root user!\n"
2013-12-21 14:06:12 +05:30
exit 1
fi
2022-01-15 07:58:10 +05:30
LAUNCHER_NAME=@Launcher_APP_BINARY_NAME@
2021-10-13 05:29:25 +05:30
LAUNCHER_DIR="$(dirname "$(readlink -f "$0")")"
echo "Launcher Dir: ${LAUNCHER_DIR}"
2013-02-12 21:44:23 +05:30
2015-06-12 13:10:41 +05:30
# Set up env - filter out input LD_ variables but pass them in under different names
2015-12-18 03:08:14 +05:30
export GAME_LIBRARY_PATH=${GAME_LIBRARY_PATH-${LD_LIBRARY_PATH}}
export GAME_PRELOAD=${GAME_PRELOAD-${LD_PRELOAD}}
2022-03-23 17:50:14 +05:30
export LD_LIBRARY_PATH="${LAUNCHER_DIR}/lib@LIB_SUFFIX@":$LAUNCHER_LIBRARY_PATH
2021-10-13 05:29:25 +05:30
export LD_PRELOAD=$LAUNCHER_PRELOAD
export QT_PLUGIN_PATH="${LAUNCHER_DIR}/plugins"
export QT_FONTPATH="${LAUNCHER_DIR}/fonts"
2013-11-24 11:06:16 +05:30
2013-12-13 21:08:17 +05:30
# Detect missing dependencies...
2021-10-13 05:29:25 +05:30
DEPS_LIST=`ldd "${LAUNCHER_DIR}"/plugins/*/*.so 2>/dev/null | grep "not found" | sort -u | awk -vORS=", " '{ print $1 }'`
2013-12-16 02:57:32 +05:30
if [ "x$DEPS_LIST" = "x" ]; then
2021-10-13 05:29:25 +05:30
# We have all our dependencies. Run the launcher.
2018-07-15 18:21:05 +05:30
echo "No missing dependencies found."
2013-11-24 11:06:16 +05:30
2018-07-15 18:21:05 +05:30
# Just to be sure...
2021-10-13 05:29:25 +05:30
chmod +x "${LAUNCHER_DIR}/bin/${LAUNCHER_NAME}"
2013-12-13 21:08:17 +05:30
2021-10-13 05:29:25 +05:30
# Run the launcher
exec -a "${LAUNCHER_DIR}/${LAUNCHER_NAME}" "${LAUNCHER_DIR}/bin/${LAUNCHER_NAME}" -d "${LAUNCHER_DIR}" "$@"
2013-12-13 21:08:17 +05:30
2021-10-13 05:29:25 +05:30
# Run the launcher in valgrind
# valgrind --log-file="valgrind.log" --leak-check=full --track-origins=yes "${LAUNCHER_DIR}/bin/${LAUNCHER_NAME}" -d "${LAUNCHER_DIR}" "$@"
2014-03-30 15:56:24 +05:30
2021-10-13 05:29:25 +05:30
# Run the launcher with callgrind, delay instrumentation
# valgrind --log-file="valgrind.log" --tool=callgrind --instr-atstart=no "${LAUNCHER_DIR}/bin/${LAUNCHER_NAME}" -d "${LAUNCHER_DIR}" "$@"
2018-07-15 18:21:05 +05:30
# use callgrind_control -i on/off to profile actions
2015-04-15 06:43:57 +05:30
2021-10-13 05:29:25 +05:30
# Exit with launcher's exit code.
2021-07-28 01:16:38 +05:30
# exit $?
2013-12-13 21:08:17 +05:30
else
2018-07-15 18:21:05 +05:30
# apt
if which apt-file &>/dev/null; then
LIBRARIES=`echo "$DEPS_LIST" | grep -oP "[^, ]*" | sort -u`
COMMAND_LIBS=`for LIBRARY in $LIBRARIES; do apt-file -l search $LIBRARY; done`
COMMAND_LIBS=`echo "$COMMAND_LIBS" | sort -u | awk -vORS=" " '{ print $1 }'`
INSTALL_CMD="sudo apt-get install $COMMAND_LIBS"
# pacman
elif which pkgfile &>/dev/null; then
LIBRARIES=`echo "$DEPS_LIST" | grep -oP "[^, ]*" | sort -u`
COMMAND_LIBS=`for LIBRARY in $LIBRARIES; do pkgfile $LIBRARY; done`
COMMAND_LIBS=`echo "$COMMAND_LIBS" | sort -u | awk -vORS=" " '{ print $1 }'`
INSTALL_CMD="sudo pacman -S $COMMAND_LIBS"
# dnf
elif which dnf &>/dev/null; then
LIBRARIES=`echo "$DEPS_LIST" | grep -oP "[^, ]*" | sort -u`
COMMAND_LIBS=`for LIBRARY in $LIBRARIES; do dnf whatprovides -q $LIBRARY; done`
COMMAND_LIBS=`echo "$COMMAND_LIBS" | grep -v 'Repo' | sort -u | awk -vORS=" " '{ print $1 }'`
INSTALL_CMD="sudo dnf install $COMMAND_LIBS"
# yum
elif which yum &>/dev/null; then
LIBRARIES=`echo "$DEPS_LIST" | grep -oP "[^, ]*" | sort -u`
COMMAND_LIBS=`for LIBRARY in $LIBRARIES; do yum whatprovides $LIBRARY; done`
COMMAND_LIBS=`echo "$COMMAND_LIBS" | sort -u | awk -vORS=" " '{ print $1 }'`
INSTALL_CMD="sudo yum install $COMMAND_LIBS"
# zypper
elif which zypper &>/dev/null; then
LIBRARIES=`echo "$DEPS_LIST" | grep -oP "[^, ]*" | sort -u`
COMMAND_LIBS=`for LIBRARY in $LIBRARIES; do zypper wp $LIBRARY; done`
COMMAND_LIBS=`echo "$COMMAND_LIBS" | sort -u | awk -vORS=" " '{ print $1 }'`
INSTALL_CMD="sudo zypper install $COMMAND_LIBS"
# emerge
elif which pfl &>/dev/null; then
LIBRARIES=`echo "$DEPS_LIST" | grep -oP "[^, ]*" | sort -u`
COMMAND_LIBS=`for LIBRARY in $LIBRARIES; do pfl $LIBRARY; done`
COMMAND_LIBS=`echo "$COMMAND_LIBS" | sort -u | awk -vORS=" " '{ print $1 }'`
INSTALL_CMD="sudo emerge $COMMAND_LIBS"
fi
2013-12-16 02:57:32 +05:30
2021-10-13 05:29:25 +05:30
MESSAGE="Error: The launcher is missing the following libraries that it needs to work correctly:\n\t${DEPS_LIST}\nPlease install them from your distribution's package manager."
2018-07-15 18:21:05 +05:30
MESSAGE="$MESSAGE\n\nHint (please apply common sense): $INSTALL_CMD\n"
2013-12-16 02:57:32 +05:30
2018-07-15 18:21:05 +05:30
printerror "$MESSAGE"
exit 1
2013-12-13 21:08:17 +05:30
fi