Skip to content
RazZziel edited this page Jul 27, 2014 · 6 revisions

Console apps

Text-only apps will work inside AppImages justs fine.

The only possible problem is that users will expect to be able to run the app when clicking on the .run file, but if the app is purely text-only, nothing will happen.

To workaround this issue, we'll detect if the user is in an interactive shell or not. If he is, we'll launch the application normally. If he isn't, we'll launch some form of terminal emulator available on the system, and launch the app inside it.

run_shell() {
        if tty -s <&1; then
                "$@"
        else
                echo "*** Detected non-interactive shell, launching terminal emulator..."

                if which konsole; then konsole -e "$@"
                elif which gnome-terminal; then gnome-terminal --geometry=77x25 --disable-factory -x "$@"
                elif which xterm; then xterm -geometry 77x25 -e "$@"
                elif which terminator; then terminator -e "$@" # Not tested
                elif which lxterminal; then lxterminal -e "$@" # Not tested
                elif which sakura; then sakura -e "$@" # Not tested
                elif which aterm; then aterm -e "$@" # Not tested
                else
                        echo "No terminal emulator found, please install one of the following:"
                        echo "  konsole, terminator, lxterminal, sakura, gnome-terminal, xterm, aterm"
                fi
        fi
}

Now use that function like:

run_shell bash -c "<whatever you want to run>"

For example, in my AppRun template, I use:

run_shell bash -c ""$BINARY" $BINARY_ARGS $@"

Considerations

On my AppRun template, I usually copy all game output to a file for debugging purposes if the game fails to run, like this:

{
        run_shell bash -c ""$BINARY" $BINARY_ARGS $@"
        ret=$?
} 2>&1 | tee "$LOGFILE"

However, this will break interactive shell detection, because every single command run inside tee is considered to be run in a non-interactive shell. Hence, I need to disable output redirection:

{
        run_shell bash -c ""$BINARY" $BINARY_ARGS $@"
        ret=$?
}