RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Wanting custom scripts to run at start up and shutdown

    Scheduled Pinned Locked Moved Help and Support
    raspbianscriptstart upshutdown
    9 Posts 3 Posters 1.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.
    • J
      jmcdra
      last edited by

      I've written some scripts to transfer PSP save files to a USB and from the USB to the PSP save folder. They work when they are run manually however I would like for them to run automatically at start up and shutdown. How would I go about doing that?

      Existing scripts:
      Copy to Retropie (Want it to run at start up)

      #!/bin/bash
      
      cp -R /media/usb0/retropie-mount/Savefiles/PSP/SAVEDATA/* /opt/retropie/configs/psp/SAVEDATA/
      

      Copy to USB (Want it to run at shutdown)

      #!/bin/bash
      
      cp -R /opt/retropie/configs/psp/SAVEDATA/* /media/usb0/retropie-mount/Savefiles/PSP/SAVEDATA
      

      Help would be much appreciated :D

      cyperghostC 1 Reply Last reply Reply Quote 0
      • cyperghostC
        cyperghost @jmcdra
        last edited by

        @jmcdra Best way would be to edit
        /opt/retropie/configs/all/autostart.sh and then add your commands before and after the emulationstation call.

        1 Reply Last reply Reply Quote 1
        • J
          jmcdra
          last edited by

          Thank you :) I'll give it a try :D

          1 Reply Last reply Reply Quote 0
          • LolonoisL
            Lolonois
            last edited by

            The suggested solution by @cyperghost works until you rewrite the autostart.sh via retropie_setup.sh.

            Before

            <statement A>
            emulationstation #auto
            <statement B>
            

            After:

            <statement A>
            <statement B>
            emulationstation #auto
            

            Here's why (whatever should be 'autostarted' is added to the end of autostart.sh (>>): retropie setup scripts

            The scripting functionality of emulationstation (scroll down to Scripting topic) has currently an event for "quit" - but not for "startup" (yet).

            So either you refrain from rewriting your autostart.sh via the retropie_setup.sh script
            -or-
            you put pre-emulationstation statements (<statement A>) in autostart.sh and the post-emulationstation <statement B> commands into the /home/pi/.emulationstation/scripts/quit/ folder. In the latter case the autostart.sh can safely be rewritten without messing the order as sketched above.

            You may table this in the "Ideas and development" section, if there is a general use for a "startup" event hook in emulationstation (so there is no more interference with the retropie_setup.sh rewrite of autostart.sh).

            Cheers

            cyperghostC J 2 Replies Last reply Reply Quote 1
            • cyperghostC
              cyperghost @Lolonois
              last edited by

              @Lolonois Thanks for pointing out

              1 Reply Last reply Reply Quote 0
              • J
                jmcdra @Lolonois
                last edited by

                @Lolonois
                To make sure I'm understanding you, my autostart.sh should look like this:

                cp -R /media/usb0/retropie-mount/Savefiles/PSP/SAVEDATA/* /opt/retropie/configs/psp/SAVEDATA/
                emulationstation #auto
                

                And just move the post emulationstation script into a folder,
                /home/pi/.emulationstation/scripts/quit/ and the system will know to run it at shutdown?

                All the stuff I'm seeing about shutdown scripts seems to be implying that you need to create a .service file. I'm not questioning your reasoning here, I'm just trying to understand the instructions so I don't delete my save files by accident.

                Thanks in advance! :)

                1 Reply Last reply Reply Quote 0
                • LolonoisL
                  Lolonois
                  last edited by

                  @jmcdra The first part is right.

                  For the secon part put a script in /home/pi/.emulationstation/scripts/quit/myquit.sh and mark it executable (chmod a+x myquit.sh). Or pick a more memorizable name for myquit.sh.

                  For testing I would start with a simple touch /home/pi/touched_es_start in autostart.sh
                  and in the myquit.sh: touch /home/pi/touched_es_quit.

                  Start emulationstation as usual, wait a minute (or more), then quit ES. On the console check that the filenames (touched_es_start and touched_es_quit) have a timestamp that differs the time you waited (e.g. a minute or more).

                  If this works out well, you did it right and can proceed with your script content.

                  Needless to say to stash away a backup of your precious data before you start this experiment if you are worried about losing/overwriting it accidentially.

                  Cheers

                  J 1 Reply Last reply Reply Quote 0
                  • J
                    jmcdra @Lolonois
                    last edited by

                    @Lolonois It worked! Thank you so much! That was so much simpler than all the stuff I was finding on google. I really appreciate it! :D

                    1 Reply Last reply Reply Quote 0
                    • LolonoisL
                      Lolonois
                      last edited by

                      You're welcome.

                      On more thing: As a courtesy for other user here, please add [Solved] or similar to the topic of your original post.

                      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.