Skip to content

Instantly share code, notes, and snippets.

@AmirulAndalib
Forked from rokibhasansagar/README.md
Created September 25, 2023 04:51
Show Gist options
  • Save AmirulAndalib/dd7be449c7cb7573a0180b54e4a6e882 to your computer and use it in GitHub Desktop.
Save AmirulAndalib/dd7be449c7cb7573a0180b54e4a6e882 to your computer and use it in GitHub Desktop.

Revisions

  1. @rokibhasansagar rokibhasansagar revised this gist Jun 12, 2021. No changes.
  2. @rokibhasansagar rokibhasansagar revised this gist Jun 12, 2021. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,14 @@
    ## To use Service Accounts through script, follow this method

    Make sure you have created `/torapp` folder in root with user write access.
    As the `Dockerfile` defined `WORKDIR /torapp`, make sure you have `/torapp` folder in root with user write access.

    If you use any other `WORKDIR`, please change the path mention from this method according to your needs.

    ### Step 1: Put your service account in a folder

    I've uploaded 100 SA JSON files in "accounts" folder in a private repo.
    I've uploaded 100 SA JSON files in "accounts" folder in a private repo. DO NOT UPLOAD them in a Public Repo.

    Clone the Repo with your Personal Access Token (PAT). Always keep the token secret.

    ```shell
    git clone https://${PAT}@github.com/USERNAME/PRIVATE_REPONAME --depth 1 /torapp/sa
    @@ -36,7 +40,7 @@ team_drive = xyz_yxz_010
    ### Step 3: Set the rclone config path and remote name

    In `ExecVarsSample.py`, set `DEF_RCLONE_DRIVE` as the <TeamDriveID> from rclone config.

    Also set the rclone config path in `RCLONE_CONFIG`. Usually it's `~/.config/rclone/rclone.conf` for any user.

    ### Step 4: Modify `start.sh` file
  3. @rokibhasansagar rokibhasansagar created this gist Jun 12, 2021.
    58 changes: 58 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    ## To use Service Accounts through script, follow this method

    Make sure you have created `/torapp` folder in root with user write access.

    ### Step 1: Put your service account in a folder

    I've uploaded 100 SA JSON files in "accounts" folder in a private repo.

    ```shell
    git clone https://${PAT}@github.com/USERNAME/PRIVATE_REPONAME --depth 1 /torapp/sa
    ```

    This will put the JSON files inside `/torapp/sa/accounts/` folder.

    ### Step 2: Use pre-defined rclone config

    Place your rclone config with this format. Make sure you have this line in the config -

    `service_account_file = /torapp/sa/accounts/__ServiceAcc__`

    So, the full rclone config would look like this -

    ```shell
    [TeamDriveID]
    type = drive
    client_id = xxxxx-xxxxxxxxxxx.apps.googleusercontent.com
    client_secret = yyyyyyyyyyyyyyyyyyyyyyyy
    scope = drive
    root_folder_id =
    chunk_size = 128M
    token = {"access_token":"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz","token_type":"Bearer","refresh_token":"nnnnnnnnnnnnnnnnn","expiry":"2021-05-30T20:14:18.276611995+06:00"}
    service_account_file = /torapp/sa/accounts/__ServiceAcc__
    team_drive = xyz_yxz_010
    ```

    ### Step 3: Set the rclone config path and remote name

    In `ExecVarsSample.py`, set `DEF_RCLONE_DRIVE` as the <TeamDriveID> from rclone config.

    Also set the rclone config path in `RCLONE_CONFIG`. Usually it's `~/.config/rclone/rclone.conf` for any user.

    ### Step 4: Modify `start.sh` file

    ```shell
    _randomSA() {
    # Get a list of SA JSON Filenames
    ls /torapp/sa/accounts/ > /torapp/sa.list
    # Change The SA Filename in rclone config file every 30m
    while true; do
    sed -i 's|__ServiceAcc__|'"$(shuf -n 1 /torapp/sa.list)"'|' ~/.config/rclone/rclone.conf
    sleep 30m
    done
    }
    # Run the randomizer in background
    _randomSA & disown
    # Run main Bot Start Script
    gunicorn tortoolkit:start_server --bind 0.0.0.0:$PORT --worker-class aiohttp.GunicornWebWorker & python3 -m tortoolkit
    ```