Skip to content

Commit

Permalink
updated installer
Browse files Browse the repository at this point in the history
  • Loading branch information
Itz-fork committed Dec 30, 2023
1 parent cec2e46 commit 98d27d5
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ AUTH_USERS=*
USE_ENV=False
LOG_CHAT=-1001234567890
MONGO_URI=mongodb+srv://username:password@host/dbname?retryWrites=true&w=majority
CIPHER_KEY=vJmDXO4xria6SYVcOfVYd3k3YM8WiiGBfRjbQ8MBsvI=
CYPHER_KEY=vJmDXO4xria6SYVcOfVYd3k3YM8WiiGBfRjbQ8MBsvI=

DOWNLOAD_LOCATION=${PWD}/NexaBots
CHUNK_SIZE=524288
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</p>


# Mega.nz-Bot (nightly 🌃)
# Mega.nz-Bot - Cypher 🥷
A simple telegram bot to download, upload files or folders from [Mega.nz](https://mega.nz/)


Expand Down Expand Up @@ -39,7 +39,7 @@ To setup [Mega.nz-Bot](https://github.com/Itz-fork/Mega.nz-Bot) follow these ste

- Clone the Repo,
```
git clone -b nightly https://github.com/Itz-fork/Mega.nz-Bot
git clone https://github.com/Itz-fork/Mega.nz-Bot
```
- Enter the directory,
```
Expand Down
110 changes: 85 additions & 25 deletions installer.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env bash


# COLORS #
# COLORS
White="\033[1;37m"
Red="\033[1;31m"
Cyan="\033[1;36m"
Yellow="\033[1;93m"
Green="\033[1;32m"
Un_Purple="\033[4;35m"
Expand All @@ -15,13 +16,13 @@ declare -A pkgs_git=([apt]=git-all [pacman]=git [dnf]=git-all)
declare -A pkgs_pip=([apt]=python3-pip [pacman]=python-pip [dnf]=python3-pip)


# Output functions #
# Output functions
function show_process() {
echo -e "${White}==> ${1}${Reset}"
}

function show_hint() {
echo -e " 💡: ${Yellow}${1}${Reset}"
echo -e " Tip 💡: ${Yellow}${1}${Reset}"
}

function show_error() {
Expand Down Expand Up @@ -87,19 +88,13 @@ function clone_repo() {
# Check dependencies
function check_deps() {
show_process "Checking dependencies 🔍"

is_git=$(command -v git &> /dev/null)
is_pip3=$(command -v pip3 &> /dev/null)
is_ffmpeg=$(command -v ffmpeg &> /dev/null)
is_megatools=$(command -v megatools &> /dev/null)

if ! $is_git ; then
if ! command -v git &> /dev/null ; then
pkg_installer ${pkgs_git[$PKGMN]}
elif ! $is_pip3 ; then
elif ! command -v pip3 &> /dev/null ; then
pkg_installer ${pkgs_pip[$PKGMN]}
elif ! $is_ffmpeg ; then
elif ! command -v ffmpeg &> /dev/null ; then
pkg_installer ffmpeg
elif ! $is_megatools ; then
elif ! command -v megatools &> /dev/null ; then
pkg_installer megatools
fi

Expand All @@ -122,36 +117,101 @@ function gen_env() {
read -p "Enter your API HASH: " api_hash
read -p "Enter your BOT TOKEN: " bot_token

# Mega account
# read mega.nz email and password with default values
def_mail="[email protected]"
def_pass="strong#password"
read -p "Enter your Mega.nz Email [$def_mail]: " mega_email
mega_email=${mega_email:-def_mail}
read -p "Enter your Mega.nz Passsword [$def_pass]: " mega_password
mega_password=${mega_password:-def_pass}
mega_email=""
mega_password=""
private_bot=false
while true; do
read -p "Do you want to create private bot with pre-configured mega account? [y/n]" add_mega
case $add_mega in
y|yes|Y|Yes ) private_bot=true; break;;
* ) private_bot=false; break;;
esac
done
if $private_bot ; then
read -p "Enter your Mega.nz Email [$def_mail]: " mega_email
mega_email="MEGA_EMAIL=${mega_email:-def_mail}"
read -p "Enter your Mega.nz Passsword [$def_pass]: " mega_password
mega_password="MEGA_PASSWORD=${mega_password:-def_pass}"
fi

# read authorized users in to a variable called auth_users
# if auth_users are empty set to "*" otherwise check if private_bot var is set to true
# if the private_bot var is set to true then auth_users will be the input otherwise it will be "*|<user input>"
read -p "Enter authorized users (seperate with space) [empty for all users]: " auth_users
auth_users=${auth_users:-"*"}
if $private_bot ; then
auth_users="$auth_users"
else
auth_users="*|$auth_users"
fi

touch .env
# add log chat
log_chat=""
while true; do
read -p "Do you want to see user activity logs? [y/n]" see_logs
case $see_logs in
y|yes|Y|Yes ) see_logs=true; break;;
* ) see_logs=false; break;;
esac
done

if $see_logs ; then
read -p "Enter a chat id where bot is an admin [preferably a channel]: " log_chat
log_chat="LOG_CHAT=${log_chat}"
fi


# add mongodb url
mongo_url=""
while true; do
read -p "Do you want to setup mongodb? [y/n]" set_mongo
case $set_mongo in
y|yes|Y|Yes ) set_mongo=true; break;;
* ) set_mongo=false; break;;
esac
done

if $set_mongo ; then
read -p "Enter the mongodb url [more info: https://t.ly/YxYXq]: " mongo_url
mongo_url="MONGO_URI=${mongo_url}"
fi


# generate cypher key
cypher_key=$(python3 -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())")


touch .env || echo "" > .env
cat <<EOF >> .env
APP_ID=$api_id
API_HASH=$api_hash
BOT_TOKEN=$bot_token
USE_ENV=True
MEGA_EMAIL=$mega_email
MEGA_PASSWORD=$mega_password
$mega_email
$mega_password
USE_ENV=False
AUTH_USERS=$auth_users
$log_chat
$mongo_url
CYPHER_KEY=$cypher_key
DOWNLOAD_LOCATION=${PWD}/NexaBots
DOWNLOAD_LOCATION="${PWD}"/NexaBots
CHUNK_SIZE=524288
TG_MAX_SIZE=2040108421
EOF

show_hint "If your bot won't work as expected, try reassigning USE_ENV and DOWNLOAD_LOCATION in .env file"
show_hint "If your bot won't work as expected, try reassigning USE_ENV and DOWNLOAD_LOCATION in .env file. Not sure what to do? Contact support at @Nexa_bots"
}


function run_installer() {
echo -e "${White}${Un_Purple}Welcome to ${Red}Mega.nz-Bot${Reset}${White}${Un_Purple} Setup!${Reset}"
echo -e "${White}${Un_Purple}Welcome to ${Red}Mega.nz-Bot${Reset}${White}${Un_Purple} - ${Cyan}Cypher${Reset}${White}${Un_Purple} Setup!${Reset}"

exit
setup_env
clone_repo
check_deps
Expand Down
3 changes: 0 additions & 3 deletions mega.ini

This file was deleted.

13 changes: 13 additions & 0 deletions mega.ini.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Login]
Username = [email protected]
Password = your-password

[Network]
# 10240 = 10MiB/s
SpeedLimit = 10240
Proxy = socks5://127.0.0.1:9050
ParallelTransfers = 8

[Cache]
# 120 = 2min
Timeout=120
4 changes: 2 additions & 2 deletions megadl/helpers/cypher.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def __init__(self):
key = f.read().encode()
self.cipher = Fernet(key)
# check if private key exists as an env var
elif os.getenv("CIPHER_KEY"):
self.cipher = Fernet(os.getenv("CIPHER_KEY").encode())
elif os.getenv("CYPHER_KEY"):
self.cipher = Fernet(os.getenv("CYPHER_KEY").encode())
# otherwise exit with error code 1
# although we can generate a new key that's not a good idea
# because if deployer lose it, it'll make all the existing data useless
Expand Down

0 comments on commit 98d27d5

Please sign in to comment.