From cb2424383935a01bd21991022ff7c2ba4c459c6a Mon Sep 17 00:00:00 2001 From: twojstaryzdomu Date: Wed, 15 Jun 2022 16:36:14 +0200 Subject: [PATCH 1/3] Refactor runcommand.sh's output directory into a global variable and use /tmp as fallback This is to allow another directory for runcommand.sh outputs for cases when output are worth preserving (i.e. crash). Also, /dev/shm may not be accessible on all environments, for user discretionary reasons. When /dev/shm doesn't exist or isn't writable, Fall back to /tmp. --- scriptmodules/supplementary/runcommand/runcommand.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scriptmodules/supplementary/runcommand/runcommand.sh b/scriptmodules/supplementary/runcommand/runcommand.sh index 3d9fe45d13..153c3bfbe0 100755 --- a/scriptmodules/supplementary/runcommand/runcommand.sh +++ b/scriptmodules/supplementary/runcommand/runcommand.sh @@ -79,7 +79,11 @@ ROOTDIR="/opt/retropie" CONFIGDIR="$ROOTDIR/configs" -LOG="/dev/shm/runcommand.log" +OUTPUTDIR="/dev/shm" +[ -d "${OUTPUTDIR}" ] \ + && [ -w "${OUTPUTDIR}" ] \ + || OUTPUTDIR=/tmp +LOG="${OUTPUTDIR}/runcommand.log" RUNCOMMAND_CONF="$CONFIGDIR/all/runcommand.cfg" VIDEO_CONF="$CONFIGDIR/all/videomodes.cfg" @@ -929,7 +933,7 @@ function switch_fb_res() { function build_xinitrc() { local mode="$1" - local xinitrc="/dev/shm/retropie_xinitrc" + local xinitrc="${OUTPUTDIR}/retropie_xinitrc" case "$mode" in clear) @@ -1068,7 +1072,7 @@ function config_backend() { } function retroarch_append_config() { - local conf="/dev/shm/retroarch.cfg" + local conf="${OUTPUTDIR}/retroarch.cfg" local dim # only for retroarch emulators @@ -1317,7 +1321,7 @@ function launch_command() { } function log_info() { - echo -e "$SYSTEM\n$EMULATOR\n$ROM\n$COMMAND" >/dev/shm/runcommand.info + echo -e "$SYSTEM\n$EMULATOR\n$ROM\n$COMMAND" >${OUTPUTDIR}/runcommand.info } function runcommand() { From db699392bd9e73c985127506cca738b879639e98 Mon Sep 17 00:00:00 2001 From: twojstaryzdomu Date: Sat, 18 Jun 2022 00:47:24 +0200 Subject: [PATCH 2/3] Change name to LOG_DIR and add a configuration menu --- scriptmodules/supplementary/runcommand.sh | 8 ++++++++ .../supplementary/runcommand/runcommand.sh | 15 +++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/scriptmodules/supplementary/runcommand.sh b/scriptmodules/supplementary/runcommand.sh index 1b212ff228..395b5f6049 100644 --- a/scriptmodules/supplementary/runcommand.sh +++ b/scriptmodules/supplementary/runcommand.sh @@ -43,6 +43,7 @@ function install_bin_runcommand() { iniSet "governor" "" iniSet "disable_menu" "0" iniSet "image_delay" "2" + iniSet "log_dir" "" chown $user:$user "$configdir/all/runcommand.cfg" fi if [[ ! -f "$configdir/all/runcommand-launch-dialog.cfg" ]]; then @@ -110,6 +111,7 @@ function gui_runcommand() { 'disable_joystick=0' \ 'image_delay=2' \ 'governor=' \ + 'log_dir=' \ )" [[ -z "$governor" ]] && governor="Default: don't change" @@ -137,6 +139,7 @@ function gui_runcommand() { options+=(4 "Launch image delay in seconds (currently $image_delay)") options+=(5 "CPU governor configuration (currently: $governor)") + options+=(6 "Set log/scratch directory (currently: ${log_dir:-/dev/shm})") local choice=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) [[ -z "$choice" ]] && break @@ -159,6 +162,11 @@ function gui_runcommand() { 5) governor_runcommand ;; + 6) + cmd=(dialog --backtitle "$__backtitle" --inputbox "Please enter the log directory" 10 60 "$log_dir") + choice=$("${cmd[@]}" 2>&1 >/dev/tty) + iniSet "log_dir" "$choice" + ;; esac done } diff --git a/scriptmodules/supplementary/runcommand/runcommand.sh b/scriptmodules/supplementary/runcommand/runcommand.sh index 153c3bfbe0..a7def72267 100755 --- a/scriptmodules/supplementary/runcommand/runcommand.sh +++ b/scriptmodules/supplementary/runcommand/runcommand.sh @@ -79,11 +79,6 @@ ROOTDIR="/opt/retropie" CONFIGDIR="$ROOTDIR/configs" -OUTPUTDIR="/dev/shm" -[ -d "${OUTPUTDIR}" ] \ - && [ -w "${OUTPUTDIR}" ] \ - || OUTPUTDIR=/tmp -LOG="${OUTPUTDIR}/runcommand.log" RUNCOMMAND_CONF="$CONFIGDIR/all/runcommand.cfg" VIDEO_CONF="$CONFIGDIR/all/videomodes.cfg" @@ -123,6 +118,10 @@ function get_config() { iniGet "image_delay" IMAGE_DELAY="$ini_value" [[ -z "$IMAGE_DELAY" ]] && IMAGE_DELAY=2 + iniGet "log_dir" + LOG_DIR="$ini_value" + [[ -z "$LOG_DIR" ]] && LOG_DIR="/dev/shm" + LOG="$LOG_DIR/runcommand.log" fi if [[ -n "$DISPLAY" ]] && $XRANDR &>/dev/null; then @@ -933,7 +932,7 @@ function switch_fb_res() { function build_xinitrc() { local mode="$1" - local xinitrc="${OUTPUTDIR}/retropie_xinitrc" + local xinitrc="$LOG_DIR/retropie_xinitrc" case "$mode" in clear) @@ -1072,7 +1071,7 @@ function config_backend() { } function retroarch_append_config() { - local conf="${OUTPUTDIR}/retroarch.cfg" + local conf="$LOG_DIR/retroarch.cfg" local dim # only for retroarch emulators @@ -1321,7 +1320,7 @@ function launch_command() { } function log_info() { - echo -e "$SYSTEM\n$EMULATOR\n$ROM\n$COMMAND" >${OUTPUTDIR}/runcommand.info + echo -e "$SYSTEM\n$EMULATOR\n$ROM\n$COMMAND" >"$LOG_DIR/runcommand.info" } function runcommand() { From de233e8d49e2c07db5cfbaf9ab5de2559c492071 Mon Sep 17 00:00:00 2001 From: twojstaryzdomu Date: Sat, 18 Jun 2022 00:48:27 +0200 Subject: [PATCH 3/3] Ensure LOG_DIR exists or default to /dev/shm --- scriptmodules/supplementary/runcommand/runcommand.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scriptmodules/supplementary/runcommand/runcommand.sh b/scriptmodules/supplementary/runcommand/runcommand.sh index a7def72267..b40191240b 100755 --- a/scriptmodules/supplementary/runcommand/runcommand.sh +++ b/scriptmodules/supplementary/runcommand/runcommand.sh @@ -120,7 +120,7 @@ function get_config() { [[ -z "$IMAGE_DELAY" ]] && IMAGE_DELAY=2 iniGet "log_dir" LOG_DIR="$ini_value" - [[ -z "$LOG_DIR" ]] && LOG_DIR="/dev/shm" + [[ -d "$LOG_DIR" ]] && LOG_DIR="/dev/shm" LOG="$LOG_DIR/runcommand.log" fi