Skip to content

Commit 040981c

Browse files
committed
Add support for multiple accounts in config | Fix #98
Add four new flags * -a | --account - Use a different account than default * -la | --list accounts - List all the accounts configured with CLIENT_ID, CLIENT_SECRET and REFRESH_TOKEN * -ca | --create-account - Create a new account * -da | --delete-account - Delete an existing account --list-accounts, --create-accounts and --delete-account flags can be used without any usual input required The config format is changed, ACCOUNT_${account}_ prefix is added to every config var, where ${account} is the account name The old configs will be automatically migrated with account name default( if default taken then a number suffix will be added like default1, default2, etc ) move authentication/config related functions to auth-utils.[bash|sh] create more authentication functions to reduce some clutter add a lot of error checks, minute situations like chmod failing, failing to write to config file bash script changes: export all sub functions in their sub scripts export variables when it is created that are needed for parallel uploads
1 parent 28cd628 commit 040981c

16 files changed

+2704
-933
lines changed

README.md

+48-12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- To anyone or a specific email.
2828
- Config file support
2929
- Easy to use on multiple machines.
30+
- Support for multiple accounts in a single config.
3031
- Latest gdrive api used i.e v3
3132
- Pretty logging
3233
- Easy to install and update
@@ -359,16 +360,18 @@ To change the default config file or use a different one temporarily, see `-z /
359360
This is the format of a config file:
360361

361362
```shell
362-
CLIENT_ID="client id"
363-
CLIENT_SECRET="client secret"
364-
REFRESH_TOKEN="refresh token"
363+
ACCOUNT_default_CLIENT_ID="client id"
364+
ACCOUNT_default_CLIENT_SECRET="client secret"
365+
ACCOUNT_default_REFRESH_TOKEN="refresh token"
365366
SYNC_DEFAULT_ARGS="default args of gupload command for gsync"
366-
ROOT_FOLDER_NAME="root folder name"
367-
ROOT_FOLDER="root folder id"
368-
ACCESS_TOKEN="access token"
369-
ACCESS_TOKEN_EXPIRY="access token expiry"
367+
ACCOUNT_default_ROOT_FOLDER_NAME="root folder name"
368+
ACCOUNT_default_ROOT_FOLDER="root folder id"
369+
ACCOUNT_default_ACCESS_TOKEN="access token"
370+
ACCOUNT_default_ACCESS_TOKEN_EXPIRY="access token expiry"
370371
```
371372

373+
where `default` is the name of the account.
374+
372375
You can use a config file in multiple machines, the values that are explicitly required are `CLIENT_ID`, `CLIENT_SECRET` and `REFRESH_TOKEN`.
373376

374377
If `ROOT_FOLDER` is not set, then it is asked if running in an interactive terminal, otherwise `root` is used.
@@ -382,13 +385,14 @@ A pre-generated config file can be also used where interactive terminal access i
382385
Just have to print values to `"${HOME}/.googledrive.conf"`, e.g:
383386

384387
```shell
385-
printf "%s\n" "CLIENT_ID=\"client id\"
386-
CLIENT_SECRET=\"client secret\"
387-
REFRESH_TOKEN=\"refresh token\"
388-
" >| "${HOME}/.googledrive.conf"
388+
printf "%s\n" '
389+
ACCOUNT_default_CLIENT_ID="client id"
390+
ACCOUNT_default_CLIENT_SECRET="client secret"
391+
ACCOUNT_default_REFRESH_TOKEN="refresh token"
392+
' >| "${HOME}/.googledrive.conf"
389393
```
390394

391-
Note: Don't skip those backslashes before the double qoutes, it's necessary to handle spacing.
395+
Note: If you have an old config, then nothing extra is needed, just need to run the script once and the default config will be automatically converted to the new format.
392396

393397
### Upload
394398

@@ -422,6 +426,38 @@ These are the custom flags that are currently implemented:
422426

423427
---
424428

429+
- <strong>-a | --account 'account name'</strong>
430+
431+
Use different account than the default one.
432+
433+
To change the default account name, do
434+
435+
`gupload -a/--account default=account_name`
436+
437+
---
438+
439+
- <strong>-la | --list-accounts</strong>
440+
441+
Print all configured accounts in the config files.
442+
443+
---
444+
445+
- <strong>-ca | --create-account 'account name'</strong>
446+
447+
To create a new account with the given name if does not already exists. If the given account exists then script will ask for a new name.
448+
449+
Note 1: Only for interactive terminal usage.
450+
451+
Note 2: This flag is preferred over `--account`.
452+
453+
---
454+
455+
- <strong>-da | --delete-account 'account name'</strong>
456+
457+
To delete an account information from config file.
458+
459+
---
460+
425461
- <strong>-c | -C | --create-dir <foldername></strong>
426462

427463
Option to create directory. Will provide folder id. Can be used to specify workspace folder for uploading files/folders.

0 commit comments

Comments
 (0)