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

    [SCRIPT] RetroPie Shell Script Boilerplate

    Scheduled Pinned Locked Moved Projects and Themes
    scriptboilerplateshellretropie
    12 Posts 3 Posters 2.4k 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 If I ever will use config files than this would be a good starting point ;) Usually I parse arguments via command parameters as all of my scripts are very tight and need no configuration.

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

        @hiulit OMFG! I was thinking about making the same thing but was a bit unmotivated to start it from scratch. Now you started it... such a relief! :D

        After writing all those scripts here and there for the RetroPie community I think I have something to share. I hope to find some time to contribute on your repo.

        Thanks for bringing this up!

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

          @cyperghost I'm glad you like! :D
          I like to use config files because it makes the script more 'user-friendly' in my opinion. Feel free to contribute to the repo if you find a better way of handling config files (setting and getting values)

          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 @meleu
            last edited by

            @meleu Awesome! I'm already waiting for your contributions! And any other person who'd like to contribute too.
            Together we can come up with a nice and useful boilerplate :)

            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 I think the comments are kinda wordy. Would you mind if I change the style, trying to reduce the text a bit?

              • 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 Yeah, sure, no problem! Go for it!

                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 PR submitted.

                  • 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 Thanks! PR commented ;)

                    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 updated the RetroPie Shell Script Boilerplate:

                      UPDATE 1:

                      • Merged #2 from @meleu .
                      • Added check_dependencies().
                      • Added reset_config() to use it in conjunction with set_config() and get_config().
                      • Added --version (because I think everyone should use it :P)
                      • Added 2 ways to find /home.
                      • Added more useful global variables.

                      These changes are also reflected in the first comment.

                      Coming soon... dialog functions!! Again, thanks to @meleu ;)

                      My little contributions to the RetroPie project:

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

                        @hiulit Some additional functions

                        # This will determine of savestate directory = config
                        # This is part of hiuilits Boilerplate script, with small modification
                        # if '~' is detected then expand full homepath
                        function get_config() {
                            local config
                            config="$(grep -Po "(?<=^$1 = ).*" "$CONFIG_FILE")"
                            config="${config%\"}"
                            config="${config#\"}"
                            # [[ ${config:0:1} = "~" ]] && config="${config#??}" && config=~/"$config" # Expand homepath
                            # [[ -z ${config##*/} ]] && config="${config%?}" # Sanitize pathes if last character is a /
                            # [[ ${config:0:1} != "/" ]] && config="annother value because it is likely no path"
                            echo "$config"
                        }
                        
                        # This will determine which script is curently running
                        # Is it 'runcommand-onend.sh' or 'runcommand-onstart.sh'
                        # It will extract 'end' or 'start' ... Usefull if you need to know which runcommand called the script
                        function get_runcommand() {
                           local i
                           local file_array=("runcommand-onend.sh" "runcommand-onstart.sh")
                           for i in "${file_array[@]}"
                           do
                              [[ $(pgrep -f "$i") ]] && i="${i#*-on}" && echo "${i%.*}"
                           done
                        }
                        
                        # Determining file ages
                        function file_age() {
                            echo "$(date +%s -r "$1")"
                        }
                        
                        hiulitH 1 Reply Last reply Reply Quote 1
                        • hiulitH
                          hiulit @cyperghost
                          last edited by

                          @cyperghost Hey, thanks! I'll take a look at them ;)

                          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.