2022-06-09 08:25:20 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# This file is containing some global function needed for the script such as the config file tools
|
|
|
|
|
2022-09-06 13:24:36 +00:00
|
|
|
# Static variables
|
|
|
|
rd_conf="/var/config/retrodeck/retrodeck.cfg" # RetroDECK config file path
|
|
|
|
emuconfigs="/app/retrodeck/emu-configs" # folder with all the default emulator configs
|
|
|
|
lockfile="/var/config/retrodeck/.lock" # where the lockfile is located
|
2022-09-19 07:04:44 +00:00
|
|
|
default_sd="/run/media/mmcblk0p1" # Steam Deck SD default path
|
2022-09-06 13:24:36 +00:00
|
|
|
hard_version="$(cat '/app/retrodeck/version')" # hardcoded version (in the readonly filesystem)
|
2022-09-06 12:46:59 +00:00
|
|
|
|
2022-06-09 08:25:20 +00:00
|
|
|
conf_write() {
|
|
|
|
# writes the variables in the retrodeck config file
|
2022-06-14 12:57:51 +00:00
|
|
|
|
2022-09-17 15:03:25 +00:00
|
|
|
echo "DEBUG: printing the config file content before writing it:"
|
2022-09-17 15:17:27 +00:00
|
|
|
cat "$rd_conf"
|
2022-09-17 15:03:25 +00:00
|
|
|
echo ""
|
|
|
|
|
2022-07-25 19:01:45 +00:00
|
|
|
echo "Writing the config file: $rd_conf"
|
2022-07-23 18:19:03 +00:00
|
|
|
|
2022-06-14 12:57:51 +00:00
|
|
|
# TODO: this can be optimized with a while and a list of variables to check
|
2022-07-23 18:19:03 +00:00
|
|
|
if [ ! -z "$version" ] #if the variable is not null then I update it
|
|
|
|
then
|
2022-09-17 15:17:27 +00:00
|
|
|
sed -i "s%version=.*%version=$version%" "$rd_conf"
|
2022-06-14 12:57:51 +00:00
|
|
|
fi
|
|
|
|
|
2022-07-23 18:19:03 +00:00
|
|
|
if [ ! -z "$rdhome" ]
|
|
|
|
then
|
2022-09-17 15:17:27 +00:00
|
|
|
sed -i "s%rdhome=.*%rdhome=$rdhome%" "$rd_conf"
|
2022-06-14 12:57:51 +00:00
|
|
|
fi
|
|
|
|
|
2022-07-23 18:19:03 +00:00
|
|
|
if [ ! -z "$roms_folder" ]
|
|
|
|
then
|
2022-09-17 15:17:27 +00:00
|
|
|
sed -i "s%roms_folder=.*%roms_folder=$roms_folder%" "$rd_conf"
|
2022-06-14 12:57:51 +00:00
|
|
|
fi
|
|
|
|
|
2022-10-01 13:58:05 +00:00
|
|
|
if [ ! -z "$saves_folder" ]
|
|
|
|
then
|
|
|
|
sed -i "s%saves_folder=.*%saves_folder=$saves_folder%" "$rd_conf"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z "$states_folder" ]
|
|
|
|
then
|
|
|
|
sed -i "s%states_folder=.*%states_folder=$states_folder%" "$rd_conf"
|
|
|
|
fi
|
|
|
|
|
2022-07-27 09:20:38 +00:00
|
|
|
if [ ! -z "$media_folder" ]
|
|
|
|
then
|
2022-09-17 15:17:27 +00:00
|
|
|
sed -i "s%media_folder=.*%media_folder=$media_folder%" "$rd_conf"
|
2022-07-27 09:20:38 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z "$themes_folder" ]
|
|
|
|
then
|
2022-09-17 15:17:27 +00:00
|
|
|
sed -i "s%themes_folder=.*%themes_folder=$themes_folder%" "$rd_conf"
|
2022-07-27 09:20:38 +00:00
|
|
|
fi
|
|
|
|
|
2022-09-19 07:28:58 +00:00
|
|
|
if [ ! -z "$sdcard" ]
|
|
|
|
then
|
|
|
|
sed -i "s%sdcard=.*%sdcard=$sdcard%" "$rd_conf"
|
|
|
|
fi
|
2022-09-17 15:03:25 +00:00
|
|
|
echo "DEBUG: New contents:"
|
2022-09-17 15:17:27 +00:00
|
|
|
cat "$rd_conf"
|
2022-09-17 15:03:25 +00:00
|
|
|
echo ""
|
|
|
|
|
2022-09-17 15:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# If there is no config file I initalize the file with the the default values
|
|
|
|
if [ ! -f "$rd_conf" ]
|
|
|
|
then
|
|
|
|
|
|
|
|
echo "RetroDECK config file not found in $rd_conf"
|
|
|
|
echo "Initializing"
|
2022-10-06 19:31:30 +00:00
|
|
|
touch $rd_conf
|
|
|
|
|
2022-09-19 07:25:49 +00:00
|
|
|
# Initializing the variables
|
2022-09-17 15:20:39 +00:00
|
|
|
version="$hard_version" # if we are here means that the we are in a new installation, so the version is valorized with the hardcoded one
|
|
|
|
rdhome="$HOME/retrodeck" # the retrodeck home, aka ~/retrodeck
|
|
|
|
roms_folder="$rdhome/roms" # the default roms folder path
|
2022-09-29 21:26:02 +00:00
|
|
|
saves_folder="$rdhome/saves" # the default saves folder path
|
|
|
|
states_folder="$rdhome/states" # the default states folder path
|
2022-09-21 14:22:00 +00:00
|
|
|
media_folder="$rdhome/downloaded_media" # the media folder, where all the scraped data is downloaded into
|
|
|
|
themes_folder="$rdhome/themes" # the themes folder
|
2022-09-19 07:05:20 +00:00
|
|
|
sdcard="$default_sd" # Steam Deck SD default path
|
2022-09-17 15:20:39 +00:00
|
|
|
|
2022-09-19 07:25:49 +00:00
|
|
|
# Writing the variables for the first time
|
2022-09-21 14:22:00 +00:00
|
|
|
echo '#!/bin/bash' >> $rd_conf
|
2022-09-19 07:25:49 +00:00
|
|
|
echo "version=$version" >> $rd_conf
|
|
|
|
echo "rdhome=$rdhome" >> $rd_conf
|
|
|
|
echo "roms_folder=$roms_folder" >> $rd_conf
|
2022-09-29 21:26:02 +00:00
|
|
|
echo "saves_folder=$saves_folder" >> $rd_conf
|
|
|
|
echo "states_folder=$states_folder" >> $rd_conf
|
2022-09-19 07:25:49 +00:00
|
|
|
echo "media_folder=$media_folder" >> $rd_conf
|
|
|
|
echo "themes_folder=$themes_folder" >> $rd_conf
|
|
|
|
echo "sdcard=$sdcard" >> $rd_conf
|
|
|
|
|
2022-09-24 18:28:49 +00:00
|
|
|
echo "Setting config file permissions"
|
|
|
|
chmod +rwx $rd_conf
|
|
|
|
|
2022-09-17 15:20:39 +00:00
|
|
|
# If the config file is existing i just read the variables (source it)
|
|
|
|
else
|
|
|
|
echo "Found RetroDECK config file in $rd_conf"
|
|
|
|
echo "Loading it"
|
|
|
|
source "$rd_conf"
|
|
|
|
fi
|