Debian Codegraph @

utils/buteosync-tool

raw
1 #!/bin/bash
2
3 MSYNCD_HOME=$HOME/.cache/msyncd
4 BUTEO_CONFIG=/etc/buteo/
5 BUTEO_LOG_SETTING=$BUTEO_LOG_SETTING/set_sync_log_level
6 BUTEO_PROCESS=msync
7
8 function usage ()
9 {
10 echo "
11 usage: $0 [options]
12
13 This is a common line tool for Buteo sync. It can be used to peform various tasks like
14 initiating sync, fetching the available profiles etc. Some options require you to run
15 this tool as a root user
16
17 -h | --help : this help
18 -e | --enableprofile: enables a given profile
19 -d | --disableprofile: disables a given profile
20 -l | --listprofiles: lists all available profiles
21 -s | --startsync: starts sync for a given profile
22 -r | --syncresult: dumps the sync results
23 "
24 }
25
26 function is_msyncd_running ()
27 {
28 if [ -z $(pidof $BUTEO_PROCESS) ] ; then
29 return 0
30 else
31 return 1
32 fi
33 }
34
35 function enable_debug ()
36 {
37 echo 4 > $BUTEO_LOG_SETTING
38 pkill -9 $BUTEO_PROCESS
39 }
40
41 function disable_debug ()
42 {
43 :> $BUTEO_LOG_SETTING
44 pkill -9 $BUTEO_PROCESS
45 }
46
47 function list_sync_profiles ()
48 {
49 ls $BUTEO_CONFIG/profiles/sync
50 }
51
52 function list_enabled_profiles ()
53 {
54 echo "Enabled profiles "
55 }
56
57 function disable_profile ()
58 {
59 echo "Disabling profile " $1
60 }
61
62 function enable_profile ()
63 {
64 echo "Enabling profile " $1
65 }
66
67 function start_sync ()
68 {
69 profile_name=$1
70 # Set the dbus session bus before sending the message
71 export $(dbus-launch |grep DBUS_SESSION_BUS_ADDRESS)
72
73 # Send dbus message to start sync for profile $profile_name
74 dbus-send --session --type=method_call --print-reply --dest=com.meego.msyncd /synchronizer com.meego.msyncd.startSync string:'$profile_name'
75
76 echo "Initiated sync. Check $HOME/.cache/msyncd/synchronizer.log to follow sync process"
77 }
78
79 function sync_result ()
80 {
81 profile_name=$1
82
83 # List all the sync results for now
84 cat $MSYNCD_HOME/sync/logs/$profile_name.log.xml
85
86 echo "A non-zero minor/major code means error"
87 echo "If your results are not seen, then the plugin has not exited properly (probably did not emit a signal to sync fw)"
88
89 # minorcode=$(xmllint --xpath 'string(//synclog/syncresults/@minorcode)' $MSYNCD_HOME/sync/logs/$profile_name.log.xml)
90 # majorcode=$(xmllint --xpath 'string(//synclog/syncresults/@majorcode)' $MSYNCD_HOME/sync/logs/$profile_name.log.xml)
91 # timestamp=$(xmllint --xpath 'string(//synclog/syncresults/@time)' $MSYNCD_HOME/sync/logs/$profile_name.log.xml)
92 }
93
94 if [ $# -lt 1 ]
95 then
96 usage
97 exit 127
98 fi
99
100 ARGS=$(getopt -o "he:d:ls:r:" -l "help,enableprofile:,disableprofile:,listprofiles,startsync:,syncresult:" -n "buteosync-tool" -- "$@")
101
102 eval set -- "$ARGS"
103
104 case "$1" in
105 -e | --enableprofile)
106 enable_profile $2
107 shift;;
108 -h | --help)
109 usage
110 shift;;
111 -d | --disableprofile)
112 disable_profile $2
113 shift;;
114 -l | --listprofiles)
115 list_sync_profiles
116 shift;;
117 -s | --startsync)
118 start_sync $2
119 shift;;
120 -r | --syncresult)
121 sync_result $2
122 shift;;
123 esac
124