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 75.9k 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.
    • mituM
      mitu Global Moderator @hansolo77
      last edited by mitu

      @hansolo77 It can be done. This is how I'd do it.

      1. Download the .map file (curl/wget) locally. Should be text only. Check for errors or if the file is empty and exit if so.

      2. Read the file line by line, split it in col1 (zip name) and col2 (game name). For each col1:

        • Look in the gamelist for the arcade system to search for col1.zip, either via grep or xmlstarlet. [1]
          The idea is to get the path to the ROM zip file as the value into path
        • If you found the path, then check if arcade_folder_path/path exists and if so, add it to a list (list_rom).
        • Repeat steps above if your rom might be in a different system (i.e. mame2003-libretro, fba) and nothing was found in the previous step.
      3. At the end, walk over list_rom and produce a custom collection file in $HOME/.emulationstation/collections/custom-GameEx.cfg containing one line for each ROM path in the list. If a previous .cfg fie exists, back it up.

      You should have to create the collection before running the script so you can choose in ES to make it visible, but once ES knows to show it, I think you only need to restart ES after each script run.

      The above assumes you only have arcade ROMs, since the naming is standard. Make sure to lowecase the col1 in step 2 (I've seen that TMNT is uppercase, but the zip name should be lowercase and

      [1] - get the path of rom using xmlstarlet and ROM name.

      $ xmlstarlet sel -t -v "//game[contains(path,'1943.zip')]/path" .emulationstation/gamelists/arcade/gamelist.xml 
      # outputs: 
       ./1943.zip
      
      1 Reply Last reply Reply Quote 0
      • hansolo77H
        hansolo77
        last edited by

        I knew it could be done! :) Now to just decipher all that and make a script lol. I’m on vacation after next week, maybe I’ll try to work on it then!

        Who's Scruffy Looking?

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

          @meleu @mitu What I'd like to achieve is getting the screen resolution of the device that is/will be using Fun Facts! Splashscreens. And I've seen that it differs from different systems.

          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

            @hiulit said in shell scripting topic:

            @meleu @mitu What I'd like to achieve is getting the screen resolution of the device that is/will be using Fun Facts! Splashscreens. And I've seen that it differs from different systems.

            Uhmmm... maybe what you need is slightly different than just detect whether the user is running your script while in a x11 environment or not.

            If you need to discover if the emulators you installed/compiled on your RetroPie were for use on a X11 environment, I suggest you to try the isPlatform function. You can do something like this:

            . $HOME/RetroPie-Setup/scriptmodules/helpers.sh
            . $HOME/RetroPie-Setup/scriptmodules/system.sh
            if isPlatform "x11"; then
                echo "Your emulators runs on a X11 environment"
            else
                echo "Your emulators does NOT run on a X11 environment"
            fi
            

            Regarding resolution discovering techniques, you are surely ahead of me on this subject. :-)

            I hope it helps.

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

              @meleu My problem was that I had these xdpyinfo functions to get the screen resolution and they were working in my VM running Pixel, but when I tried them on the Raspberry Pi I got an error, something like: xdpyinfo: command not found. I tried sudo apt-get xdpyinfo but it didn't work, so I manage to found another way to get the screen resolution from a Raspberry pi, and that's where these fbset -s functions come from.

              So now I need to know when do I need to use one function or the other.

              What I have right now (and seems to be working) is:

              function get_system_platform() {
                  . "$home/RetroPie-Setup/scriptmodules/helpers.sh"
                  . "$home/RetroPie-Setup/scriptmodules/system.sh"
                  get_platform
                  echo "$__platform"
              }
              
              
              function get_screen_resolution_x() {
                  if [[ "$(get_system_platform)" != "x86" ]]; then
                      local screen_resolution
                      screen_resolution="$(fbset -s | grep -o -P '(?<=").*(?=")')"
                      echo "$screen_resolution" | cut -dx -f1
                  else
                      xdpyinfo | awk -F '[ x]+' '/dimensions:/{print $3}'
                  fi
              }
              
              
              function get_screen_resolution_y() {
                  if [[ "$(get_system_platform)" != "x86" ]]; then
                      local screen_resolution
                      screen_resolution="$(fbset -s | grep -o -P '(?<=").*(?=")')"
                      echo "$screen_resolution" | cut -dx -f2
                  else
                      xdpyinfo | awk -F '[ x]+' '/dimensions:/{print $4}'
                  fi
              }
              

              My little contributions to the RetroPie project:

              • Shell-Script-Boilerplate
              • Fun-Facts-Splashscreens
              • Limit-Last-Played-Games
              mituM 1 Reply Last reply Reply Quote 0
              • mituM
                mitu Global Moderator @hiulit
                last edited by

                @hiulit xdpyinfo is part of the x11-utils package (https://packages.debian.org/stretch/x11-utils), so it's not installed if you're not installing an X.org env (like in Raspbian Lite). But even if it is installed, it only works in a X.org session (desktop environment), otherwise it will return an error.

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

                  @mitu So then, would it be save to use something like this?

                      if [[ $DISPLAY ]]; then
                          xdpyinfo blah, blah...
                      else
                          do_something_for_none_X_org_session
                      fi
                  

                  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

                    @hiulit said in shell scripting topic:

                    @mitu So then, would it be save to use something like this?

                        if [[ $DISPLAY ]]; then
                            xdpyinfo blah, blah...
                        else
                            do_something_for_none_X_org_session
                        fi
                    

                    eh... did you read my last post above? I think it answers exactly what you asked on your last post.

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

                      @meleu Yeah, I read it, but I thought it was a different thing, because you said:

                      If you need to discover if the emulators you installed/compiled on your RetroPie were for use on a X11 environment

                      and don't know if I want/need to know if the emulator is compiled for X11 but rather if the machine is running X11. Or at least that's what I think.

                      I'm really not sure if I'm not explaining myself clearly or if I'm not understanding you, but just in case, I'll try it one more time :P, hehe!

                      I need to get the screen resolution of the machine running RetroPie. How can I have a cross-platform solution? Because the Raspberry Pi has one method of getting the screen resolution and my VM running Pixel has another one (and maybe another platform will have another method)

                      Sorry again @meleu and @mitu if I'm not being clear enough. Or if I'm not asking the right questions.

                      Thanks!

                      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
                      • cyperghostC
                        cyperghost
                        last edited by

                        @meleu Thanks for your Pull-Request on BashROMManager
                        It's not just cosmetic ;)
                        I also resolved a small bug that would prevent us from using the FastForward feature

                        So version is 0.79 now and I think it's a solid codebase for improvements and for changing coding style... step by step

                        @hiulit You are also welcome to give your input here
                        We are talking about here: https://github.com/crcerror/RetroPie-RPM-BashROMManager
                        ;)

                        hiulitH meleuM 2 Replies Last reply Reply Quote 2
                        • meleuM
                          meleu @hiulit
                          last edited by

                          @hiulit Here are some info that looks like you're not aware (and is confused because of it):

                          • X is the graphical server for UNIX systems (including Linux).

                          • the resolution on a pure command line (the one you're getting with fbset) is different than the resolution when you are on a X environment (the one you're getting with xdpyinfo).

                          • The emulators installed by RetroPie on a Raspbery Pi do NOT need a X environment.

                          • The emulators installed by RetroPie on a Linux-x86 system needs a X environment.

                          • If you are on a Raspberry Pi and startx (or whatever command you use to start the graphical interface) you'll have the $DISPLAY variable, but it does NOT mean that you run the emulators on X. Therefore, when you show your launching image (with a fun fact on it) you will NOT necessarily be on the resolution you detected with your current method.

                          Even after all this stuff being said, I wouldn't bother that much to detect the resolution with this degree of precision. In my opinion you should focus only on keeping the aspect ratio of the image you're using for background, this would be enough.

                          If you show me exactly where in the fun-fact's code you want/need this and I can try to be more helpful.

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

                            @cyperghost Yeah, thanks! I've been following the thread ;) I'll dig in when I have the time. Good job!

                            My little contributions to the RetroPie project:

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

                              @cyperghost I strongly recommend you to take a look at @hiulit 's work on the retropie-shell-script-boilerplate.sh (I believe he would give this input also). I also worked on that template.

                              I was about to submit a new PR when I realized that you would take some advantage looking at that code. ;-)


                              @hiulit what do you think about focusing on aspect ratio instead of trying to detect the exact resolution?

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

                                @meleu Hey sorry, yeah, maybe you're right! But then, should I have a predefined resolution? Like 1080p, 720p, 800x600 and let the user decided which size to use?

                                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 said in shell scripting topic:

                                  should I have a predefined resolution?

                                  I'm not confident enough to say what you should do :), but I can say what I do on my launching image generator tool.

                                  I'm currently away from my dev machine to confirm, but IIRC the command below is what you need to resize an image to a height of 576 pixels. The resulting_image's width will be the one necessary to keep the same aspect ratio of the original_image.

                                  convert -resize x576 original_image resulting_image
                                  

                                  EDIT: confirmed. The command above works exactly as I described.

                                  By the way, I noticed you're commiting experimental stuff (such as this resolution thing you were discussing above) directly on the master branch of the fun-facts repo. This is NOT a good practice. ;-)

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

                                    This post is deleted!
                                    1 Reply Last reply Reply Quote 0
                                    • cyperghostC
                                      cyperghost
                                      last edited by cyperghost

                                      @meleu Yes I used your function call. Works nice.
                                      Is there anything against the return $value method?
                                      Or am I abusing the being of $? as method to check if a function/command gave return code =0 for okay and !=0 for errors?

                                      So thx... pushed BashROMManager to v080 now.
                                      Do you have any suggestion in the use of xmlstarlet or better use grep?

                                      Maybe the script can be extended to clean also image-files and videos related to it - version 2.x?

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

                                        @meleu Yeah! I know! I should've created a new branch for this new feature.. :P But It is safe to use master because I made the code backwards compatible, so nothing that was already there is broken and the new things aren't even documented yet. When using git for yourself (at least for me) you tend to use bad practices because it's easier, hehe!

                                        A part from that, I see you point of just using height to maintain the aspect ratio, but I don't know how can I can create images for different resolutions that will look good on every device. I mean, if I use, let's say, the 576px you said, it will look too small on a 1920x1080 screen, I think. I'll give it a try anyway to see how "bad" (or good!) it looks. Thanks, as always! ;)

                                        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

                                          @hiulit said in shell scripting topic:

                                          I don't know how can I can create images for different resolutions that will look good on every device. I mean, if I use, let's say, the 576px you said, it will look too small on a 1920x1080 screen, I think

                                          My tool generate launching images with 576 pixels height and keep the aspect ratio of the image being used as background, Rokkervik's pixel-themed launching images are 480x272. All of them looks just fine on my 1920x1080 TVs...

                                          If you create launching images 1920x1080 the resulting file can be very big and the raspberry pi can delay to display a big image

                                          • 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 Yeah, you're right. Pixel theme images look fine on my 1920x1080 monitor. I'll try it! ;)

                                            My little contributions to the RetroPie project:

                                            • Shell-Script-Boilerplate
                                            • Fun-Facts-Splashscreens
                                            • Limit-Last-Played-Games
                                            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.