From c821fbeddf67a8844a2ea3740f58e0daf307c483 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 5 Oct 2021 12:20:16 +0100 Subject: [PATCH] drive: add `-o config` option to `backend drives` to config for all shared drives See: https://forum.rclone.org/t/bulk-create-remotes-to-existing-google-shared-drives/26837/ --- backend/drive/drive.go | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/backend/drive/drive.go b/backend/drive/drive.go index bdc80bc79..12282889e 100755 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -3162,7 +3162,7 @@ account. Usage: - rclone backend drives drive: + rclone backend [-o config] drives drive: This will return a JSON list of objects like this @@ -3179,6 +3179,22 @@ This will return a JSON list of objects like this } ] +With the -o config parameter it will output the list in a format +suitable for adding to a config file to make aliases for all the +drives found. + + [My Drive] + type = alias + remote = drive,team_drive=0ABCDEF-01234567890,root_folder_id=: + + [Test Drive] + type = alias + remote = drive,team_drive=0ABCDEFabcdefghijkl,root_folder_id=: + +Adding this to the rclone config file will cause those team drives to +be accessible with the aliases shown. This may require manual editing +of the names. + `, }, { Name: "untrash", @@ -3290,7 +3306,21 @@ func (f *Fs) Command(ctx context.Context, name string, arg []string, opt map[str } return f.makeShortcut(ctx, arg[0], dstFs, arg[1]) case "drives": - return f.listTeamDrives(ctx) + drives, err := f.listTeamDrives(ctx) + if err != nil { + return nil, err + } + if _, ok := opt["config"]; ok { + lines := []string{} + for _, drive := range drives { + lines = append(lines, "") + lines = append(lines, fmt.Sprintf("[%s]", drive.Name)) + lines = append(lines, fmt.Sprintf("type = alias")) + lines = append(lines, fmt.Sprintf("remote = %s,team_drive=%s,root_folder_id=:", f.name, drive.Id)) + } + return lines, nil + } + return drives, nil case "untrash": dir := "" if len(arg) > 0 {