Skip to content

Instantly share code, notes, and snippets.

@gelbehexe
Created October 27, 2021 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gelbehexe/60335e4bb84f045fa83fb7826049508b to your computer and use it in GitHub Desktop.
Save gelbehexe/60335e4bb84f045fa83fb7826049508b to your computer and use it in GitHub Desktop.
rclone mount script for onedrive
#!/bin/bash
rcloneTmpPid="$(dirname "$(mktemp -u)")/rclone.${USER}.pid"
target="${HOME}/mnt/OneDrive"
function mountIt() {
local pid rc
mkdir -p "$target" || exit 1
rclone mount --vfs-cache-mode writes --allow-non-empty OneDrive: "$target" &
rc=$?
pid=$!
if [ "$rc" -gt 0 ]; then
>&2 echo "Error mounting OneDrive"
return $rc
fi
echo "$pid" > "${rcloneTmpPid}"
chmod 600 "${rcloneTmpPid}"
return 0
}
if [ "$1" = "m" ]; then
# mount
if [ -e "${rcloneTmpPid}" ]; then
>&2 echo "Error: file '${rcloneTmpPid}' already exists"
exit 1
fi
mountIt && exit 0
exit 1
fi
if [ "$1" = "u" ]; then
# unmount
if [ ! -e "${rcloneTmpPid}" ]; then
>&2 echo "Error: file '${rcloneTmpPid}' does not exist"
exit 1
fi
kill "$(cat "${rcloneTmpPid}")"
test -n "${rcloneTmpPid}" && rm -f "${rcloneTmpPid}"
exit 0
fi
>&2 echo "Usage:"
>&2 echo " $0 <m|u>"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment