RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    shell scripting topic

    Scheduled Pinned Locked Moved Ideas and Development
    shellshell scriptprogramming
    191 Posts 10 Posters 76.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cyperghostC
      cyperghost @hiulit
      last edited by

      @hiulit Welcome on board ;)

      hiulitH 1 Reply Last reply Reply Quote 1
      • hiulitH
        hiulit @cyperghost
        last edited by

        @cyperghost Thanks! :)

        My little contributions to the RetroPie project:

        • Shell-Script-Boilerplate
        • Fun-Facts-Splashscreens
        • Limit-Last-Played-Games
        1 Reply Last reply Reply Quote 1
        • lostlessL
          lostless
          last edited by lostless

          Just to continue this discussion. The kill run command program portion of shutdown script no longer works with retroarch in the most latest update from yesterday. Raspian files updated as well. It works with kodi. I have no other apps other than retroarch or kodi to test on. But this happened on 2 pi’s of mine so it last not a config i messes up.

          So in essence. If in ES, shuts down fine. If in kodi, it exits to ES and then shuts down. If in retroarch, it just shuts down without saving meta data. Using the kill portion as a exit button. Nothing happens in retroarch, but kodi does exit.

          1 Reply Last reply Reply Quote 0
          • F
            FlashPC
            last edited by

            Hi guys, this is only a hypothetical question. Is it possible to reset the order of the joysticks on the raspberry pi from the command line without rebooting.

            As far as I know udev takes care of the js ordering. Yet emulators like Daphne only uses js0.

            So can it be done where the script takes a snapshot of the udev js order, then asks you which usb device to use, then organise the list to have your desired device use the js0 slot and disable the rest. Then on the emulator exit return the udev js order to what it was.

            meleuM 1 Reply Last reply Reply Quote 0
            • meleuM
              meleu @FlashPC
              last edited by meleu

              @FlashPC You don't need to reboot to change the js* order. I think that changing the plugs is enough.

              I don't know any way to set a joystick to be the js0 "on-the-fly" (keeping all of them connected). I've read something about using udev rules to set a specific controller to be the js0, but I'm afraid it isn't possible to change it on-the-fly.

              By the way, I've wrote a script to let the user choose which controller to use for RetroArch players 1-4, but it works only for RetroArch emulators/cores.

              • Useful topics
              • joystick-selection tool
              • rpie-art tool
              • achievements I made
              1 Reply Last reply Reply Quote 0
              • F
                FlashPC
                last edited by

                @meleu the retroarch joystick selector is sweet, and it works great with the retroarch cores.

                I did read somewhere that it might be possible to kill the udev process, and change the udev rules but that was using red hat linux I think....

                1 Reply Last reply Reply Quote 0
                • meleuM
                  meleu
                  last edited by

                  @cyperghost let's bring this to our nerdy thread :-)

                  @cyperghost said in Hide systems/consoles and only show "all games" section:

                  @EctoOne you're right. Using that symbolic link approach and removing the unwanted systems from es_systems.cfg would work too (I think).

                  Hmmm.... Are you sure? Where are the runcommand calls stored? Or do you create them by your custom control script?

                  The script I made to launch the emulator detects the system in ROM's path. The script is quite small, then I'm pasting it here:

                  #!/usr/bin/env bash
                  # runcustom.sh
                  
                  # testing if it's a symbolic link
                  if [[ ! -L "$1" ]]; then
                      dialog --msgbox "ERROR: \"$1\" is not a symbolic link." 0 0
                      exit 1
                  fi
                  
                  # getting the name of the file that the symbolic link points to
                  rom="$(readlink "$1")"
                  
                  # getting the system based on the folder the rom is stored
                  system="$(echo "$rom" | sed 's|\(.*/RetroPie/roms/[^/]*\).*|\1|' | xargs basename)"
                  
                  # now launch runcommand normally
                  /opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ "$system" "$rom"
                  

                  More details in the original post: https://retropie.org.uk/forum/topic/10849/create-a-custom-es-system-able-to-launch-games-for-many-systems

                  • Useful topics
                  • joystick-selection tool
                  • rpie-art tool
                  • achievements I made
                  cyperghostC 1 Reply Last reply Reply Quote 0
                  • cyperghostC
                    cyperghost @meleu
                    last edited by cyperghost

                    @meleu Yes, last line is the call command like es_systems.cfg
                    I'm not aware of the linking method but this should work in 99% of all time.
                    The method I used is to extract the whole command calls of es_systems in one file.

                    But both methods are hacks.... So your suggestions is really the best - use the all systems method. Maybe if the kios-mode is implented ES is supervisor-save and there is no need for such efforts :)

                    1 Reply Last reply Reply Quote 0
                    • meleuM
                      meleu
                      last edited by meleu

                      @hiulit Another tip for your fun-facts-script project:

                      Declare a variable for fun_facts.txt, set the file's full path to the variable, and use the variable when you need to reference that file.

                      It avoids some No such file or directory errors when you invoke the script from another directory.

                      Example:

                      ~/src/funfacts $ ls
                      es-fun-facts-splashscreens.sh*  fun_facts.txt
                      ~/src/funfacts $ ./es-fun-facts-splashscreens.sh
                      Mario first appeared in 1981 as the playable character in Nintendo's arcade game Donkey Kong. However, he was a carpenter known only as Jumpman
                      ~/src/funfacts $ # THE SCRIPT RUNS FINE
                      ~/src/funfacts $ cd ..
                      ~/src $ ./funfacts/es-fun-facts-splashscreens.sh
                      shuf: fun_facts.txt: No such file or directory
                      
                      

                      EDIT

                      This is the best method I've found to detect the script's dir:

                      readonly SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
                      

                      if your fun_facts.txt is in the same file as the script, then you can just add the following line right after the SCRIPT_DIR definition:

                      readonly FUN_FACTS_TXT="$SCRIPT_DIR/fun_facts.txt"
                      
                      • Useful topics
                      • joystick-selection tool
                      • rpie-art tool
                      • achievements I made
                      hiulitH 1 Reply Last reply Reply Quote 1
                      • hiulitH
                        hiulit @meleu
                        last edited by

                        @meleu Thank you! Done! Works perfectly :D
                        Could you elaborate on how $(cd "$(dirname "$0") works? What does $0 mean? Thanks again!

                        My little contributions to the RetroPie project:

                        • Shell-Script-Boilerplate
                        • Fun-Facts-Splashscreens
                        • Limit-Last-Played-Games
                        meleuM 1 Reply Last reply Reply Quote 0
                        • hiulitH
                          hiulit
                          last edited by

                          I found that if I specify a font when using convert it decreases the image creation time, like a lot!
                          It also depends on the sentence's length. But when specifying a font I get pretty good results with a 3 line sentence :O

                          real 0m3.338s
                          user 0m2.472s
                          sys  0m0.824s
                          

                          compared to:

                          real 1m3.849s
                          user 0m12.148s
                          sys  0m1.024s
                          

                          My little contributions to the RetroPie project:

                          • Shell-Script-Boilerplate
                          • Fun-Facts-Splashscreens
                          • Limit-Last-Played-Games
                          cyperghostC 1 Reply Last reply Reply Quote 1
                          • meleuM
                            meleu @hiulit
                            last edited by meleu

                            @hiulit said in shell scripting topic:

                            Could you elaborate on how $(cd "$(dirname "$0") works? What does $0 mean?

                            $0 is a positional parameter where the string you used to call the script is stored. More info about positional parameters can be found here (by the way, this doc has valuable info about bash scripting).

                            Now let me elaborate why I think that one-liner to get the script dir is a good way to go...

                            To ilustrate let's consider that the script was invoked from a different directory than the one where the script is placed. Let's consider the scenario I used as example on my post above, where I am calling the your script with this line:

                            prompt$  ./funfacts/es-fun-facts-splashscreens.sh
                            

                            Now I'm going to break down this variable definition line (skipping the parts that I think you already know):

                            readonly SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
                            
                            • $0 results in ./funfacts/es-fun-facts-splashscreens.sh

                            • dirname "./funfacts/es-fun-facts-splashscreens.sh" results in./funfacts

                            • cd "./funfacts" && pwd results in /FULL/PATH/TO/src/funfacts

                            I hope I was clear. :)


                            EDIT: if you want an extremely detailed and strong way to get the script's dir, take a look here: http://www.ostricher.com/2014/10/the-right-way-to-get-the-directory-of-a-bash-script/

                            It's a bit overkill for such a single task, but I would like to let the link here for future references. :)

                            • Useful topics
                            • joystick-selection tool
                            • rpie-art tool
                            • achievements I made
                            1 Reply Last reply Reply Quote 1
                            • hiulitH
                              hiulit
                              last edited by

                              Hey, thanks again! It's crystal clear.

                              My little contributions to the RetroPie project:

                              • Shell-Script-Boilerplate
                              • Fun-Facts-Splashscreens
                              • Limit-Last-Played-Games
                              1 Reply Last reply Reply Quote 0
                              • hiulitH
                                hiulit
                                last edited by

                                For the fun facts splashscreens project I want to know which theme is currently active in EmulationStation and its font.

                                Here's what I'm doing:

                                function get_current_theme() {
                                    grep "name=\"ThemeSet\"" "$home/.emulationstation/es_settings.cfg" | sed -n -e "s/^.*value=['\"]\(.*\)['\"].*/\1/p"
                                }
                                
                                function get_theme_font() {
                                    xmlstarlet sel -t -v "/theme/view[contains(@name,'detailed')]/textlist/fontPath" "$ES_DIR/themes/$current_theme/$current_theme.xml" 2> /dev/null
                                }
                                

                                It's working but I don't know if it's the right way to do it.

                                Acutally, get_theme_font() is taken from @meleu 's generate-launching-imagesso I guess it should be ok :P

                                My little contributions to the RetroPie project:

                                • Shell-Script-Boilerplate
                                • Fun-Facts-Splashscreens
                                • Limit-Last-Played-Games
                                meleuM 1 Reply Last reply Reply Quote 0
                                • meleuM
                                  meleu @hiulit
                                  last edited by meleu

                                  @hiulit I think they are just fine. Maybe get_current_theme() can be tweaked a little to be an one-liner sed. But as this is a small script, it's fine to keep it as is.

                                  Another little thing I noticed is regarding that Regular Expression in the sed line. You don't need to explicitly match "start of the line followed by anything" (this is what ^.* means).

                                  Also, I think we can tweak get_theme_font() in order to let it get the font for an arbitrary theme (defined by the user).

                                  • Useful topics
                                  • joystick-selection tool
                                  • rpie-art tool
                                  • achievements I made
                                  1 Reply Last reply Reply Quote 1
                                  • cyperghostC
                                    cyperghost @hiulit
                                    last edited by cyperghost

                                    @hiulit said in shell scripting topic:

                                    I found that if I specify a font when using convert it decreases the image creation time, like a lot!
                                    It also depends on the sentence's length. But when specifying a font I get pretty good results with a 3 line sentence :O

                                    That was my first suggestion. But convert gots 2 caveeats

                                    1. It needs ghostscript (I'm unsure if caption needs it)
                                    2. You have to set correct position
                                    3. (It needs the font you call)

                                    ... but it's faster than just use captions because it's independent of the images you merge but it's your turn to set coordinates ;)

                                    @meleu It's always a pleasure to see you in action ;)

                                    1 Reply Last reply Reply Quote 1
                                    • meleuM
                                      meleu
                                      last edited by

                                      @hiulit said in Fun Facts Splashscreens:

                                      @meleu When I encountered the problem with Pixel theme and xmlstarlet I tried a different approach for finding the font.

                                      function get_theme_font() {
                                          get_current_theme
                                          if [[ -n "$(find "$ES_DIR/themes/$current_theme/art" -type f -name '*.ttf')" ]]; then
                                              font="$(find "$ES_DIR/themes/$current_theme/art" -type f -name '*.ttf')"
                                          else
                                              font=$DEFAULT_FONT
                                          fi
                                      }
                                      

                                      I did the job, but I wasn't happy about repeating the find function , but I don't know any better :P

                                      Do you think that could be a workaround for finding theme fonts?

                                      I know that some themes can have multiple fonts but I think it's ok to use the first one found.

                                      3 notes about the code above:

                                      1. you should use that font="$(find...)" before the if and then if [[ -n "$font" ]] (optmization)

                                      2. maybe using find can be a good approach but only after the current method fail. Also that find command needs more tweaking... Look the files at ComicBook/art directory for example. There are more than one .ttf file. Then we can make the find get only the first match. You did a good catching here! ;)

                                      3. that line with font=$DEFAULT_FONT... Man, memorize one thing for you shell script coder life: unless you have a really good reason, ALWAYS DOUBLE QUOTE YOUR VARIABLES. If you want an extensive (and a bit boring) explanation for that, you can read it here

                                      I'm on my lunch time now. I'll try to eat something and then send another PR.

                                      Cheers!

                                      • Useful topics
                                      • joystick-selection tool
                                      • rpie-art tool
                                      • achievements I made
                                      cyperghostC 1 Reply Last reply Reply Quote 0
                                      • cyperghostC
                                        cyperghost @meleu
                                        last edited by

                                        @meleu @hiulit Maybe annother point of view but maybe if the theme name is already extracted why not just search for *.ttf-files and use results as match and then do use just a simple grep alongside the xml to get a match ;)

                                        meleuM 1 Reply Last reply Reply Quote 0
                                        • meleuM
                                          meleu @cyperghost
                                          last edited by

                                          @cyperghost as far as I understood @hiulit wants specifically the font used in detailed view. At least that's what that xmlstarlet command is getting.

                                          @hiulit submitted another PR: https://github.com/hiulit/es-fun-facts-splashscreens/pull/2

                                          • Useful topics
                                          • joystick-selection tool
                                          • rpie-art tool
                                          • achievements I made
                                          cyperghostC hiulitH 2 Replies Last reply Reply Quote 0
                                          • cyperghostC
                                            cyperghost @meleu
                                            last edited by

                                            @meleu Ah okay approved. But I think a generic solution is hard to find - so it's nice to have the fallback option to use Carbon-fonts :)

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                            Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.