add -s option to autosync
This commit is contained in:
parent
df4f6f24ff
commit
44a2b82cde
73
t.sh
73
t.sh
|
@ -55,7 +55,9 @@ function usage() {
|
||||||
local titleformat format
|
local titleformat format
|
||||||
local usage_var desc_var
|
local usage_var desc_var
|
||||||
format="%22s %-40s %s\n"
|
format="%22s %-40s %s\n"
|
||||||
echo "usage: $0 COMMAND [commandopts]"
|
echo "usage: $0 COMMAND [OPTIONS] [commandopts]"
|
||||||
|
echo
|
||||||
|
echo " -s Auto-sync with server when complete."
|
||||||
echo
|
echo
|
||||||
printf "$format" "COMMAND" "DESCRIPTION" "SYNONYMS"
|
printf "$format" "COMMAND" "DESCRIPTION" "SYNONYMS"
|
||||||
for x in $valid_modes; do
|
for x in $valid_modes; do
|
||||||
|
@ -1053,6 +1055,40 @@ function getchildren() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function tasksync() {
|
||||||
|
local res upcount downcount noun
|
||||||
|
|
||||||
|
if [[ $1 == "-a" ]]; then
|
||||||
|
noun="Auto-sync"
|
||||||
|
else
|
||||||
|
noun="Sync"
|
||||||
|
fi
|
||||||
|
res=$(${VDIRSYNCER} sync 2>&1)
|
||||||
|
rv=$?
|
||||||
|
|
||||||
|
if [[ $rv -eq 0 ]]; then
|
||||||
|
upcount=$(echo "$res" | grep -v ^Sync | grep -c ${VDS_REMOTE})
|
||||||
|
downcount=$(echo "$res" | grep -v ^Sync | grep -c ${VDS_LOCAL})
|
||||||
|
|
||||||
|
[[ $upcount -eq 1 ]] && upess="" || upess="s"
|
||||||
|
[[ $downcount -eq 1 ]] && downess="" || downess="s"
|
||||||
|
|
||||||
|
if [[ $upcount -eq 0 && $downcount -eq 0 ]]; then
|
||||||
|
action "$noun complete - no changes."
|
||||||
|
elif [[ $upcount -eq 0 ]]; then
|
||||||
|
action "$noun complete - $downcount change$downess pulled."
|
||||||
|
elif [[ $downcount -eq 0 ]]; then
|
||||||
|
action "$noun complete - $upcount change$upess pushed."
|
||||||
|
else
|
||||||
|
action "$noun complete - $upcount change$upess pushed, $downcount change$downess pulled."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
error "$noun failed. Output:"
|
||||||
|
echo "$res" | sed -e 's/^/ /'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Should be in config file:
|
# Should be in config file:
|
||||||
#basedir=/Users/rpearce/scripts/t
|
#basedir=/Users/rpearce/scripts/t
|
||||||
#dir=$basedir/docs
|
#dir=$basedir/docs
|
||||||
|
@ -1140,9 +1176,10 @@ addcmd "view" "view <id>" "Show detailed info for given task" "v|view|info|vcal"
|
||||||
|
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
TESTMODE=0
|
TESTMODE=0
|
||||||
|
AUTOSYNC=0
|
||||||
|
|
||||||
|
|
||||||
ARGS="hdt"
|
ARGS="hdst"
|
||||||
while getopts "$ARGS" i; do
|
while getopts "$ARGS" i; do
|
||||||
case "$i" in
|
case "$i" in
|
||||||
h)
|
h)
|
||||||
|
@ -1152,6 +1189,9 @@ while getopts "$ARGS" i; do
|
||||||
d)
|
d)
|
||||||
DEBUG=1
|
DEBUG=1
|
||||||
;;
|
;;
|
||||||
|
s)
|
||||||
|
AUTOSYNC=1
|
||||||
|
;;
|
||||||
t)
|
t)
|
||||||
DEBUG=1
|
DEBUG=1
|
||||||
TESTMODE=1
|
TESTMODE=1
|
||||||
|
@ -1183,29 +1223,7 @@ fi
|
||||||
|
|
||||||
# Commands that don't need tasks loaded
|
# Commands that don't need tasks loaded
|
||||||
if [[ $mode == "sync" ]]; then
|
if [[ $mode == "sync" ]]; then
|
||||||
res=$(${VDIRSYNCER} sync 2>&1)
|
tasksync
|
||||||
rv=$?
|
|
||||||
|
|
||||||
if [[ $rv -eq 0 ]]; then
|
|
||||||
upcount=$(echo "$res" | grep -v ^Sync | grep -c ${VDS_REMOTE})
|
|
||||||
downcount=$(echo "$res" | grep -v ^Sync | grep -c ${VDS_LOCAL})
|
|
||||||
|
|
||||||
[[ $upcount -eq 1 ]] && upess="" || upess="s"
|
|
||||||
[[ $downcount -eq 1 ]] && downess="" || downess="s"
|
|
||||||
|
|
||||||
if [[ $upcount -eq 0 && $downcount -eq 0 ]]; then
|
|
||||||
action "Sync complete - no changes."
|
|
||||||
elif [[ $upcount -eq 0 ]]; then
|
|
||||||
action "Sync complete - $downcount change$downess pulled."
|
|
||||||
elif [[ $downcount -eq 0 ]]; then
|
|
||||||
action "Sync complete - $upcount change$upess pushed."
|
|
||||||
else
|
|
||||||
action "Sync complete - $upcount change$upess pushed, $downcount change$downess pulled."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
error "sync failed. Output:"
|
|
||||||
echo "$res" | sed -e 's/^/ /'
|
|
||||||
fi
|
|
||||||
exit $rv
|
exit $rv
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1391,3 +1409,8 @@ else
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [[ $AUTOSYNC -eq 1 && $mode != "sync" ]]; then
|
||||||
|
tasksync -a
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue