Navigation

    UBports Robot Logo

    UBports Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Run script on boot

    Support
    boot script
    6
    13
    147
    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.
    • dobey
      dobey last edited by

      What is your end goal exactly? You need to run something as the phablet user?

      You can create an upstart job to run your script in ~/.local/share/upstart/ perhaps.

      T 1 Reply Last reply Reply Quote 0
      • T
        thrill_seeker @dobey last edited by thrill_seeker

        @dobey It is just to hide android (anbox) apps from the drawer; I have a script that I run everytime that I boot the phone, and would like to automate this.
        How exactly does this .local/share/upstart work? There is no upstart existing script or folder as I see it. And how should I call the script from there? Sorry, I am a little bit lost 🙂 Thanks!

        dobey E M 3 Replies Last reply Reply Quote 0
        • dobey
          dobey @thrill_seeker last edited by

          @thrill_seeker Or maybe it is in ~/.config/upstart/ instead. I don't recall exactly.

          1 Reply Last reply Reply Quote 0
          • E
            Emphrath @thrill_seeker last edited by

            @thrill_seeker Oh wow what a nice script ! Could you share this please ?

            T 1 Reply Last reply Reply Quote 0
            • M
              matteo @thrill_seeker last edited by

              @thrill_seeker hi, as @dobey said you should write a simple .conf file to be stored in .config/upstart location. The content of the file should be something like the following:

              description "script by yourName"
              
              start on started unity8
              
              respawn
              
              exec /linkToYourScriptLocation/yourScript.sh
              
              

              The above script is meant to be executed at the fist start-up of the device (when unity8 is started). Please notice this is the simplest as possible .conf file to accomplish the only duty of executing your script. To have additional information on the further commands available, you might be interested in reading the Upstart manual you can find on the internet.

              dobey 1 Reply Last reply Reply Quote 0
              • dobey
                dobey @matteo last edited by

                @matteo I would not include respawn there for something only meant to run on boot. Otherwise it will simply keep re-running it I think.

                1 Reply Last reply Reply Quote 1
                • T
                  thrill_seeker last edited by

                  Hi again, I am sorry but I tried exactly what you said and does not work 😞 I think that maybe anbox is started after unity8 as well, and the script may be run before anbox launches?

                  I am not really sure, but thank you very much anyway for your time!

                  arubislander 1 Reply Last reply Reply Quote 0
                  • T
                    thrill_seeker @Emphrath last edited by thrill_seeker

                    @Emphrath Of course! Here you have:

                    #!/bin/bash
                    
                    # Set variables
                    filelist_dir=/home/phablet/Documents/anbox
                    bk_dir=/home/phablet/Documents/anbox/bk
                    files_dir=/home/phablet/.local/share/applications
                    filelist=list_files.txt
                    
                    # Delete dir bk if exists and create it again
                    rm -rf $bk_dir
                    mkdir $bk_dir
                    
                    # Get string of files to mv from filelist
                    files=$(cat $filelist_dir/$filelist)
                    
                    # Append files_dir to each file
                    files_to_mv=$(for file in $files; do echo $files_dir/$file; done)
                    
                    # Move all files from files_dir into bk_dir
                    for file in $files_to_mv; do mv $file $bk_dir; done
                    

                    This file is called desktop-delete.sh, and reads a file called list_files.txt that contains all apps to hide. In my case, it contains the following (see .local/share/applications for all apps):

                    anbox-com-android-inputmethod-latin.desktop
                    anbox-com-android-inputmethod-latin.png
                    anbox-com-android-calculator2.desktop
                    anbox-com-android-calculator2.png
                    anbox-com-android-calendar.desktop
                    anbox-com-android-calendar.png
                    anbox-com-android-contacts.desktop
                    anbox-com-android-contacts.png
                    anbox-com-android-deskclock.desktop
                    anbox-com-android-deskclock.png
                    anbox-com-android-documentsui.desktop
                    anbox-com-android-documentsui.png
                    anbox-com-android-email.desktop
                    anbox-com-android-email.png
                    anbox-com-android-gallery3d.desktop
                    anbox-com-android-gallery3d.png
                    anbox-com-android-music.desktop
                    anbox-com-android-music.png
                    anbox-com-android-settings.desktop
                    anbox-com-android-settings.png
                    anbox-org-chromium-webview_shell.desktop
                    anbox-org-chromium-webview_shell.png
                    

                    I have both files contained in this path: Documents/anbox. The file delete-desktop.sh should be executable (do chmod a+x Documents/anbox/delete-desktop.sh).

                    Having all this, is just a matter of executing the script (./Documents/anbox/delete-desktop.sh) and should work fine!

                    E 1 Reply Last reply Reply Quote 0
                    • arubislander
                      arubislander @thrill_seeker last edited by

                      @thrill_seeker

                      One way to check if the script is run, but then Anbox regenerates the files is to check the timestamp on the files after a reboot. If they are from before the reboot, then your script was not executed for whatever reason. Otherwise, you might be right, in which case you could add a delay (sleep xx) in your upstart job before your script is executed.

                      T 1 Reply Last reply Reply Quote 0
                      • E
                        Emphrath @thrill_seeker last edited by

                        @thrill_seeker awesome ! thx

                        1 Reply Last reply Reply Quote 1
                        • T
                          thrill_seeker @arubislander last edited by

                          @arubislander Good point! I tried it, but to no avail u.u anyway, thank you for the tip!

                          1 Reply Last reply Reply Quote 0
                          • B
                            BigB last edited by BigB

                            What does exacly exec do?

                            I ask, because sh doesn't work for my script like . does.

                            I'm also interested as I want to run VPN on boot and keep it always on.

                            Here are my scrips and other information.

                            Also, what are the nmcli commands that enable cellular data? I tried to find it and I'm run out of ideas.

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