Skip to content

How To Deploy

Sunil Kumar edited this page Jul 26, 2021 · 9 revisions

Deploying The Bot Is Easy, You Can Follow The Steps To Deploy Ur Own Bot. These Steps Are Suitable For Linux OS, So We Suggest You Use A Linux VPS.

1. Install Python & Docker.

A. Install Docker

    curl -sSL https://get.docker.com | sudo sh
    sudo usermod -aG docker ${USER} 

B. Restart you SSH Terminal or Reboot your instance

C. Installing Python and pip

      sudo apt install python3 python3-pip

D. Install PIP & Docker Compose

     sudo apt-get -y install python3-pip
     sudo pip3 install docker-compose

2. Getting things ready

mkdir mirrorx
cd mirrorx
wget -q https://raw.githubusercontent.com/iamLiquidX/MirrorX/master/config_sample.env -O config.env
wget -q https://raw.githubusercontent.com/iamLiquidX/MirrorX/master/docker-compose.yml -O compose.yml

Everything is given Clearly in docker-compose.yml

3. Setting Up Config File.

cp config_sample.env config.env
nano config.env
  • Remove the first line saying:
_____REMOVE_THIS_LINE_____=True

Fill up rest of the fields. Meaning of each fields are discussed below:

  • BOT_TOKEN : The telegram bot token that you get from @BotFather
  • GDRIVE_FOLDER_ID : This is the folder ID of the Google Drive Folder to which you want to upload all the mirrors.
  • DOWNLOAD_DIR : The path to the local folder where the downloads should be downloaded to
  • DOWNLOAD_STATUS_UPDATE_INTERVAL : A short interval of time in seconds after which the Mirror progress message is updated. (I recommend to keep it 5 seconds at least)
  • OWNER_ID : The Telegram user ID (not username) of the owner of the bot
  • AUTO_DELETE_MESSAGE_DURATION : Interval of time (in seconds), after which the bot deletes it's message (and command message) which is expected to be viewed instantly. Note: Set to -1 to never automatically delete messages
  • IS_TEAM_DRIVE : (Optional field) Set to "True" if GDRIVE_FOLDER_ID is from a Team Drive else False or Leave it empty.
  • AUTHORIZED_CHATS : (Optional field) Write all the User and Group ID's you want to authorize Bot Separated by Space (Example : "123456789 987654321 -1001234567890") Bot Can Distinguish Between User ID and Group Id & Allow only users to Restart the bot while Group IDs can't Restart the Bot.
  • USE_SERVICE_ACCOUNTS: (Optional field) (Leave empty if unsure) Whether to use service accounts or not. For this to work see "Using service accounts" section below.
  • INDEX_URL : (Optional field) Refer to https://github.com/maple3142/GDIndex/ The URL should not have any trailing '/'
  • API_KEY : This is to authenticate to your telegram account for downloading Telegram files. You can get this from https://my.telegram.org DO NOT put this in quotes.
  • API_HASH : This is to authenticate to your telegram account for downloading Telegram files. You can get this from https://my.telegram.org
  • UPTOBOX_TOKEN : This is to download files using premium account of UpToBox. You can get this from https://uptobox.com/my_account
  • MEGA_KEY: Mega.nz api key to mirror mega.nz links. Get it from Mega SDK Page
  • MEGA_USERNAME: Your email id you used to sign up on mega.nz for using premium accounts (Leave th)
  • MEGA_PASSWORD: Your password for your mega.nz account
  • STOP_DUPLICATE_MIRROR: (Optional field) (Leave empty if unsure) if this field is set to True , bot will check file in drive, if it is present in drive, downloading will ne stopped. (Note - File will be checked using filename, not using filehash, so this feature is not perfect yet)
  • BLOCK_MEGA_LINKS: (Optional field) If you want to remove mega.nz mirror support (bcoz it's too much buggy and unstable), set it to True.
  • SHORTENER: (Optional field) if you want to use shortener in Gdrive and index link, fill shotener url here. Examples :-

exe.io

gplinks.in

shrinkme.io

urlshortx.com

shortzon.com

Note :- Above are the supported url shorteners.

  • SHORTENER_API: Fill your shortener api key if you are using shortener.

Note: You can limit maximum concurrent downloads by changing the value of MAX_CONCURRENT_DOWNLOADS in config.env now. By default, it's set to 4

4. Getting Google OAuth API Credential File

  • Visit the Google Cloud Console
  • Go to the OAuth Consent tab, fill it, and save.
  • Go to the Credentials tab and click Create Credentials -> OAuth Client ID
  • Choose Desktop and Create.
  • Use the download button to download your credentials.
  • Move that file to the root of mirror-bot, and rename it to credentials.json
  • Visit Google API page
  • Search for Drive and enable it if it is disabled
  • Finally, run the script to generate token file (token.pickle) for Google Drive:
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib
python3 utils/generate_drive_token.py
  • Keep compose.yml and config.env in the same directory and change to the directory
  • accounts or tokens can be in any folder but the paths must be correctly mapped in compose.yml

5.Setting Up Service Accounts/Token.

-First, get you current directory by using pwd command.

-Now if you are using service accounts, edit the compose.yml using nano compose.yml, go to volumes section and add the accounts folder in volumes as shown below. In my case accounts folder was in /root/mirrorx/accounts. It can be different for you.

Example-

Before Edit-

Before

After Edit-

After Edit

  • If you are using token.pickle and credential.json method, Then uncomment and the token.pickle and credential.json line by removing the # infront of them.
  • Now Edit edit the location of token.pickle & credential.json file. In my case bot files were in /root/mirrorx.

Example-

Before Edit-

Before Edit

After Edit-

After Edit

  • Now Start The Bot.

6. Starting The Bot.

  • Start docker daemon (skip if already running):
sudo dockerd
  • Run the image using compose:
sudo docker-compose up

or

sudo docker-compose up -d

Enjoy Ur Bot. Down Are Some Optional Steps.

Using service accounts for uploading to avoid user rate limit

For Service Account to work, you must set USE_SERVICE_ACCOUNTS="True" in config file or environment variables Many thanks to AutoRClone for the scripts

Generating service accounts

Step 1. Generate service accounts What is service account

Let us create only the service accounts that we need. Warning: abuse of this feature is not the aim of autorclone and we do NOT recommend that you make a lot of projects, just one project and 100 sa allow you plenty of use, its also possible that over abuse might get your projects banned by google.

Note: 1 service account can copy around 750gb a day, 1 project makes 100 service accounts so thats 75tb a day, for most users this should easily suffice. 

python3 utils/gen_sa_accounts.py --quick-setup 1 --new-only

A folder named accounts will be created which will contain keys for the service accounts created

NOTE: If you have created SAs in past from this script, you can also just re download the keys by running:

python3 utils/gen_sa_accounts.py --download-keys project_id

Add all the service accounts to the Team Drive or folder

  • Run:
python3 utils/add_to_team_drive.py -d SharedTeamDriveSrcID