diff --git a/global.sh b/global.sh new file mode 100755 index 00000000..363c2ecf --- /dev/null +++ b/global.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# This file is containing some global function needed for the script such as the config file tools + +conf_init() { + # initializing and reading the retrodeck config file + if [ ! -f $rd_conf ] + then # I have to initialize the variables as they cannot be red from an empty config file + touch $rd_conf + version="$(cat /app/retrodeck/version)" # version info taken from the version file + rdhome="$HOME/retrodeck" # the retrodeck home, aka ~/retrodeck + roms_folder="$rdhome/roms" # default roms folder location (intenral) + else # i just read the variables + source $rd_conf + fi +} + +conf_write() { + # writes the variables in the retrodeck config file + sed -i "s%version=.*%version=$version%" $rd_conf + sed -i "s%rdhome=.*%rdhome=$rdhome%" $rd_conf + sed -i "s%rdhome=.*%rdhome=$roms_folder" $rd_conf +} \ No newline at end of file diff --git a/net.retrodeck.retrodeck.yml b/net.retrodeck.retrodeck.yml index 65f03b92..be45244f 100644 --- a/net.retrodeck.retrodeck.yml +++ b/net.retrodeck.retrodeck.yml @@ -1018,6 +1018,9 @@ modules: - cp retrodeck.sh /app/bin/retrodeck.sh - chmod +x /app/bin/retrodeck.sh + + - cp global.sh /app/bin/global.sh + - chmod +x /app/bin/global.sh # Desktop entry - cp net.retrodeck.retrodeck.desktop /app/share/applications/net.retrodeck.retrodeck.desktop @@ -1073,4 +1076,6 @@ modules: - type: file path: net.retrodeck.retrodeck.desktop - type: file - path: net.retrodeck.retrodeck.appdata.xml \ No newline at end of file + path: net.retrodeck.retrodeck.appdata.xml + - type: file + path: global.sh \ No newline at end of file diff --git a/retrodeck.sh b/retrodeck.sh index 7f9ce114..05f8f6e7 100644 --- a/retrodeck.sh +++ b/retrodeck.sh @@ -1,10 +1,15 @@ #!/bin/bash +# Init default values, this may be overwritten by retrodeck.cfg as it sourced later with global.sh + lockfile="$HOME/retrodeck/.lock" # where the lockfile is located -version="$(cat /app/retrodeck/version)" # version info taken from the version file -rdhome="$HOME/retrodeck" # the retrodeck home, aka ~/retrodecck emuconfigs="/app/retrodeck/emu-configs" # folder with all the default emulator configs sdcard="/run/media/mmcblk0p1" # Steam Deck SD default path +rd_conf="/app/retrodeck/retrodeck.cfg" # RetroDECK config file path +version="$(cat /app/retrodeck/version)" # version info taken from the version file +rdhome="$HOME/retrodeck" # the retrodeck home, aka ~/retrodeck + +source global.sh # Functions area @@ -325,7 +330,9 @@ done if [ -f "$lockfile" ] && [ "$(cat "$lockfile")" != "$version" ]; then echo "Lockfile version is "$(cat "$lockfile")" but the actual version is $version" - post_update + conf_init # Initializing/reading the config file (sourced from global.sh) + post_update # Executing post update script + conf_write # Writing variables in the config file (sourced from global.sh) start_retrodeck exit 0 fi @@ -335,7 +342,9 @@ fi if [ ! -f "$lockfile" ]; then echo "Lockfile not found" - finit + conf_init # Initializing/reading the config file (sourced from global.sh) + finit # Executing First/Force init + conf_write # Writing variables in the config file (sourced from global.sh) exit 0 fi diff --git a/tools/move-roms.sh b/tools/move-roms.sh index a6bfafce..eca4bbb9 100644 --- a/tools/move-roms.sh +++ b/tools/move-roms.sh @@ -1,29 +1,30 @@ #!/bin/bash -if [ -d ~/retrodeck/roms ] && [ -d /run/media/mmcblk0p1/retrodeck/roms ] -then # found both internal and sd folders - zenity --title "RetroDECK" --warning --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --text="I found a roms folder both in internal and SD Card,\nin order to make this tool useful you should remove one of the two or merge them." +source global.sh + +zenity --question --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --cancel-label="Quit" --ok-label "Continue" --text="WARNING: this script is experimental\nplease be sure you back up your data before continuing.\n\nDo you want to continue?" +if [ $? == 1 ] #cancel +then exit 0 fi -if [ -d ~/retrodeck/roms ] && [ ! -d /run/media/mmcblk0p1/retrodeck/roms ] -then # found internal folder and not the external - roms_path=~/retrodeck - new_roms_path=/run/media/mmcblk0p1/retrodeck +zenity --question --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --cancel-label="Cancel" --ok-label "Browse" --text="The roms folder is now: $roms_folder\nplease select the new location.\nA retrodeck/roms folder will be created starting from the directory that you selected." +if [ $? == 1 ] #cancel +then + exit 0 fi -if [ ! -d ~/retrodeck/roms ] && [ -d /run/media/mmcblk0p1/retrodeck/roms ] -then # found external folder and not the internal - roms_path=/run/media/mmcblk0p1/retrodeck - new_roms_path=~/retrodeck -fi +new_roms_path="$(zenity --file-selection --title="Choose a new roms folder location" --directory)"/retrodeck/roms -zenity --title "RetroDECK" --question --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --text="Should I move the roms from\n\n$roms_path/roms\n\nto\n\n$new_roms_path/roms?" +zenity --title "RetroDECK" --question --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --text="Should I move the roms from\n\n$roms_folder\n\nto\n\n$new_roms_path?" if [ $? == 0 ] #yes then mkdir -p $new_roms_path - mv -f $roms_path/roms $new_roms_path/roms + mv -f $roms_folder $new_roms_path rm -f /var/config/emulationstation/ROMs - ln -s $new_roms_path/roms /var/config/emulationstation/ROMs - rm -f $roms_path/roms + ln -s $new_roms_path /var/config/emulationstation/ROMs + rm -f $roms_folder + zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --text="Done\nYour roms are now located in:\n\n$roms_folder\n\nPress OK to continue." + $roms_folder=$new_roms_path # Updating variable + conf_write # Writing variables in the config file (sourced from global.sh) fi