Created
February 29, 2024 05:20
-
-
Save Davenchy/a934f12c62d0ca603653bbcad9807819 to your computer and use it in GitHub Desktop.
A bash script to mount a shared google drive directory into my disk using rclone
This file contains hidden or 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
#!/usr/bin/env bash | |
# Use rclone to mount a shared google drive directory into my disk. | |
# | |
# Assumed you already created a readonly gdrive rclone config. | |
# Assumed you already added your access token or you authenticated the rclone config with your drive. | |
# Check the rclone docs for more info: https://rclone.org/drive/ | |
# You don't have to assign everything, usually I leave everything empty and I use my browser to authenticate. | |
# the rclone config name | |
rclone_config_name="EmbeddedLinuxDiploma" | |
# the path to the shared directory on your drive | |
drive_shared_path="/EL 2023" | |
# where to mount on your disk | |
mount_point="./gdrive" | |
# check if the path is already mounted | |
is_mounted() { | |
mount | grep "$(realpath $mount_point)" &>/dev/null | |
return $? | |
} | |
action=$1 | |
case "$action" in | |
"umount") doas umount -f "$mount_point" ;; | |
"mount") | |
if is_mounted; then | |
echo "ERROR: already mounted to $mount_point" 1>&2 | |
exit 2 | |
fi | |
# execute rclone mount | |
rclone mount --drive-shared-with-me \ | |
"${rclone_config_name}:${drive_shared_path}" "$mount_point" & | |
# make sure that rclone is done | |
sleep 1 | |
;; | |
"status") if is_mounted; then echo "mounted"; else echo "umounted"; exit 1; fi ;; | |
*) echo "Usage: $0 <mount|umount|status>" 1>&2; exit 1 ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment