This script is used to automate the process of mounting rclone remote directories to local ones as described by a YAML configuration file. It can also unmount all previously mounted directories and clean up their corresponding local directories.
- rclone: This script depends on
rclone
, a command line program to manage files on cloud storage.
The script sets up the configuration automatically if it's not previously defined. Specifically, it creates a YAML configuration file at ~/.config/mount/mount.yaml
.
Each line in the configuration file should have the format remote: local_dir
, where remote
is the name of the remote directory as defined in rclone and local_dir
is the directory where the remote will be mounted.
For example:
client-crypt: ~/Documents/Clients
render-crypt: ~/Movies/Render
The configuration also supports encrypted rclone
configurations that require a password for decrypting.
To set this up, you can run the following command in your Terminal:
security add-generic-password -a "rclone" -s "rclone" -w
This will prompt you to enter the password (the one used for your rclone
encryption), and it'll be saved securely in your Keychain, associated with the account and service, both named "rclone". That way, the password will be fetched securely when needed by the script.
If you'd like to choose a custom account or service name, modify the above command accordingly. But also ensure that the script is updated to fetch the password from the correct Keychain entry.
Accessing the macOS keychain from command-line utilities (like security
) usually works seamlessly, as long as the user is logged in. The access to keychain items happens without the user having to manually unlock it each time. However, keep in mind that the first time a new application or script attempts to access an item in the keychain, the system may prompt the user to grant this permission. This is a one-time event. For subsequent requests, the permission doesn't have to be given manually.
To ensure that the script functions as expected, it's recommended to run it once manually to go through any potential permission requests. Once these are granted, the script will operate unattended as expected.
Keep in mind that different versions of macOS might have slightly different behaviors. Privacy settings or system preferences might also affect this. If the user faces issues with keychain access, they might need to check their system's keychain access settings under "Security & Privacy" in System Preferences.
Simply run the script and it will mount all remote directories into the respective local directories as mentioned in ~/.config/mount/mount.yaml
.
./mount_remotes.sh
Pass -u
or -u --auto
as an argument when running the script.
./mount_remotes.sh -u
This command will unmount all the directories that are mentioned in ~/.config/mount/mount.yaml
. It's a good practice to unmount your directories when they're no longer needed, given that any changes made in the local directories are usually write/synced back to the remote location when the system is idle.
All errors are logged using the logger
command which can then be viewed using the Console app in macOS. Filter by the script name to see the log messages generated by this script.
In case of missing rclone
configurations or non-empty mount points, the respective directory will be skipped and errors will be logged in the system logs.
If the script is run with the --auto
flag, macOS notifications are sent on any error.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Note: You will need to have rclone
correctly setup and installed on your machine where this script will be running. For more details on how to achieve this, you will find the Official rclone documentation really useful.