NEW VARIABLES SYSTEM

This commit is contained in:
xargon 2022-06-09 10:25:20 +02:00
parent 23e0ebe755
commit d4a6e1f170
4 changed files with 59 additions and 21 deletions

23
global.sh Executable file
View file

@ -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
}

View file

@ -1018,6 +1018,9 @@ modules:
- cp retrodeck.sh /app/bin/retrodeck.sh - cp retrodeck.sh /app/bin/retrodeck.sh
- chmod +x /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 # Desktop entry
- cp net.retrodeck.retrodeck.desktop /app/share/applications/net.retrodeck.retrodeck.desktop - cp net.retrodeck.retrodeck.desktop /app/share/applications/net.retrodeck.retrodeck.desktop
@ -1073,4 +1076,6 @@ modules:
- type: file - type: file
path: net.retrodeck.retrodeck.desktop path: net.retrodeck.retrodeck.desktop
- type: file - type: file
path: net.retrodeck.retrodeck.appdata.xml path: net.retrodeck.retrodeck.appdata.xml
- type: file
path: global.sh

View file

@ -1,10 +1,15 @@
#!/bin/bash #!/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 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 emuconfigs="/app/retrodeck/emu-configs" # folder with all the default emulator configs
sdcard="/run/media/mmcblk0p1" # Steam Deck SD default path 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 # Functions area
@ -325,7 +330,9 @@ done
if [ -f "$lockfile" ] && [ "$(cat "$lockfile")" != "$version" ]; if [ -f "$lockfile" ] && [ "$(cat "$lockfile")" != "$version" ];
then then
echo "Lockfile version is "$(cat "$lockfile")" but the actual version is $version" 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 start_retrodeck
exit 0 exit 0
fi fi
@ -335,7 +342,9 @@ fi
if [ ! -f "$lockfile" ]; if [ ! -f "$lockfile" ];
then then
echo "Lockfile not found" 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 exit 0
fi fi

View file

@ -1,29 +1,30 @@
#!/bin/bash #!/bin/bash
if [ -d ~/retrodeck/roms ] && [ -d /run/media/mmcblk0p1/retrodeck/roms ] source global.sh
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." 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 exit 0
fi fi
if [ -d ~/retrodeck/roms ] && [ ! -d /run/media/mmcblk0p1/retrodeck/roms ] 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."
then # found internal folder and not the external if [ $? == 1 ] #cancel
roms_path=~/retrodeck then
new_roms_path=/run/media/mmcblk0p1/retrodeck exit 0
fi fi
if [ ! -d ~/retrodeck/roms ] && [ -d /run/media/mmcblk0p1/retrodeck/roms ] new_roms_path="$(zenity --file-selection --title="Choose a new roms folder location" --directory)"/retrodeck/roms
then # found external folder and not the internal
roms_path=/run/media/mmcblk0p1/retrodeck
new_roms_path=~/retrodeck
fi
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 if [ $? == 0 ] #yes
then then
mkdir -p $new_roms_path 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 rm -f /var/config/emulationstation/ROMs
ln -s $new_roms_path/roms /var/config/emulationstation/ROMs ln -s $new_roms_path /var/config/emulationstation/ROMs
rm -f $roms_path/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 fi