How can I auto-configure most of "rclone config"?

As part of my automated backup scripts, I want to use rclone to backup directories to Google drive.

I’m aware of the reasons why there needs to be an “rclone config” step. However, I want to automate parts of it, such as setting the remote name and the service to be used.

How can I do this?

This may be cheating but…

#!/bin/bash
cd /tmp
wget -O rclone-current-linux-amd64.zip https://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
cp rclone-v*/rclone /usr/sbin; rm -rf rclone*
mkdir ~/.config
mkdir ~/.config/rclone
cat > ~/.config/rclone/rclone.conf << EOF
###### PASTE RCLONE CONFIG HERE ######
[Google]
type = drive
client_id =
client_secret =
token = {"access_token":"ABCD","token_type":"Bearer","refresh_token":"EFGH","expiry":"2017-01-01T00:13:24.778083454-07:00"}
####### OVERWRITE ABOVE WITH YOUR WORKING CONFIG #######
EOF
SERVER=$(hostname)
SERVER=${SERVER,,}
tar -c -f /tmp/${SERVER}-backup.tar.gz file1 /etc/file2 /home/myuser1 /home/myuser2
rclone copy /tmp/${SERVER}-backup.tar.gz Google:/Backups -q --checksum --drive-chunk-size=64M
rm /tmp/${SERVER}-backup.tar.gz

Basically, you paste a working config file over the lines separated by #### (including those lines) and the script will install the latest rclone, setup a configuration file, tar up some files (change to match your files and paths of course), name the TAR file after the server you’re backing up, copy it to the rclone target named “Google” (in my example) under a root folder called “Backups.”

Of course, on subsequent runs, you don’t really need to install rclone or the config file anymore so ideally, you’d separate this into two scripts: one to install the latest rclone and one to do the backup.