UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Explaining cardDAV contacts sync script

    Scheduled Pinned Locked Moved Support
    4 Posts 2 Posters 723 Views 2 Watching
    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.
      • Z Offline
        zlamalp
        last edited by

        Hi,

        I'd like to ask, if somebody can explain purpose of following in the script for syncing contacts and calendars.

        # line 27
        export DBUS_SESSION_BUS_ADDRESS=$(ps -u phablet e | grep -Eo 'dbus-daemon.*address=unix:abstract=/tmp/dbus-[A-Za-z0-9]{10}' | tail -c35)
        

        and later usage on line

        #line 61
        COMMAND_LINE="export DISPLAY=:0.0 && export DBUS_SESSION_BUS_ADDRESS=$(ps -u phablet e | grep -Eo 'dbus-daemon.*address=unix:abstract=/tmp/dbus-[A-Za-z0-9]{10}' | tail -c35) && /usr/bin/syncevolution $CALENDAR_NAME && /usr/bin/syncevolution $CONTACTS_NAME"
        

        Because I encountered a problem, when I run /sbin/sogosync. It just fails to contact the server and contacts are not updated.

        But if i run /usr/bin/syncevolution nextcloudcontacts directly from the command line, it works and sync changes from / to the server.

        I'm not sure, why cron service need to export a display and DBUS_SESSION_BUS_ADDRESS. Which I found out was different in a file compared to when I run original command in a command line.

        Maybe the script /sbin/sogosync should contain dynamic command and not printed address resolved when echoing it to the file itself (sudo echo "$COMMAND_LINE" > /sbin/sogosync) ?

        1 Reply Last reply Reply Quote 0
        • Y Offline
          YannickH
          last edited by

          Hi zlamalp,

          I faced the same issue when I wanted to put in place sync script.
          I'm using the script given in link on this page :
          https://docs.ubports.com/en/latest/userguide/advanceduse/dav.html
          The script is on git repository :
          https://gist.github.com/boTux/069b53d8e06bdb9b9c97

          I don't know if the script you use is the same (line 27 is different).
          Nevertheless, when I used this script, the sync doesn't work anymore after reboot of the phone.
          It's because the following command :

          DBUS_SESSION_BUS_ADDRESS=$(ps -u phablet e | grep -Eo 'dbus-daemon.*address=unix:abstract=/tmp/dbus-[A-Za-z0-9]{10}' | tail -c35)
          

          doesn't return the same value after a reboot.
          So you have to evaluate it after each reboot.

          To do so, I changed the lines number 96 to 100 (in the script) by these ones :

          CRON_FREQUENCY="hourly"
          
          sudo mount / -o remount,rw
          COMMAND_LINE="export DISPLAY=:0.0 && export DBUS_SESSION_BUS_ADDRESS=$(ps -u phablet e | grep -Eo 'dbus-daemon.*address=unix:abstract=/tmp/dbus-[A-Za-z0-9]{10}' | tail -c35) && /usr/bin/syncevolution $OC_DATABASE_NAME"
          sudo sh -c "echo '$COMMAND_LINE' > /sbin/sogosync"
          sudo chmod +x /sbin/sogosync
          
          CRON_LINE="@$CRON_FREQUENCY /sbin/sogosync"
          (crontab -u phablet -r;) # only if no other cronjob already exist in the crontab
          (crontab -u phablet -l; echo "$CRON_LINE" ) | crontab -u phablet -
          sudo mount / -o remount,ro
          sudo service cron restart
          

          With these modification, the value is evaluate et each reboot.

          Hope it will help you,

          Yannick

          1 Reply Last reply Reply Quote 1
          • Z Offline
            zlamalp
            last edited by

            Hi @YannickH,

            thank you, but the lines you posted are exactly the same as mine. When I run this script it ends up with evaluated DBUS_SESSION_BUS_ADDRESS=whatevervalue insead of containing the DBUS_SESSION_BUS_ADDRESS=$(ps -u phablet e | grep -Eo 'dbus-daemon.*address=unix:abstract=/tmp/dbus-[A-Za-z0-9]{10}' | tail -c35) as it probably should since the dbus address is different on each restart.

            But my question is also whether it is necessary or somehow usefull to have it in a script. As example what I mean:

            I got notification "your contacts were synced" the first time I synced my contacts. But notification showed up after first restart (not after sync finished as I would expect). But also it never appears again. Even if I manually sync my contacts or make changes to the contacts (expecting to sync them later).

            Is it related to this ? Is this notification related to used backed (syncevolution), when it should appear ?

            Y 1 Reply Last reply Reply Quote 0
            • Y Offline
              YannickH @zlamalp
              last edited by

              Hi @zlamalp,
              I have to tell you that my solution is not really working.
              Indeed, when I gave you my answer, I've forgotten that I had changed the way I create the /sbin/sogosync file.

              In fact, after the creation by running the original script, I modified this file manually in console mode :
              sudo mount / -o remount,rw
              sudo vi /sbin/sogosync
              Then I edited the file in order to fit with the following lines :

              export DISPLAY=:0.0 && export DBUS_SESSION_BUS_ADDRESS="$(ps -u phablet e | grep -Eo 'dbus-daemon.*address=unix:abstract=/tmp/dbus-[A-Za-z0-9]{10}' | tail -c35)" && /usr/bin/syncevolution data_base_name
              

              Note : in the above line data_base_name is to be replace by the name of your database.
              Then at each execution by cron daemon, the string DBUS_SESSION_BUS_ADDRESS is evaluated.
              It would be nice if the original script would be able to put this line in the file itself but I'm not an expert in shell programming so I've no solution to propose.

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