simplify running SMAPI without a terminal on Linux/macOS

This commit is contained in:
Jesse Plamondon-Willard 2021-12-18 23:07:33 -05:00
parent beb1acd4f8
commit 95f658014e
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 61 additions and 50 deletions

View File

@ -4,6 +4,7 @@
## Upcoming release ## Upcoming release
* For players: * For players:
* Fixed outdated instructions in Steam error message. * Fixed outdated instructions in Steam error message.
* Simplified [running without a terminal on Linux/macOS](https://stardewvalleywiki.com/Modding:Player_Guide/Troubleshooting#SMAPI_doesn.27t_recognize_controller_.28Steam_only.29) when needed.
* Updated compatibility list. * Updated compatibility list.
* For the web UI: * For the web UI:

View File

@ -6,6 +6,10 @@
# move to script's directory # move to script's directory
cd "$(dirname "$0")" || exit $? cd "$(dirname "$0")" || exit $?
# change to true to skip opening a terminal
# This isn't recommended since you won't see errors, warnings, and update alerts.
SKIP_TERMINAL=false
########## ##########
## Open terminal if needed ## Open terminal if needed
@ -16,7 +20,6 @@ cd "$(dirname "$0")" || exit $?
if [ "$(uname)" == "Darwin" ]; then if [ "$(uname)" == "Darwin" ]; then
if [ ! -t 1 ]; then # https://stackoverflow.com/q/911168/262123 if [ ! -t 1 ]; then # https://stackoverflow.com/q/911168/262123
# sanity check to make sure we don't have an infinite loop of opening windows # sanity check to make sure we don't have an infinite loop of opening windows
SKIP_TERMINAL=false
for argument in "$@"; do for argument in "$@"; do
if [ "$argument" == "--no-reopen-terminal" ]; then if [ "$argument" == "--no-reopen-terminal" ]; then
SKIP_TERMINAL=true SKIP_TERMINAL=true
@ -63,64 +66,71 @@ else
LAUNCH_FILE="./StardewModdingAPI" LAUNCH_FILE="./StardewModdingAPI"
export LAUNCH_FILE export LAUNCH_FILE
# select terminal (prefer xterm for best compatibility, then known supported terminals) # run in terminal
for terminal in xterm gnome-terminal kitty terminator xfce4-terminal konsole terminal termite alacritty mate-terminal x-terminal-emulator; do if [ "$SKIP_TERMINAL" == "false" ]; then
if command -v "$terminal" 2>/dev/null; then # select terminal (prefer xterm for best compatibility, then known supported terminals)
export TERMINAL_NAME=$terminal for terminal in xterm gnome-terminal kitty terminator xfce4-terminal konsole terminal termite alacritty mate-terminal x-terminal-emulator; do
break; if command -v "$terminal" 2>/dev/null; then
export TERMINAL_NAME=$terminal
break;
fi
done
# find the true shell behind x-terminal-emulator
if [ "$TERMINAL_NAME" = "x-terminal-emulator" ]; then
export TERMINAL_NAME="$(basename "$(readlink -f $(command -v x-terminal-emulator))")"
fi fi
done
# find the true shell behind x-terminal-emulator # run in selected terminal and account for quirks
if [ "$TERMINAL_NAME" = "x-terminal-emulator" ]; then export TERMINAL_PATH="$(command -v $TERMINAL_NAME)"
export TERMINAL_NAME="$(basename "$(readlink -f $(command -v x-terminal-emulator))")" if [ -x $TERMINAL_PATH ]; then
fi case $TERMINAL_NAME in
terminal|termite)
# consumes only one argument after -e
# options containing space characters are unsupported
exec $TERMINAL_NAME -e "env TERM=xterm $LAUNCH_FILE $@"
;;
# run in selected terminal and account for quirks xterm|konsole|alacritty)
export TERMINAL_PATH="$(command -v $TERMINAL_NAME)" # consumes all arguments after -e
if [ -x $TERMINAL_PATH ]; then exec $TERMINAL_NAME -e env TERM=xterm $LAUNCH_FILE "$@"
case $TERMINAL_NAME in ;;
terminal|termite)
# consumes only one argument after -e
# options containing space characters are unsupported
exec $TERMINAL_NAME -e "env TERM=xterm $LAUNCH_FILE $@"
;;
xterm|konsole|alacritty) terminator|xfce4-terminal|mate-terminal)
# consumes all arguments after -e # consumes all arguments after -x
exec $TERMINAL_NAME -e env TERM=xterm $LAUNCH_FILE "$@" exec $TERMINAL_NAME -x env TERM=xterm $LAUNCH_FILE "$@"
;; ;;
terminator|xfce4-terminal|mate-terminal) gnome-terminal)
# consumes all arguments after -x # consumes all arguments after --
exec $TERMINAL_NAME -x env TERM=xterm $LAUNCH_FILE "$@" exec $TERMINAL_NAME -- env TERM=xterm $LAUNCH_FILE "$@"
;; ;;
gnome-terminal) kitty)
# consumes all arguments after -- # consumes all trailing arguments
exec $TERMINAL_NAME -- env TERM=xterm $LAUNCH_FILE "$@" exec $TERMINAL_NAME env TERM=xterm $LAUNCH_FILE "$@"
;; ;;
kitty) *)
# consumes all trailing arguments # If we don't know the terminal, just try to run it in the current shell.
exec $TERMINAL_NAME env TERM=xterm $LAUNCH_FILE "$@" # If THAT fails, launch with no output.
;; env TERM=xterm $LAUNCH_FILE "$@"
if [ $? -eq 127 ]; then
exec $LAUNCH_FILE --no-terminal "$@"
fi
esac
*) ## terminal isn't executable; fallback to current shell or no terminal
# If we don't know the terminal, just try to run it in the current shell. else
# If THAT fails, launch with no output. echo "The '$TERMINAL_NAME' terminal isn't executable. SMAPI might be running in a sandbox or the system might be misconfigured? Falling back to current shell."
env TERM=xterm $LAUNCH_FILE "$@" env TERM=xterm $LAUNCH_FILE "$@"
if [ $? -eq 127 ]; then if [ $? -eq 127 ]; then
exec $LAUNCH_FILE --no-terminal "$@" exec $LAUNCH_FILE --no-terminal "$@"
fi fi
esac fi
## terminal isn't executable; fallback to current shell or no terminal # explicitly run without terminal
else else
echo "The '$TERMINAL_NAME' terminal isn't executable. SMAPI might be running in a sandbox or the system might be misconfigured? Falling back to current shell." exec $LAUNCH_FILE --no-terminal "$@"
env TERM=xterm $LAUNCH_FILE "$@"
if [ $? -eq 127 ]; then
exec $LAUNCH_FILE --no-terminal "$@"
fi
fi fi
fi fi