Skip to content

Commit

Permalink
Add support for multiple accounts in config | Fix labbots#98
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Akianonymus committed May 8, 2021
1 parent 28cd628 commit 040981c
Show file tree
Hide file tree
Showing 16 changed files with 2,704 additions and 933 deletions.
60 changes: 48 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- To anyone or a specific email.
- Config file support
- Easy to use on multiple machines.
- Support for multiple accounts in a single config.
- Latest gdrive api used i.e v3
- Pretty logging
- Easy to install and update
Expand Down Expand Up @@ -359,16 +360,18 @@ To change the default config file or use a different one temporarily, see `-z /
This is the format of a config file:

```shell
CLIENT_ID="client id"
CLIENT_SECRET="client secret"
REFRESH_TOKEN="refresh token"
ACCOUNT_default_CLIENT_ID="client id"
ACCOUNT_default_CLIENT_SECRET="client secret"
ACCOUNT_default_REFRESH_TOKEN="refresh token"
SYNC_DEFAULT_ARGS="default args of gupload command for gsync"
ROOT_FOLDER_NAME="root folder name"
ROOT_FOLDER="root folder id"
ACCESS_TOKEN="access token"
ACCESS_TOKEN_EXPIRY="access token expiry"
ACCOUNT_default_ROOT_FOLDER_NAME="root folder name"
ACCOUNT_default_ROOT_FOLDER="root folder id"
ACCOUNT_default_ACCESS_TOKEN="access token"
ACCOUNT_default_ACCESS_TOKEN_EXPIRY="access token expiry"
```

where `default` is the name of the account.

You can use a config file in multiple machines, the values that are explicitly required are `CLIENT_ID`, `CLIENT_SECRET` and `REFRESH_TOKEN`.

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

```shell
printf "%s\n" "CLIENT_ID=\"client id\"
CLIENT_SECRET=\"client secret\"
REFRESH_TOKEN=\"refresh token\"
" >| "${HOME}/.googledrive.conf"
printf "%s\n" '
ACCOUNT_default_CLIENT_ID="client id"
ACCOUNT_default_CLIENT_SECRET="client secret"
ACCOUNT_default_REFRESH_TOKEN="refresh token"
' >| "${HOME}/.googledrive.conf"
```

Note: Don't skip those backslashes before the double qoutes, it's necessary to handle spacing.
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.

### Upload

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

---

- <strong>-a | --account 'account name'</strong>

Use different account than the default one.

To change the default account name, do

`gupload -a/--account default=account_name`

---

- <strong>-la | --list-accounts</strong>

Print all configured accounts in the config files.

---

- <strong>-ca | --create-account 'account name'</strong>

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.

Note 1: Only for interactive terminal usage.

Note 2: This flag is preferred over `--account`.

---

- <strong>-da | --delete-account 'account name'</strong>

To delete an account information from config file.

---

- <strong>-c | -C | --create-dir <foldername></strong>

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

0 comments on commit 040981c

Please sign in to comment.