From 3dc344054a701379528ca5de256210ce232c8cc3 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 2 Apr 2021 20:35:02 -0400 Subject: don't overwrite .bin.osx file unnecessarily to avoid resetting file permissions (#768) --- src/SMAPI.Installer/assets/unix-launcher.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/SMAPI.Installer/assets/unix-launcher.sh') diff --git a/src/SMAPI.Installer/assets/unix-launcher.sh b/src/SMAPI.Installer/assets/unix-launcher.sh index 1d97d487..93bf58d8 100644 --- a/src/SMAPI.Installer/assets/unix-launcher.sh +++ b/src/SMAPI.Installer/assets/unix-launcher.sh @@ -37,8 +37,13 @@ if [ "$UNAME" == "Darwin" ]; then ln -s /Library/Frameworks/Mono.framework/Versions/Current/lib/libgdiplus.dylib libgdiplus.dylib fi + # create bin file + # Note: don't overwrite if it's identical, to avoid resetting permission flags + if [ ! -x StardewModdingAPI.bin.osx ] || ! cmp StardewValley.bin.osx StardewModdingAPI.bin.osx >/dev/null 2>&1; then + cp -p StardewValley.bin.osx StardewModdingAPI.bin.osx + fi + # launch SMAPI - cp StardewValley.bin.osx StardewModdingAPI.bin.osx open -a Terminal ./StardewModdingAPI.bin.osx "$@" else # choose launcher -- cgit From ec9914efad9e4ba46d49337b473b79bcdfd20d1f Mon Sep 17 00:00:00 2001 From: kuesji koesnu Date: Sun, 2 May 2021 17:37:08 +0300 Subject: launcher strict sandbox fix on linux i added a check for is found terminal is executable. game will launch with standart exec if found terminal is not exist or executable. ( fix for issue #775 ) --- src/SMAPI.Installer/assets/unix-launcher.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/SMAPI.Installer/assets/unix-launcher.sh') diff --git a/src/SMAPI.Installer/assets/unix-launcher.sh b/src/SMAPI.Installer/assets/unix-launcher.sh index 93bf58d8..0046e716 100644 --- a/src/SMAPI.Installer/assets/unix-launcher.sh +++ b/src/SMAPI.Installer/assets/unix-launcher.sh @@ -80,8 +80,14 @@ else export LAUNCHTERM="$(basename "$(readlink -f $(COMMAND x-terminal-emulator))")" fi - # run in selected terminal and account for quirks - case $LAUNCHTERM in + + if [ ! -x $LAUNCHTERM ]; then + echo "looks like found no terminal available for launch. maybe in sandbox or misconfigured system? fallbacking to execution without terminal" + export TERM="xterm" + exec $LAUNCHER $@ + else + # run in selected terminal and account for quirks + case $LAUNCHTERM in terminal|termite) # LAUNCHTERM consumes only one argument after -e # options containing space characters are unsupported @@ -110,5 +116,6 @@ else if [ $? -eq 127 ]; then exec $LAUNCHER --no-terminal "$@" fi - esac + esac + fi fi -- cgit From bc9b5a84f0ecbf563d5f682f8ed38e50e7e675fc Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 2 May 2021 18:07:05 -0400 Subject: use POSIX command directly in Linux launcher --- src/SMAPI.Installer/assets/unix-launcher.sh | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'src/SMAPI.Installer/assets/unix-launcher.sh') diff --git a/src/SMAPI.Installer/assets/unix-launcher.sh b/src/SMAPI.Installer/assets/unix-launcher.sh index 0046e716..7611dfcd 100644 --- a/src/SMAPI.Installer/assets/unix-launcher.sh +++ b/src/SMAPI.Installer/assets/unix-launcher.sh @@ -59,17 +59,9 @@ else fi export LAUNCHER - # get cross-distro version of POSIX command - COMMAND="" - if command -v command 2>/dev/null; then - COMMAND="command -v" - elif type type 2>/dev/null; then - COMMAND="type -p" - fi - # select terminal (prefer xterm for best compatibility, then known supported terminals) for terminal in xterm gnome-terminal kitty terminator xfce4-terminal konsole terminal termite alacritty mate-terminal x-terminal-emulator; do - if $COMMAND "$terminal" 2>/dev/null; then + if command -v "$terminal" 2>/dev/null; then export LAUNCHTERM=$terminal break; fi @@ -77,7 +69,7 @@ else # find the true shell behind x-terminal-emulator if [ "$LAUNCHTERM" = "x-terminal-emulator" ]; then - export LAUNCHTERM="$(basename "$(readlink -f $(COMMAND x-terminal-emulator))")" + export LAUNCHTERM="$(basename "$(readlink -f $(command -v x-terminal-emulator))")" fi -- cgit From b8b120b759f292da8b6583831de2894fe44a0012 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 2 May 2021 18:11:58 -0400 Subject: rename variables in Linux launcher for clarity --- src/SMAPI.Installer/assets/unix-launcher.sh | 78 ++++++++++++++--------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'src/SMAPI.Installer/assets/unix-launcher.sh') diff --git a/src/SMAPI.Installer/assets/unix-launcher.sh b/src/SMAPI.Installer/assets/unix-launcher.sh index 7611dfcd..e0a106cb 100644 --- a/src/SMAPI.Installer/assets/unix-launcher.sh +++ b/src/SMAPI.Installer/assets/unix-launcher.sh @@ -46,68 +46,68 @@ if [ "$UNAME" == "Darwin" ]; then # launch SMAPI open -a Terminal ./StardewModdingAPI.bin.osx "$@" else - # choose launcher - LAUNCHER="" + # choose binary file to launch + LAUNCH_FILE="" if [ "$ARCH" == "x86_64" ]; then ln -sf mcs.bin.x86_64 mcs cp StardewValley.bin.x86_64 StardewModdingAPI.bin.x86_64 - LAUNCHER="./StardewModdingAPI.bin.x86_64" + LAUNCH_FILE="./StardewModdingAPI.bin.x86_64" else ln -sf mcs.bin.x86 mcs cp StardewValley.bin.x86 StardewModdingAPI.bin.x86 - LAUNCHER="./StardewModdingAPI.bin.x86" + LAUNCH_FILE="./StardewModdingAPI.bin.x86" fi - export LAUNCHER + export LAUNCH_FILE # select terminal (prefer xterm for best compatibility, then known supported terminals) for terminal in xterm gnome-terminal kitty terminator xfce4-terminal konsole terminal termite alacritty mate-terminal x-terminal-emulator; do if command -v "$terminal" 2>/dev/null; then - export LAUNCHTERM=$terminal + export TERMINAL_NAME=$terminal break; fi done # find the true shell behind x-terminal-emulator - if [ "$LAUNCHTERM" = "x-terminal-emulator" ]; then - export LAUNCHTERM="$(basename "$(readlink -f $(command -v x-terminal-emulator))")" + if [ "$TERMINAL_NAME" = "x-terminal-emulator" ]; then + export TERMINAL_NAME="$(basename "$(readlink -f $(command -v x-terminal-emulator))")" fi - if [ ! -x $LAUNCHTERM ]; then + if [ ! -x $TERMINAL_NAME ]; then echo "looks like found no terminal available for launch. maybe in sandbox or misconfigured system? fallbacking to execution without terminal" export TERM="xterm" - exec $LAUNCHER $@ + exec $LAUNCH_FILE $@ else # run in selected terminal and account for quirks - case $LAUNCHTERM in - terminal|termite) - # LAUNCHTERM consumes only one argument after -e - # options containing space characters are unsupported - exec $LAUNCHTERM -e "env TERM=xterm $LAUNCHER $@" - ;; - xterm|konsole|alacritty) - # LAUNCHTERM consumes all arguments after -e - exec $LAUNCHTERM -e env TERM=xterm $LAUNCHER "$@" - ;; - terminator|xfce4-terminal|mate-terminal) - # LAUNCHTERM consumes all arguments after -x - exec $LAUNCHTERM -x env TERM=xterm $LAUNCHER "$@" - ;; - gnome-terminal) - # LAUNCHTERM consumes all arguments after -- - exec $LAUNCHTERM -- env TERM=xterm $LAUNCHER "$@" - ;; - kitty) - # LAUNCHTERM consumes all trailing arguments - exec $LAUNCHTERM env TERM=xterm $LAUNCHER "$@" - ;; - *) - # If we don't know the terminal, just try to run it in the current shell. - env TERM=xterm $LAUNCHER "$@" - # if THAT fails, launch with no output - if [ $? -eq 127 ]; then - exec $LAUNCHER --no-terminal "$@" - 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 $@" + ;; + xterm|konsole|alacritty) + # consumes all arguments after -e + exec $TERMINAL_NAME -e env TERM=xterm $LAUNCH_FILE "$@" + ;; + terminator|xfce4-terminal|mate-terminal) + # consumes all arguments after -x + exec $TERMINAL_NAME -x env TERM=xterm $LAUNCH_FILE "$@" + ;; + gnome-terminal) + # consumes all arguments after -- + exec $TERMINAL_NAME -- env TERM=xterm $LAUNCH_FILE "$@" + ;; + kitty) + # consumes all trailing arguments + exec $TERMINAL_NAME env TERM=xterm $LAUNCH_FILE "$@" + ;; + *) + # If we don't know the terminal, just try to run it in the current shell. + env TERM=xterm $LAUNCH_FILE "$@" + # if THAT fails, launch with no output + if [ $? -eq 127 ]; then + exec $LAUNCH_FILE --no-terminal "$@" + fi esac fi fi -- cgit From 0f27d6f4c18812d90e51b10c05bfa1a69953c721 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 2 May 2021 18:26:02 -0400 Subject: fix new executable check in Linux launcher, update release notes (#775) --- docs/release-notes.md | 1 + src/SMAPI.Installer/assets/unix-launcher.sh | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src/SMAPI.Installer/assets/unix-launcher.sh') diff --git a/docs/release-notes.md b/docs/release-notes.md index 271609e2..73b9376d 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -18,6 +18,7 @@ * Fixed `StardewModdingAPI.bin.osx` on macOS overwritten with an identical file on launch, which resets file permissions (thanks to 007wayne!). * Fixed error for non-English players after returning to title, reloading, and entering town with a completed movie theater. * Fixed `world_clear` console command not removing resource clumps outside the farm and secret woods. + * Fixed error running SMAPI in a strict sandbox on Linux (thanks to kuesji!). * Fixed inconsistent spelling/style for 'macOS'. * For modders: diff --git a/src/SMAPI.Installer/assets/unix-launcher.sh b/src/SMAPI.Installer/assets/unix-launcher.sh index e0a106cb..a33c0d7f 100644 --- a/src/SMAPI.Installer/assets/unix-launcher.sh +++ b/src/SMAPI.Installer/assets/unix-launcher.sh @@ -72,42 +72,51 @@ else export TERMINAL_NAME="$(basename "$(readlink -f $(command -v x-terminal-emulator))")" fi - - if [ ! -x $TERMINAL_NAME ]; then - echo "looks like found no terminal available for launch. maybe in sandbox or misconfigured system? fallbacking to execution without terminal" - export TERM="xterm" - exec $LAUNCH_FILE $@ - else - # run in selected terminal and account for quirks + # run in selected terminal and account for quirks + export TERMINAL_PATH="$(command -v $TERMINAL_NAME)" + if [ -x $TERMINAL_PATH ]; then 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) # consumes all arguments after -e exec $TERMINAL_NAME -e env TERM=xterm $LAUNCH_FILE "$@" ;; + terminator|xfce4-terminal|mate-terminal) # consumes all arguments after -x exec $TERMINAL_NAME -x env TERM=xterm $LAUNCH_FILE "$@" ;; + gnome-terminal) # consumes all arguments after -- exec $TERMINAL_NAME -- env TERM=xterm $LAUNCH_FILE "$@" ;; + kitty) # consumes all trailing arguments exec $TERMINAL_NAME env TERM=xterm $LAUNCH_FILE "$@" ;; + *) # If we don't know the terminal, just try to run it in the current shell. + # If THAT fails, launch with no output. env TERM=xterm $LAUNCH_FILE "$@" - # if THAT fails, launch with no output if [ $? -eq 127 ]; then exec $LAUNCH_FILE --no-terminal "$@" fi esac + + ## terminal isn't executable; fallback to current shell or no terminal + 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." + env TERM=xterm $LAUNCH_FILE "$@" + if [ $? -eq 127 ]; then + exec $LAUNCH_FILE --no-terminal "$@" + fi fi fi -- cgit