|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Gets the current seafile status to display icon
|
|
|
|
|
|
|
|
SYNC_COMPLETE=$(printf '%s%s' '%{F#0F0}' $(echo -e '\Uf0216')) # green
|
|
|
|
SYNC_IN_PROGRESS=$(printf '%s%s' '%{F#FF0}' $(echo -e '\Uf1216')) # yellow
|
|
|
|
SYNC_FAILED=$(printf '%s%s' '%{F#F00}' $(echo -e '\Uf0b98')) # red
|
|
|
|
|
|
|
|
if ! command -v seaf-cli &>/dev/null ; then
|
|
|
|
echo "depends on seaf-cli">&2
|
|
|
|
echo "$SYNC_FAILED"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# getting folder status and trimming headers
|
|
|
|
SEAFILE_STATUS=$(seaf-cli status 2>/dev/null | tail -n +2)
|
|
|
|
ERRORS=$(echo "$SEAFILE_STATUS" | grep "error")
|
|
|
|
|
|
|
|
if [[ -n "$ERRORS" ]] ; then
|
|
|
|
# some directories have errors
|
|
|
|
echo "Error: Failed to sync">&2
|
|
|
|
echo "$ERRORS">&2
|
|
|
|
echo "$SYNC_FAILED"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
IN_PROGRESS=$(echo "$SEAFILE_STATUS" | grep -v "synchronized")
|
|
|
|
if [[ -n "$IN_PROGRESS" ]] ; then
|
|
|
|
# some form of syncing in progress
|
|
|
|
echo "$SYNC_IN_PROGRESS"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$IN_PROGRESS" ]] ; then
|
|
|
|
# nothing in progress and no errors
|
|
|
|
echo "$SYNC_COMPLETE"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# should never get here
|
|
|
|
echo "UNKNOWN_ERROR!">&2
|
|
|
|
exit 1
|