2022-03-27 13:30:22 +00:00
#!/bin/bash
2022-06-09 08:25:20 +00:00
# Init default values, this may be overwritten by retrodeck.cfg as it sourced later with global.sh
2022-07-18 08:04:17 +00:00
lockfile = lockfile = "/var/config/retrodeck/.lock" # where the lockfile is located
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
2022-06-09 08:25:20 +00:00
source global.sh
2022-03-30 14:14:43 +00:00
2022-07-10 19:48:19 +00:00
# We moved the lockfile in /var/config/retrodeck in order to solve issue #53 - Remove in a few versions
if [ -f " $HOME /retrodeck/.lock " ]
then
mv " $HOME /retrodeck/.lock " $lockfile
fi
2022-05-19 14:30:43 +00:00
# Functions area
dir_prep( ) {
# This script is creating a symlink preserving old folder contents and moving them in the new one
# Call me with:
# dir prep "real dir" "symlink location"
real = " $1 "
symlink = " $2 "
2022-06-16 09:13:07 +00:00
echo -e " \n[DIR PREP]\nMoving $symlink in $real " #DEBUG
2022-05-19 14:30:43 +00:00
# if the dest dir exists we want to backup it
if [ -d " $symlink " ] ;
then
echo " $symlink found " #DEBUG
mv -fv " $symlink " " $symlink .old "
fi
# if the real dir doesn't exist we create it
if [ ! -d " $real " ] ;
then
echo " $real not found, creating it " #DEBUG
mkdir -pv " $real "
fi
# creating the symlink
echo " linking $real in $symlink " #DEBUG
2022-05-20 05:41:46 +00:00
mkdir -pv " $( dirname " $symlink " ) " # creating the full path except the last folder
ln -sv " $real " " $symlink "
2022-05-19 14:30:43 +00:00
# moving everything from the old folder to the new one, delete the old one
if [ -d " $symlink .old " ] ;
then
echo " Moving the data from $symlink .old to $real " #DEBUG
2022-06-08 10:13:43 +00:00
mv -fv " $symlink " .old/* $real
2022-05-19 14:30:43 +00:00
echo " Removing $symlink .old " #DEBUG
rm -rf " $symlink .old "
fi
2022-06-16 09:13:07 +00:00
echo -e " $symlink is now $real \n "
2022-05-19 14:30:43 +00:00
}
2022-05-11 11:43:15 +00:00
2022-05-19 14:30:43 +00:00
tools_init( ) {
rm -rfv /var/config/retrodeck/tools/
mkdir -pv /var/config/retrodeck/tools/
cp -r /app/retrodeck/tools/* /var/config/retrodeck/tools/
mkdir -pv /var/config/emulationstation/.emulationstation/custom_systems/tools/
cp /app/retrodeck/tools-gamelist.xml /var/config/retrodeck/tools/gamelist.xml
}
standalones_init( ) {
# This script is configuring the standalone emulators with the default files present in emuconfigs folder
2022-06-16 09:13:07 +00:00
echo "----------------------"
2022-05-19 14:30:43 +00:00
echo "Initializing standalone emulators"
2022-06-16 09:13:07 +00:00
echo "----------------------"
2022-05-19 14:30:43 +00:00
# Yuzu
2022-06-16 09:13:07 +00:00
echo "----------------------"
echo "Initializing YUZU"
echo "----------------------"
2022-05-19 14:30:43 +00:00
# removing dead symlinks as they were present in a past version
if [ -d $rdhome /bios/switch ] ; then
find $rdhome /bios/switch -xtype l -exec rm { } \;
fi
# initializing the keys folder
dir_prep " $rdhome /bios/switch/keys " "/var/data/yuzu/keys"
# initializing the firmware folder
2022-05-22 08:03:30 +00:00
dir_prep " $rdhome /bios/switch/registered " "/var/data/yuzu/nand/system/Contents/registered"
2022-05-19 14:30:43 +00:00
# configuring Yuzu
mkdir -pv /var/config/yuzu/
2022-07-10 10:08:41 +00:00
cp -fvr $emuconfigs /yuzu/* /var/config/yuzu/
2022-06-08 12:42:36 +00:00
sed -i 's#~/retrodeck#' $rdhome '#g' /var/config/yuzu/qt-config.ini
2022-06-01 20:57:37 +00:00
dir_prep " $rdhome /screenshots " "/var/data/yuzu/screenshots"
2022-05-19 14:30:43 +00:00
# Dolphin
2022-06-16 09:13:07 +00:00
echo "----------------------"
echo "Initializing DOLPHIN"
echo "----------------------"
2022-05-19 14:30:43 +00:00
mkdir -pv /var/config/dolphin-emu/
2022-07-10 10:08:41 +00:00
cp -fvr " $emuconfigs /dolphin/ " * /var/config/dolphin-emu/
2022-06-01 19:28:45 +00:00
dir_prep " $rdhome /saves " "/var/data/dolphin-emu/GBA/Saves"
2022-06-16 09:13:07 +00:00
dir_prep " $rdhome /saves " "/var/data/dolphin-emu/Wii"
2022-05-19 14:30:43 +00:00
# pcsx2
2022-06-16 09:13:07 +00:00
echo "----------------------"
echo "Initializing PCSX2"
echo "----------------------"
2022-05-19 14:30:43 +00:00
mkdir -pv /var/config/PCSX2/inis/
2022-06-16 09:13:07 +00:00
cp -fvr $emuconfigs /PCSX2_ui.ini /var/config/PCSX2/inis/
2022-06-08 12:42:36 +00:00
sed -i 's#~/retrodeck#' $rdhome '#g' /var/config/PCSX2/inis/PCSX2_ui.ini
2022-06-16 09:13:07 +00:00
cp -fvr $emuconfigs /GS.ini /var/config/PCSX2/inis/
cp -fvr $emuconfigs /PCSX2_vm.ini /var/config/PCSX2/inis/
2022-06-01 19:16:10 +00:00
dir_prep " $rdhome /states " "/var/config/PCSX2/sstates"
dir_prep " $rdhome /screenshots " "/var/config/PCSX2/snaps"
dir_prep " $rdhome /.logs " "/var/config/PCSX2/logs"
2022-07-17 06:42:08 +00:00
dir_prep " $rdhome /bios " " $rdhome /bios/pcsx2/bios "
2022-05-19 14:30:43 +00:00
# MelonDS
2022-06-16 09:13:07 +00:00
echo "----------------------"
echo "Initializing MELONDS"
echo "----------------------"
2022-05-19 14:30:43 +00:00
mkdir -pv /var/config/melonDS/
dir_prep " $rdhome /bios " "/var/config/melonDS/bios"
2022-06-16 09:13:07 +00:00
cp -fvr $emuconfigs /melonDS.ini /var/config/melonDS/
2022-06-08 12:25:58 +00:00
# Replace ~/retrodeck with $rdhome as ~ cannot be understood by MelonDS
sed -i 's#~/retrodeck#' $rdhome '#g' /var/config/melonDS/melonDS.ini
2022-05-19 14:30:43 +00:00
# CITRA
2022-07-21 18:40:44 +00:00
echo "------------------------"
2022-06-16 09:13:07 +00:00
echo "Initializing CITRA"
2022-07-21 18:40:44 +00:00
echo "------------------------"
2022-05-19 14:30:43 +00:00
mkdir -pv /var/config/citra-emu/
cp -fv $emuconfigs /citra-qt-config.ini /var/config/citra-emu/qt-config.ini
2022-06-30 08:01:29 +00:00
sed -i 's#~/retrodeck#' $rdhome '#g' /var/config/citra-emu/qt-config.ini
#TODO: do the same with roms folders after new variables is pushed (check even the others qt-emu)
#But actually everything is always symlinked to retrodeck/roms so it might be not needed
#sed -i 's#~/retrodeck#'$rdhome'#g' /var/config/citra-emu/qt-config.ini
2022-05-19 14:30:43 +00:00
# RPCS3
2022-07-21 18:40:44 +00:00
echo "------------------------"
2022-06-16 09:13:07 +00:00
echo "Initializing RPCS3"
2022-07-21 18:40:44 +00:00
echo "------------------------"
2022-05-19 14:30:43 +00:00
mkdir -pv /var/config/rpcs3/
2022-06-16 09:13:07 +00:00
cp -fvr $emuconfigs /config.yml /var/config/rpcs3/
2022-05-19 14:30:43 +00:00
2022-07-18 08:47:51 +00:00
# XEMU
2022-07-21 18:40:44 +00:00
echo "------------------------"
2022-07-18 08:47:51 +00:00
echo "Initializing XEMU"
2022-07-21 18:40:44 +00:00
echo "------------------------"
2022-07-18 08:47:51 +00:00
mkdir -pv $rdhome /saves/xemu
cp -fv $emuconfigs /xemu.toml /var/data/xemu/xemu.toml
sed -i 's#/home/deck/retrodeck#' $rdhome '#g' /var/data/xemu/xemu.toml
2022-07-18 17:32:05 +00:00
# Preparing HD dummy Image if the image is not found
if [ ! -f $rdhome /bios/xbox_hdd.qcow2 ]
then
wget "https://github.com/mborgerson/xemu-hdd-image/releases/latest/download/xbox_hdd.qcow2.zip" -P $rdhome /bios/
unzip $rdhome /bios/xbox_hdd.qcow2.zip $rdhome /bios/
rm -rfv $rdhome /bios/xbox_hdd.qcow2.zip
fi
2022-07-18 08:47:51 +00:00
2022-07-21 18:40:44 +00:00
# PPSSPPSDL
echo "------------------------"
echo "Initializing PPSSPPSDL"
echo "------------------------"
mkdir -p /var/config/ppsspp/PSP/SYSTEM/
cp -fv $emuconfigs /ppssppsdl/* /var/config/ppsspp/PSP/SYSTEM/
sed -i 's#/home/deck/retrodeck#' $rdhome '#g' /var/config/ppsspp/PSP/SYSTEM/ppsspp.ini
2022-07-21 18:52:53 +00:00
2022-05-19 14:30:43 +00:00
# PICO-8
2022-05-20 06:37:43 +00:00
# Moved PICO-8 stuff in the finit as only it knows here roms folders is
2022-05-19 14:30:43 +00:00
}
ra_init( ) {
dir_prep " $rdhome /bios " "/var/config/retroarch/system"
mkdir -pv /var/config/retroarch/cores/
cp /app/share/libretro/cores/* /var/config/retroarch/cores/
2022-07-21 18:52:53 +00:00
cp -fv $emuconfigs /retroarch.cfg /var/config/retroarch/
cp -fv $emuconfigs /retroarch-core-options.cfg /var/config/retroarch/
2022-05-19 14:30:43 +00:00
#rm -rf $rdhome/bios/bios # in some situations a double bios symlink is created
2022-06-08 12:42:36 +00:00
sed -i 's#~/retrodeck#' $rdhome '#g' /var/config/retroarch/retroarch.cfg
2022-07-21 18:40:44 +00:00
# PPSSPP
echo "--------------------------------"
echo "Initializing PPSSPP_LIBRETRO"
echo "--------------------------------"
if [ -d $rdhome /bios/PPSSPP/flash0/font ]
then
2022-07-21 18:52:53 +00:00
mv -fv $rdhome /bios/PPSSPP/flash0/font $rdhome /bios/PPSSPP/flash0/font.bak
2022-07-21 18:40:44 +00:00
fi
2022-07-21 18:52:53 +00:00
mkdir -p $rdhome /bios/PPSSPP
2022-07-21 18:40:44 +00:00
wget "https://github.com/hrydgard/ppsspp/archive/refs/heads/master.zip" -P $rdhome /bios/PPSSPP
unzip " $rdhome /bios/PPSSPP/master.zip " $rdhome /bios/PPSSPP/
2022-07-21 18:52:53 +00:00
rm -fv " $rdhome /bios/PPSSPP/master.zip "
2022-07-21 18:40:44 +00:00
if [ -d $rdhome /bios/PPSSPP/flash0/font.bak ]
then
2022-07-21 18:52:53 +00:00
mv -fv $rdhome /bios/PPSSPP/flash0/font.bak $rdhome /bios/PPSSPP/flash0/font
2022-07-21 18:40:44 +00:00
fi
2022-07-21 18:52:53 +00:00
# MSX / SVI / ColecoVision / SG-1000
echo "-----------------------------------------------------------"
echo "Initializing MSX / SVI / ColecoVision / SG-1000 LIBRETRO"
echo "-----------------------------------------------------------"
wget "http://bluemsx.msxblue.com/rel_download/blueMSXv282full.zip" -P $rdhome /bios/MSX
unzip " $rdhome /bios/MSX/blueMSXv282full.zip " $rdhome /bios/MSX
mv -rfv $rdhome /bios/MSX/Databases $rdhome /bios/Databases
mv -rfv $rdhome /bios/MSX/Machines $rdhome /bios/Machines
rm -rfv $rdhome /bios/MSX
2022-05-19 14:30:43 +00:00
}
create_lock( ) {
# creating RetroDECK's lock file and writing the version number in it
echo " $version " > " $lockfile "
}
post_update( ) {
# post update script
echo "Executing post-update script"
2022-07-10 19:48:19 +00:00
# Unhiding downloaded media from the previous versions
if [ -d " $rdhome /.downloaded_media " ]
then
2022-07-11 15:10:51 +00:00
mv -fv " $rdhome /.downloaded_media " " $rdhome /downloaded_media "
2022-07-10 19:48:19 +00:00
fi
# Unhiding themes folder from the previous versions
if [ -d " $rdhome /.themes " ]
2022-07-10 19:41:37 +00:00
then
2022-07-11 15:10:51 +00:00
mv -fv " $rdhome /.themes " " $rdhome /themes "
2022-07-10 19:41:37 +00:00
fi
2022-07-10 19:48:19 +00:00
# Doing the dir prep as we don't know from which version we came - Remove in a few versions
dir_prep " $rdhome /downloaded_media " "/var/config/emulationstation/.emulationstation/downloaded_media"
dir_prep " $rdhome /themes " "/var/config/emulationstation/.emulationstation/themes"
2022-05-21 13:25:06 +00:00
mkdir -pv $rdhome /.logs #this was added later, maybe safe to remove in a few versions
2022-07-10 19:48:19 +00:00
# Resetting es_systems, now we need it but in the future I should think a better solution, maybe with sed
cp -fv /app/retrodeck/es_settings.xml /var/config/emulationstation/.emulationstation/es_settings.xml
2022-05-19 14:30:43 +00:00
ra_init
standalones_init
tools_init
create_lock
}
start_retrodeck( ) {
# normal startup
echo " Starting RetroDECK v $version "
emulationstation --home /var/config/emulationstation
}
finit( ) {
# Force/First init, depending on the situation
echo "Executing finit"
# Internal or SD Card?
2022-05-20 06:07:15 +00:00
zenity --icon-name= net.retrodeck.retrodeck --question --no-wrap --window-icon= "/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --ok-label "Internal" --cancel-label "SD Card" --text= "Welcome to the first configuration of RetroDECK.\nThe setup will be quick but please READ CAREFULLY each message in order to avoid misconfigurations.\n\nWhere do you want your roms folder to be located?"
2022-05-19 14:30:43 +00:00
if [ $? = = 0 ] #yes - Internal
then
roms_folder = " $rdhome /roms "
else #no - SD Card
2022-06-05 17:30:29 +00:00
if [ -d " $sdcard " ] ;
2022-05-19 14:30:43 +00:00
then
roms_folder = " $sdcard /retrodeck/roms "
else
2022-06-05 17:30:29 +00:00
sdselected = false
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= "SD Card was not find in the default location.\nPlease choose the SD Card root.\nA retrodeck/roms folder will be created starting from the directory that you selected."
if [ $? = = 1 ] #cancel
then
exit 0
fi
while [ $sdselected = = false ]
do
sdcard = " $( zenity --file-selection --title= "Choose SD Card root" --directory) "
echo " DEBUG: sdcard= $sdcard , answer= $? "
zenity --question --no-wrap --window-icon= "/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --cancel-label= "No" --ok-label "Yes" --text= " Your rom folder will be:\n\n $sdcard /retrodeck/roms\n\nis that ok? "
if [ $? = = 0 ] #yes
then
sdselected = = true
roms_folder = " $sdcard /retrodeck/roms "
break
else
zenity --question --no-wrap --window-icon= "/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --cancel-label= "No" --ok-label "Yes" --text= "Do you want to quit?"
if [ $? = = 0 ] # yes, quit
then
exit 0
fi
fi
done
2022-05-19 14:30:43 +00:00
fi
fi
mkdir -pv $roms_folder
# TODO: after the next update of ES-DE this will not be needed
2022-06-08 12:49:53 +00:00
#zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --text="EmulationStation will now initialize the system.\nPlease DON'T EDIT THE ROMS LOCATION, just select:\n\nCREATE DIRECTORIES\nYES\nOK\nQUIT\n\nRetroDECK will manage the rest."
zenity --icon-name= net.retrodeck.retrodeck --info --no-wrap --window-icon= "/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --text= "RetroDECK will now install the needed files.\nPlease wait up to one minute,\nanother message will notify when the process will be finished.\n\nPress OK to continue."
2022-05-19 14:30:43 +00:00
# Recreating the folder
2022-06-08 09:54:58 +00:00
rm -rfv /var/config/emulationstation/
rm -rfv /var/config/retrodeck/tools/
2022-05-19 14:30:43 +00:00
mkdir -pv /var/config/emulationstation/
2022-06-08 09:54:58 +00:00
2022-05-19 14:30:43 +00:00
# Initializing ES-DE
2022-06-08 12:49:53 +00:00
# TODO: after the next update of ES-DE this will not be needed - let's test it
emulationstation --home /var/config/emulationstation --create-system-dirs
2022-05-19 14:30:43 +00:00
2022-06-08 09:54:58 +00:00
mkdir -pv /var/config/retrodeck/tools/
2022-06-08 12:49:53 +00:00
#zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --text="RetroDECK will now install the needed files.\nPlease wait up to one minute,\nanother message will notify when the process will be finished.\n\nPress OK to continue."
2022-05-19 14:30:43 +00:00
# Initializing ROMs folder - Original in retrodeck home (or SD Card)
dir_prep $roms_folder "/var/config/emulationstation/ROMs"
mkdir -pv $rdhome /saves
mkdir -pv $rdhome /states
mkdir -pv $rdhome /screenshots
2022-06-22 20:55:01 +00:00
mkdir -pv $rdhome /bios/pico8
2022-05-21 13:25:06 +00:00
mkdir -pv $rdhome /.logs
2022-05-19 14:30:43 +00:00
# XMLSTARLET HERE
2022-06-22 20:16:30 +00:00
cp -fv /app/retrodeck/es_settings.xml /var/config/emulationstation/.emulationstation/es_settings.xml
2022-05-19 14:30:43 +00:00
# ES-DE preparing themes and scraped folders
2022-07-10 19:48:19 +00:00
dir_prep " $rdhome /downloaded_media " "/var/config/emulationstation/.emulationstation/downloaded_media"
dir_prep " $rdhome /themes " "/var/config/emulationstation/.emulationstation/themes"
2022-05-19 14:30:43 +00:00
2022-05-20 06:37:43 +00:00
# PICO-8
2022-06-22 20:55:01 +00:00
dir_prep " $roms_folder /pico8 " " $rdhome /bios/pico8/bbs/carts " #this is the folder where pico-8 is saving the carts
2022-05-20 06:37:43 +00:00
2022-05-19 14:30:43 +00:00
ra_init
standalones_init
tools_init
create_lock
2022-06-30 21:01:57 +00:00
zenity --icon-name= net.retrodeck.retrodeck --info --no-wrap --window-icon= "/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --text= " Initialization completed.\nplease put your roms in:\n\n $roms_folder \n\nand your bioses in\n\n $rdhome /bios\n\nThen start the program again.\nIf you wish to change the roms location, you may use the tool located the tools section of RetroDECK.\n\nIMPORTANT NOTE:\nRetroDECK must be manually added and launched from your Steam Library in order to work correctly.\nMoreover is suggested to use BoilR to automatically add the SteamGridDB images to Steam (this will be automated soon).\nhttps://github.com/PhilipK/BoilR "
2022-05-19 14:30:43 +00:00
# TODO: Replace the stuff above with BoilR code when ready
}
# Arguments section
2022-05-18 14:10:32 +00:00
for i in " $@ " ; do
case $i in
-h*| --help*)
2022-05-19 14:30:43 +00:00
echo "RetroDECK v" " $( cat /var/config/retrodeck/version) "
2022-05-18 14:10:32 +00:00
echo "
Usage:
flatpak run [ FLATPAK-RUN-OPTION] net.retrodeck-retrodeck [ ARGUMENTS]
Arguments:
2022-05-19 14:30:43 +00:00
-h, --help Print this help
-v, --version Print RetroDECK version
--reset Starts the initial RetroDECK installer ( backup your data first!)
--reset-ra Resets RetroArch' s config to the default values
--reset-sa Reset standalone emulator configs to the default values
--reset-tools Recreate the tools section
2022-05-18 14:10:32 +00:00
For flatpak run specific options please run: flatpak run -h
https://retrodeck.net
"
exit
; ;
--version*| -v*)
2022-07-04 20:49:58 +00:00
conf_init
echo $version
2022-05-18 14:10:32 +00:00
exit
; ;
2022-05-19 14:30:43 +00:00
--reset-ra*)
ra_init
shift # past argument with no value
; ;
--reset-sa*)
standalones_init
shift # past argument with no value
; ;
--reset-tools*)
tools_init
2022-05-18 14:10:32 +00:00
shift # past argument with no value
; ;
2022-05-20 06:37:43 +00:00
--reset*)
rm -f " $lockfile "
shift # past argument with no value
; ;
2022-05-18 14:10:32 +00:00
-*| --*)
echo " Unknown option $i "
exit 1
; ;
*)
; ;
esac
done
2022-05-19 14:30:43 +00:00
# UPDATE TRIGGERED
# if lockfile exists but the version doesn't match
if [ -f " $lockfile " ] && [ " $( cat " $lockfile " ) " != " $version " ] ;
2022-03-28 13:01:47 +00:00
then
2022-05-19 14:30:43 +00:00
echo "Lockfile version is " $( cat " $lockfile " ) " but the actual version is $version "
2022-06-09 08:25:20 +00:00
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)
2022-05-19 14:30:43 +00:00
start_retrodeck
exit 0
fi
2022-03-31 06:03:00 +00:00
2022-05-19 14:30:43 +00:00
# LOCKFILE REMOVED
# if the lock file doesn't exist at all means that it's a fresh install or a triggered reset
if [ ! -f " $lockfile " ] ;
then
echo "Lockfile not found"
2022-06-09 08:25:20 +00:00
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)
2022-05-19 14:30:43 +00:00
exit 0
2022-04-02 09:21:05 +00:00
fi
2022-05-19 14:30:43 +00:00
# Normal Startup
start_retrodeck