Bash script snippet to display updating sync state, with pause and quit

Thanks for odrive. It took me a few goes to get it set up and working via Bash scripts (on Linux Mint 18), but I now have it set up so that I can easily sync with various cloud services on demand. I saw some discussion about odrive and encryption, but I find that using Borg Deduplicating Archiver in conjunction with odrive meets my needs - worth looking at for anyone who wants their stuff encrypted before syncing. By way of a small token of thanks, here’s the snippet of script I’m using to get a continuously updating display of the syncstate which includes checking for keyboard input (P or Q) to pause or quit. The pause is not a true pause because it just temporarily unmounts odrive, and consequently ‘unpausing’ is really a restart, but I think it’s better than nothing.

odrive_py="$HOME/.odrive-agent/bin/odrive.py"
odrive_mountpoint="$HOME/mnt/odrive"
tput civis -- invisible
while  $(python "$odrive_py" syncstate "$odrive_mountpoint") != *Synced* 
do
  tput cup 3 0
  python "$odrive_py" syncstate "$odrive_mountpoint"
  echo
  echo "Press P to Pause, Q to Quit"
  if read -t 0.2 -n 1 keypress; then
    if [ "$keypress" = "p" ]; then
      # Temporarily unmount odrive
      python "$odrive_py" unmount "$odrive_mountpoint"
      read -p "Press any key to restart sync" -n1 junk
      clear
      # Remount odrive
      python "$odrive_py" mount "$odrive_mountpoint" /
    elif [ "$keypress" = "q" ]; 	then
      break
    fi
  fi
  sleep 1s
done
if [ "$keypress" = "q" ]; then
  # Unmount odrive
  python "$odrive_py" unmount "$odrive_mountpoint"
  # Shut down sync agent
  python $odrive_py shutdown
fi

Note that it requires the sync-agent to be running and the odrive_mountpoint to be already mounted. It works for me, and anyone is welcome to use or adapt it for their own needs.

Thanks for the contribution @jess.harpur!

I’m glad to hear that Agent is working well for you.

An alternative to unmounting would be to stop agent and then start it again, which should provide quicker pick-up of the changes. An unmount will clear some tracking, which means Agent will need to re-track, once the new mount is created.

Thanks for the tip @Tony. Your suggestion does indeed improve it :slight_smile:

Replacing
python "$odrive_py" unmount "$odrive_mountpoint"
with
python $odrive_py shutdown
and also replacing
python "$odrive_py" mount "$odrive_mountpoint" /
with
$HOME/.odrive-agent/bin/odriveagent > /dev/null 2>&1 &
in the while loop worked for me.

1 Like