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