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 82.1k 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.
    • 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
                                      • hiulitH
                                        hiulit
                                        last edited by

                                        I've created this little script to format all theme.xml from a given EmulationStation theme with 4 spaces. It's really unnecessary, but I'm that kind of person :P

                                        Here it goes:

                                        #!/usr/bin/env bash
                                        
                                        THEME="pixel"
                                        
                                        for folder in "/etc/emulationstation/themes/$THEME/"*; do
                                            if [[ -d "$folder" ]]; then
                                                if [[ -f "$folder/theme.xml" ]]; then
                                                    cp "$folder/theme.xml" "$folder/theme-backup.xml"
                                                    xmlstarlet fo -s 4 "$folder/theme.xml" > "$folder/theme-indent.xml"
                                                    sed -i '/\?xml/d' "$folder/theme-indent.xml"
                                                    cp "$folder/theme-indent.xml" "$folder/theme.xml"
                                                    rm "$folder/theme-indent.xml" "$folder/theme-backup.xml"
                                                fi
                                            fi
                                        done
                                        

                                        My little contributions to the RetroPie project:

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

                                          When you have a dialog inside a dialog inside a dialog (and so on...), can the "Cancel" button act as a "Back" button? I know the label can be changed, but when you click it it goes back to the first dialog :(

                                          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 there's no "dialog inside a dialog". You execute a dialog and when you choose the "OK" or "Cancel" button the dialog finishes.

                                            What causes that impression of a "dialog inside a dialog" is usually a dialog being called one right after another, each one inside its own while loop structure.

                                            The example I have to show is one of my codes that I am least proud of when it comes to well-written code, but well, let's try...

                                            Check the rpie-art code here: https://github.com/meleu/rpie-art/blob/master/rpie-art.sh

                                            This while loop in main_menu() contains the first dialog. Depending on the option, the script calls another function which has another dialog. Let's follow the uninstall_art_menu() flow.

                                            When the user choose X on the main_menu(), the script calls the uninstall_art_menu() function which has another dialog where you can:

                                            1. Choose Cancel: the logic flow returns to main_menu() and that loop calls the main_menu()'s dialog again.
                                            2. Choose a valid option. Which calls another function which has another dialog and the chain-of-dialogs goes on...

                                            Eh... I'm not sure if I explained well. 😅

                                            Read, check the code and reread. If you still don't understand feel free to ask. ;-)

                                            • Useful topics
                                            • joystick-selection tool
                                            • rpie-art tool
                                            • achievements I made
                                            hiulitH 1 Reply Last reply Reply Quote 1
                                            • 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.