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-07-23 18:19:03 +00:00
|
|
|
rd_conf="/var/config/retrodeck/retrodeck.cfg"
|
2022-07-04 20:49:58 +00:00
|
|
|
|
2022-06-09 08:25:20 +00:00
|
|
|
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
|
2022-07-23 18:19:03 +00:00
|
|
|
echo "RetroDECK config file not found in $rd_conf"
|
|
|
|
echo "Initializing"
|
2022-06-09 08:25:20 +00:00
|
|
|
touch $rd_conf
|
2022-07-04 20:49:58 +00:00
|
|
|
|
|
|
|
# Variables to manage: adding a variable here means adding it to conf_write()
|
2022-07-23 18:19:03 +00:00
|
|
|
echo "#!/bin/bash" >> $rd_conf
|
|
|
|
|
|
|
|
# version info taken from the version file
|
|
|
|
version="$(cat /app/retrodeck/version)"
|
|
|
|
echo "version=$version" >> $rd_conf
|
|
|
|
|
|
|
|
# the retrodeck home, aka ~/retrodeck
|
|
|
|
rdhome="$HOME/retrodeck"
|
|
|
|
echo "rdhome=$rdhome" >> $rd_conf
|
|
|
|
|
|
|
|
# default roms folder location (internal)
|
2022-07-25 19:01:45 +00:00
|
|
|
roms_folder="$roms_folder"
|
2022-07-23 18:19:03 +00:00
|
|
|
echo "roms_folder=$roms_folder" >> $rd_conf
|
|
|
|
|
2022-07-04 20:49:58 +00:00
|
|
|
|
2022-06-09 08:25:20 +00:00
|
|
|
else # i just read the variables
|
2022-07-23 18:19:03 +00:00
|
|
|
echo "Found RetroDECK config file in $rd_conf"
|
|
|
|
echo "Loading it"
|
2022-06-09 08:25:20 +00:00
|
|
|
source $rd_conf
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
conf_write() {
|
|
|
|
# writes the variables in the retrodeck config file
|
2022-06-14 12:57:51 +00:00
|
|
|
|
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-06-14 12:57:51 +00:00
|
|
|
sed -i "s%version=.*%version=$version%" $rd_conf
|
|
|
|
fi
|
|
|
|
|
2022-07-23 18:19:03 +00:00
|
|
|
if [ ! -z "$rdhome" ]
|
|
|
|
then
|
2022-06-14 12:57:51 +00:00
|
|
|
sed -i "s%rdhome=.*%rdhome=$rdhome%" $rd_conf
|
|
|
|
fi
|
|
|
|
|
2022-07-23 18:19:03 +00:00
|
|
|
if [ ! -z "$roms_folder" ]
|
|
|
|
then
|
2022-07-25 19:01:45 +00:00
|
|
|
sed -i "s%roms_folder=.*%roms_folder=$roms_folder%" $rd_conf
|
2022-06-14 12:57:51 +00:00
|
|
|
fi
|
|
|
|
|
2022-06-09 08:25:20 +00:00
|
|
|
}
|