rclone for 42 network
Imagine having only 5gb in your computer, well for us 42 network students it is what we have to deal with in clusters, due to session being in cloud each student get 5GB of storage per session to use it for his files and projects, of course some projects require a lot of storage for example born2beroot project require 8gb for mandatory part and 30gb if you want to do bonus part of the project, and for that people either use USB sticks or the goinfree disk, this goinfree is a folder in the local computer which usually have up to 1tb of storage but its issue is its local, if you switch computer or if someone is sitting on the one you have your project in then it's on a lockdown, well today I brought a simple solution, why not mount your own cloud drive and use it for all your projects and files.
First let me introduce you to a powerful opensource program called Rclone, this last allow you to mount over 70 cloud providers as disk in your computer you can read a bit more about it in the official website https://rclone.org/, and it is what we are going to use for our fix, first you are going to need a cloud storage provider there’s many ways for getting one here I'll explain how to setup Google drive and Microsoft one drive because most here are or were in universities and those give student accounts which in google drive case have unlimited storage while in Microsoft case has up to 5tb of storage, but if you want to setup something else the process should be fairly easy and if you face any issue feel free to reach out to me.
Anyway, enough talk and let us get started. First, we run this code which will download and extract rclone binaries in your home directory
cd ~ && curl -LO https://downloads.rclone.org/v1.65.0/rclone-v1.65.0-osx-amd64.zip && unzip rclone-v1.65.0-osx-amd64.zip && rm rclone-v1.65.0-osx-amd64.zip && mv rclone-v1.65.0-osx-amd64/rclone ~/rclone && rm -rf rclone-v1.65.0-osx-amd64 && chmod +x ~/rclone && echo 'alias rclone="$HOME/rclone"' >> ~/.zshrc && source ~/.zshrc
This command will:
> Go to your home directory.
> Download the zipped version of rclone using curl.
> Unzip the downloaded file with unzip.
> Remove the downloaded .zip archive.
> Move the rclone binary from the extracted directory to your home directory.
> Remove the extracted directory.
> Make the rclone binary executable with chmod.
> Create an alias for rclone in your .zshrc.
> Apply the new alias by sourcing your .zshrc.
Now we just setup the mounting point (the disk we are going to mount) To do that run
rclone config
It will list all the remote you have currently you should have 0, (PS you can mount multiple providers and disks)
Hit n to create new one and give it a name for example drive
Next you select the number of providers you are going to mount for OneDrive. You can use 34 and 18 for google drive but always double check because they might change.
In google drive I highly recommend you check this https://rclone.org/drive/#making-your-own-client-id the number of transactions per second are ofc rate limited that should not really be an issue, but it's always recommended to use your own client ID, for now I will just use default so I will leave it empty, for secret leave empty or pass your secret depending on which key you are using, for the scope do 1 which give full read/write access
Next for service_account_file leave it empty, no for advanced settings and yes for using web browser
Immediately after clicking enter, you will be sent to a google login page, after you check the domain is google.com login to your account and give it access to google drive then go back to your terminal and hit enter twice and that should be it. Now hit q to exit and we move to the next step which is mounting the disk Make a folder which will be the mounting point it can be in your home, documents or even desktop i recommend putting it in your home >
cd ~ && mkdir folder
It can be named anything, next we mount it, this command is particularly important, so I will explain it.
rclone mount remote:path/to/files /path/to/local/mount --vfs-cache-mode full --cache-dir /path/to/cache
> Remote: the name we had given to platform in config (drive)
> Path/to/files: path inside our cloud for example if you made a 42 folder inside your google drive you can do drive:42
> /path/to/local/mount: path of the folder where you want the disk to be mounted (folder)
> vfs-cache-mode: I will not explain it much, but it uses local storage as cache to allow native like read/write to the user. (it is the reason you will not have a lot of ram and disk usage when dealing with big files)
> cache-dir: folder that we will use as cache for our rclone (we will use goinfree :wink:
So, for a copy paste one here
rclone mount drive:42 ~/folder/ --vfs-cache-mode full --cache-dir /Users/username/goinfre
Make sure to replace what need to be replaced
Now how about a simple shell script that you can run to mount your disk?
#!/bin/bash
if ! mount | grep -q "on /Users/username/folder "; then
/Users/username/rclone mount drive:42 /Users/username/folder --vfs-cache-mode full --cache-dir /Users/username/goinfre &
Fi
oh and here's a C version of the same script that someone gladly gave
#include <stdlib.h>
#include <stdio.h>
int main() {
int result;
result = system("mount | grep -q 'on /Users/username/folder '");
if(result != 0) {
printf("Mount point not found. Attempting to mount...\n");
result = system("/Users/username/rclone mount drive:42 /Users/username/folder --vfs-cache-mode full --cache-dir /Users/username/goinfre &");
if(result != 0) {
fprintf(stderr, "Failed to execute rclone mount command.\n");
return 1;
}
} else {
printf("Mount point already exists.\n");
}
return 0;
}
you can compile it and put it in your desktop or run it on startup ^^. Well, that is all, I hope this was and will be of help to you if you have any questions feel free to reach out and ask and have a good time.