Skip to content

Instantly share code, notes, and snippets.

@dingwen07
Created November 25, 2022 11:47
Show Gist options
  • Save dingwen07/630c52bb57cf8c98694a58d5c74e2a22 to your computer and use it in GitHub Desktop.
Save dingwen07/630c52bb57cf8c98694a58d5c74e2a22 to your computer and use it in GitHub Desktop.
#!/bin/bash
CONFIG_FILE=$HOME/.config/rclone/rclone.conf
MOUNT_POINT_BASE=$HOME/mnt
CACHE_MAX_AGE=168h
CACHE_MAX_SIZE=100G
# Create mount point base directory if it doesn't exist
mkdir -p $MOUNT_POINT_BASE
# For each line, check if it is [remote] and if so, mount it
while read -r line; do
if [[ $line == \[*\] ]]; then
# Get the name of the remote
REMOTE_NAME=$(echo $line | sed 's/\[//g' | sed 's/\]//g')
# Check mountpoint
MOUNT_POINT=$MOUNT_POINT_BASE/$REMOTE_NAME
if [ ! -d "$MOUNT_POINT" ]; then
mkdir "$MOUNT_POINT"
fi
# Check if already mounted
if mountpoint -q "$MOUNT_POINT"; then
echo "$REMOTE_NAME is already mounted"
else
echo "Mounting $REMOTE_NAME"
rclone --config $CONFIG_FILE --daemon -v \
--vfs-cache-mode full \
--vfs-cache-max-age $CACHE_MAX_AGE \
--vfs-cache-max-size $CACHE_MAX_SIZE \
mount "$REMOTE_NAME": "$MOUNT_POINT"
fi
fi
done < $CONFIG_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment