Rclone Mount

Quickly mount endpoints in rclone.

Image preview of Rclone Mount plugin.

rclone-mount.1m.sh

Edit
Open on GitHub
#!/bin/bash

# <xbar.title>Rclone Mount</xbar.title>
# <xbar.version>v1.0</xbar.version>
# <xbar.author>Ryan Chiechi</xbar.author>
# <xbar.author.github>rchiechi</xbar.author.github>
# <xbar.desc>Quickly mount endpoints in rclone.</xbar.desc>
# <xbar.image>https://i.imgur.com/woYDSdX.png</xbar.image>
# <xbar.dependencies>bash, rclone</xbar.dependencies>


#TARGET is the local mountpoint for the remote
TARGET=${HOME}/encrypted
#Homebrew installs rclone /usr/local/bin
RCLONE=/usr/local/bin/rclone
# If your rclone config is not encrypted, comment out the next two lines
RCLONEPASS=${HOME}/.password-store/Macbert/rclone.gpg
export RCLONE_CONFIG_PASS=$(/usr/local/bin/gpg -o - -d "${RCLONEPASS}" 2>/dev/null)

# You should not need to edit anythinng below here. 
function rcloneimage() {
  icon="iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAAAXNSR0IArs4c6QAAAIRlWElmTU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAACQAAAAAQAAAJAAAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAAACSgAwAEAAAAAQAAACQAAAAAODYCaQAAAAlwSFlzAAAWJQAAFiUBSVIk8AAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaH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c04hwP+qG8FWKzqFXPgA1boJVDSJqU3hd6Jaq8oqbf/iUWyodiLcog1BOgV5opm3NKxc+REjZjHQ3iEKBI0vN4TK61UjZ07xigbwoNmgUEwLZAKkk70v2dSUE5cZaI9W43ivnPAxQxq41Hghd1wXKjIjKP0hB/KCvUvZ2/+CFNz6+YoHRYD5YHi5Cx2O+1wBKtyxkGZPFqkHKr/UD10WAr4GJT/GSTbZZzRfXbpxrb1CAKONn3b5dutUwO3Dhvyd9DMoIDI0yB0MWummFgbf3lQeXXrBqV34nouzcauFkUDgLRROLQCl92VIPjqtsbtTuUHtbqbQFtb/z2CWZ7xA+QdUelR84dRGKrSHdSiK5cqJDuT3AkADYiIpT1LfAlm+lGqdfuuqPj141176ski8MmRCMOeSveB/68GCGEga/lEhjO6uDATiASQNMsfCpx8UCrGdwBk1Q6UnV3qsPLP0MoMBQeRAFmoVahzaToQfwOIobFBZU+QFh3CvlKumWSSvWr3x6nd5oz8It3yXqqToAM2Sw9BArxJTaG49xMKyLZKNiZhc+1+b96uL0kIP/sJATKJVhIWtzHH3AcQLK3G3urHsgYTXqoybCElFpQ2Ur1sH4URvHhKFcKSDvPZ7dsOROYmHFm/m1oGI1VJihxcjg2B47Gi7INFMVjwzgv8C6TRsvttfT2ZRunPbYk0cA0cTYYv3yNVtbNFm5HpmmA+ScDyhNWEKekcPzAUh6OZRBz6sPdh1zxhTqa3bmJ1YFXwpAC4BpOsiZiEMIVRFK/yc8OcsM+YfHLmw+gTGlplPDA42PaZLPWfZEfJUxo1RvX3lXTyMxOGYYzGbjGITkSbSPnaP+8h1fZG5/R6YI9Ng5tZYS9SntP9pV2MU43KdeAAAAAElFTkSuQmCC"
}

function mountpoint() {
  mount | grep -q "$1"
  return $?
}

function remotemounted() {
  while IFS= read -r remote; do
    mountpoint "${remote}" && return 0
  done < <(${RCLONE} --ask-password=false listremotes)
  return 1
}

function isremote() {
  while IFS= read -r remote; do
    [[ "$1" == "${remote}" ]] && return 0
  done < <(${RCLONE} --ask-password=false listremotes)
  return 1
}

function domount() {
  mountpoint "${TARGET}" && return 1
  ${RCLONE} --ask-password=false mount --daemon "${1}" "${TARGET}" >/dev/null 2>&1
  RETURN=$?
  sleep 5
  return
}

function dounmount() {
  diskutil unmount ${TARGET} >/dev/null 2>&1
  RETURN=$?
  sleep 5
  return
}

function listremotes() {
  echo "---"
  ${RCLONE} --ask-password=false listremotes | while read remote; do
    _item=$(printf "${remote}" | tr -d ':')
    if mountpoint ${remote} ; then
      color="color=green"
      emoji=":floppy_disk:"
    else
      color=""
      emoji=""
    fi
    echo "${emoji}  ${_item}| bash='$0' param1=${remote} refresh=true terminal=false ${color}"
  done
}

if [[ -n "$1" ]] && ! isremote "$1"; then
  exit 1
elif [[ -n "$1" ]] && mountpoint "$1" ; then
  dounmount
  exit $?
elif [[ -n "$1" ]] && remotemounted "$1" ; then
  dounmount && domount "$1"
  exit $?
elif [[ -n "$1" ]]; then
  domount "$1"
  exit $?
fi

# Output menu items
rcloneimage
echo " | image=${icon}"
listremotes