Created
October 27, 2021 11:32
-
-
Save gelbehexe/60335e4bb84f045fa83fb7826049508b to your computer and use it in GitHub Desktop.
rclone mount script for onedrive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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