use printf
This commit is contained in:
356
install.sh
356
install.sh
@@ -1,13 +1,22 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Define color codes
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[0;33m'
|
||||
BLUE='\033[0;34m'
|
||||
INPUT='\033[1;30m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
PACKAGE_MANAGER=""
|
||||
|
||||
# Ensure the script is run with root privileges
|
||||
if [[ $UID != 0 ]]; then
|
||||
echo "This script requires root privileges."
|
||||
echo "Please enter the root password to continue."
|
||||
printf "${YELLOW}This script requires root privileges.${NC}\n"
|
||||
printf "Please enter the root password to continue.\n"
|
||||
exec sudo "$0" "$@"
|
||||
else
|
||||
echo "Running with root privileges"
|
||||
printf "${YELLOW}Running with root privileges${NC}\n"
|
||||
fi
|
||||
|
||||
# Detect available package manager
|
||||
@@ -20,81 +29,89 @@ elif command -v yum &>/dev/null; then
|
||||
elif command -v pacman &>/dev/null; then
|
||||
PACKAGE_MANAGER="pacman"
|
||||
else
|
||||
echo "Unsupported package manager. Please use a compatible distribution or update the installer script."
|
||||
printf "${RED}Unsupported package manager. Please use a compatible distribution or update the installer script.${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if command -v termux-setup-storage; then
|
||||
echo "For termux, please use https://raw.githubusercontent.com/The-MoonTg-project/Moon-Userbot/main/termux-install.sh"
|
||||
printf "${RED}For termux, please use https://raw.githubusercontent.com/The-MoonTg-project/Moon-Userbot/main/termux-install.sh${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Install necessary packages based on detected package manager
|
||||
case "$PACKAGE_MANAGER" in
|
||||
apt)
|
||||
apt update -y
|
||||
apt install python3 python3-venv git wget -y || exit 2
|
||||
;;
|
||||
apk)
|
||||
apk update
|
||||
apk add python3 py3-virtualenv git wget || exit 2 # Packages here may be wrong, to verify
|
||||
;;
|
||||
yum)
|
||||
yum update -y
|
||||
yum install python3 python3-venv git wget -y || exit 2 # Packages here may be wrong, to verify
|
||||
;;
|
||||
pacman)
|
||||
pacman -S --noconfirm python python-virtualenv git wget || exit 2
|
||||
;;
|
||||
apt)
|
||||
apt update -y
|
||||
apt install python3 python3-venv git wget -y || exit 2
|
||||
;;
|
||||
apk)
|
||||
apk update
|
||||
apk add python3 py3-virtualenv git wget || exit 2 # Packages here may be wrong, to verify
|
||||
;;
|
||||
yum)
|
||||
yum update -y
|
||||
yum install python3 python3-venv git wget -y || exit 2 # Packages here may be wrong, to verify
|
||||
;;
|
||||
pacman)
|
||||
pacman -S --noconfirm python python-virtualenv git wget || exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
# Clone repository if not exists
|
||||
if [[ -d "Moon-Userbot" && "$(basename "$PWD")" != "Moon-Userbot" ]]; then
|
||||
cd Moon-Userbot || exit 2
|
||||
elif [[ "$(basename "$PWD")" == "Moon-Userbot" && -f ".env.dist" && -f "main.py" && -d "modules" ]]; then
|
||||
echo "Already inside the Moon-Userbot repo, proceeding."
|
||||
printf "${BLUE}Already inside the Moon-Userbot repo, proceeding...${NC}\n"
|
||||
else
|
||||
git clone https://github.com/The-MoonTg-project/Moon-Userbot || exit 2
|
||||
cd Moon-Userbot || exit 2
|
||||
fi
|
||||
|
||||
if [[ -f ".env" ]] && [[ -f "my_account.session" ]]; then
|
||||
echo "It seems that Moon-Userbot is already installed. Exiting..."
|
||||
printf "${GREEN}It seems that Moon-Userbot is already installed. Exiting...${NC}\n"
|
||||
exit
|
||||
fi
|
||||
|
||||
# Prompt user if they want to proceed with creating a virtual environment
|
||||
echo "It's recommended to use a virtual environment for Python projects."
|
||||
echo "Note: If your drive resources are very limited, you might consider not creating a virtual environment, but it shouldn't be rejected otherwise unless you know what you're doing."
|
||||
read -r -p "Would you like to create a virtual environment? (Y/n) > " create_venv
|
||||
printf "${YELLOW}It's recommended to use a virtual environment for Python projects.${NC}\n"
|
||||
printf "Note: If your drive resources are very limited, you might consider not creating a virtual environment, but it shouldn't be rejected otherwise unless you know what you're doing.\n"
|
||||
printf "If you're unsure, it's better to create a virtual environment.\n"
|
||||
printf "${INPUT}Would you like to create a virtual environment? (Y/n)${NC} > "
|
||||
read -r create_venv
|
||||
|
||||
if [[ "$create_venv" != "n" ]] && [[ "$create_venv" != "N" ]]; then
|
||||
# Create a virtual environment inside the cloned repository and activate it
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
# Create a virtual environment inside the cloned repository and activate it
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
|
||||
# Upgrade pip and install wheel and pillow
|
||||
pip install -U pip wheel pillow
|
||||
# Upgrade pip and install wheel and pillow
|
||||
pip install -U pip wheel pillow
|
||||
fi
|
||||
|
||||
if [ -d ".venv" ]; then
|
||||
. .venv/bin/activate
|
||||
elif [ -d "venv" ]; then
|
||||
. venv/bin/activate
|
||||
fi
|
||||
|
||||
# Install Python requirements
|
||||
pip install -U -r requirements.txt || exit 2
|
||||
# Prompt for API_ID and API_HASH
|
||||
echo
|
||||
echo "Enter API_ID and API_HASH"
|
||||
echo "You can get it here -> https://my.telegram.org/"
|
||||
echo "Leave empty to use defaults (please note that using default keys is a **very bad idea** and significantly increases your ban chances)"
|
||||
printf "Enter API_ID and API_HASH\n"
|
||||
printf "You can get it here -> https://my.telegram.org/\n"
|
||||
printf "Leave empty to use defaults (please note that using default keys is a ${RED}very bad idea${NC} and significantly increases your ban chances)\n"
|
||||
read -r -p "API_ID > " api_id
|
||||
|
||||
# Default API_ID and API_HASH
|
||||
if [[ $api_id = "" ]]; then
|
||||
echo "You have chosen to use the default API_ID and API_HASH, which is strongly discouraged."
|
||||
echo "Please type 'I agree' to confirm that you understand the risks and still wish to proceed."
|
||||
printf "${RED}You have chosen to use the default API_ID and API_HASH, which is strongly discouraged.${NC}\n"
|
||||
printf "${YELLOW}Please type${NC} '${BLUE}I agree${NC}'${YELLOW} to confirm that you understand the risks and still wish to proceed.${NC}\n"
|
||||
read -r -p "Confirmation > " confirmation
|
||||
if [[ $confirmation = "I agree" ]]; then
|
||||
api_id="2040"
|
||||
api_hash="b18441a1ff607e10a989891a5462e627"
|
||||
else
|
||||
echo "Confirmation not provided. Exiting..."
|
||||
printf "${RED}Confirmation not provided. Exiting...${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
@@ -102,149 +119,137 @@ else
|
||||
fi
|
||||
# Prompt for PM PERMIT warn limit
|
||||
# PM PERMIT warn limit is the number of messages a user can receive from others before giving them a warning, requires `antipm` plugin to be enabled
|
||||
echo
|
||||
echo "SET PM PERMIT warn limit"
|
||||
printf "SET PM PERMIT warn limit\n"
|
||||
# Now below is more clear version:
|
||||
echo "Enter the number of messages others can send you before receiving a warning, and eventually a ban or leave empty for default (3)"
|
||||
printf "The number of messages others can send you before receiving a warning, and eventually a ban or leave empty for default (3), requires $(antipm) plugin to be enabled\n"
|
||||
read -r -p "PM_LIMIT warn limit > " pm_limit
|
||||
|
||||
if [[ $pm_limit = "" ]]; then
|
||||
pm_limit="3"
|
||||
echo "Limit not provided by user; set to default"
|
||||
printf "Limit not provided by user; set to default\n"
|
||||
fi
|
||||
|
||||
# Prompt for musicbot usage
|
||||
echo
|
||||
echo "Do you want to use musicbot? (y/N)"
|
||||
read -r -p "MUSIC_BOT > " musicbot
|
||||
printf "Do you want to use musicbot? (y/N)"
|
||||
read -r musicbot
|
||||
if [[ $musicbot = "y" ]]; then
|
||||
echo
|
||||
echo "Enter SECOND_SESSION_STRING to be used by musicbot"
|
||||
printf "Enter SECOND_SESSION_STRING to be used by musicbot\n"
|
||||
read -r -p "SECOND_SESSION > " second_session
|
||||
if [[ $second_session = "" ]]; then
|
||||
echo "SECOND_SESSION not provided by user"
|
||||
printf "SECOND_SESSION not provided by user\n"
|
||||
second_session=""
|
||||
else
|
||||
echo
|
||||
echo "Please provide handler to be used by musicbot"
|
||||
printf "Please provide handler to be used by musicbotn\n"
|
||||
read -r -p "MUSIC_HANDLER > " music_handler
|
||||
if [[ $music_handler = "" ]]; then
|
||||
echo "MUSIC_HANDLER not provided by user"
|
||||
printf "MUSIC_HANDLER not provided by user\n"
|
||||
music_handler=""
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Prompt for various API keys
|
||||
echo "Enter APIFLASH_KEY for webshot plugin"
|
||||
echo "You can get it here -> https://apiflash.com/dashboard/access_keys"
|
||||
printf "Enter APIFLASH_KEY for webshot plugin\n"
|
||||
printf "You can get it here -> https://apiflash.com/dashboard/access_keys\n"
|
||||
read -r -p "APIFLASH_KEY > " apiflash_key
|
||||
|
||||
if [[ $apiflash_key = "" ]]; then
|
||||
echo "NOTE: API Not set; you'll get errors with webshot & ws module"
|
||||
printf "NOTE: API Not set; you'll get errors with webshot & ws module\n"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Enter RMBG_KEY for remove background module"
|
||||
echo "You can get it here -> https://www.remove.bg/dashboard#api-key"
|
||||
printf "Enter RMBG_KEY for remove background module\n"
|
||||
printf "You can get it here -> https://www.remove.bg/dashboard#api-key\n"
|
||||
read -r -p "RMBG_KEY > " rmbg_key
|
||||
|
||||
if [[ $rmbg_key = "" ]]; then
|
||||
echo "NOTE: API Not set; you'll not be able to use remove background modules"
|
||||
printf "NOTE: API Not set; you'll not be able to use remove background modules\n"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Enter VT_KEY for VirusTotal"
|
||||
echo "You can get it here -> https://www.virustotal.com/"
|
||||
printf "Enter VT_KEY for VirusTotal\n"
|
||||
printf "You can get it here -> https://www.virustotal.com/\n"
|
||||
read -r -p "VT_KEY > " vt_key
|
||||
|
||||
if [[ $vt_key = "" ]]; then
|
||||
echo "NOTE: API Not set; you'll not be able to use VirusTotal module"
|
||||
printf "NOTE: API Not set; you'll not be able to use VirusTotal module\n"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Enter GEMINI_KEY if you want to use AI"
|
||||
echo "You can get it here -> https://makersuite.google.com/app/apikey"
|
||||
printf "Enter GEMINI_KEY if you want to use AI\n"
|
||||
printf "You can get it here -> https://makersuite.google.com/app/apikey\n"
|
||||
read -r -p "GEMINI_KEY > " gemini_key
|
||||
|
||||
if [[ $gemini_key = "" ]]; then
|
||||
echo "NOTE: API Not set; you'll not be able to use Gemini AI modules"
|
||||
printf "NOTE: API Not set; you'll not be able to use Gemini AI modules\n"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Enter COHERE_KEY if you want to use AI"
|
||||
echo "You can get it here -> https://dashboard.cohere.com/api-keys"
|
||||
printf "Enter COHERE_KEY if you want to use AI"
|
||||
printf "You can get it here -> https://dashboard.cohere.com/api-keys\n"
|
||||
read -r -p "COHERE_KEY > " cohere_key
|
||||
|
||||
if [[ $cohere_key = "" ]]; then
|
||||
echo "NOTE: API Not set; you'll not be able to use Coral AI modules"
|
||||
printf "NOTE: API Not set; you'll not be able to use Coral AI modules\n"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Enter VCA_API_KEY for aiutils"
|
||||
echo "Learn How to Get One --> https://github.com/VisionCraft-org/VisionCraft?tab=readme-ov-file#obtaining-an-api-key"
|
||||
printf "Enter VCA_API_KEY for aiutils\n"
|
||||
printf "Learn How to Get One --> https://github.com/VisionCraft-org/VisionCraft?tab=readme-ov-file#obtaining-an-api-key\n"
|
||||
read -r -p "VCA_API_KEY > " vca_api_key
|
||||
|
||||
if [[ $vca_api_key = "" ]]; then
|
||||
echo "NOTE: API Not set; you'll not be able to use aiutils module/plugins"
|
||||
printf "NOTE: API Not set; you'll not be able to use aiutils module/plugins\n"
|
||||
fi
|
||||
|
||||
|
||||
echo
|
||||
while true; do
|
||||
# Prompt for database type and database URL if MongoDB is selected
|
||||
echo
|
||||
echo "Choose database type:"
|
||||
echo "[1] MongoDB db_url"
|
||||
echo "[2] MongoDB localhost"
|
||||
echo "[3] Sqlite (default)"
|
||||
printf "${YELLOW}Choose database type:${NC}\n"
|
||||
printf "[1] MongoDB db_url\n"
|
||||
printf "[2] MongoDB localhost\n"
|
||||
printf "[3] Sqlite (default)\n"
|
||||
read -r -p "> " db_type
|
||||
|
||||
case $db_type in
|
||||
1)
|
||||
echo "Please enter db_url"
|
||||
echo "You can get it here -> https://mongodb.com/atlas"
|
||||
read -r -p "> " db_url
|
||||
db_name=Moon_Userbot
|
||||
db_type=mongodb
|
||||
break
|
||||
;;
|
||||
2)
|
||||
if ! command -v apt &>/dev/null; then
|
||||
echo "This option requires apt package manager, which is not available on your system."
|
||||
echo "Please choose a different database type."
|
||||
continue
|
||||
fi
|
||||
1)
|
||||
printf "Please enter db_url\n"
|
||||
printf "You can get it here -> https://mongodb.com/atlas\n"
|
||||
read -r -p "> " db_url
|
||||
db_name=Moon_Userbot
|
||||
db_type=mongodb
|
||||
break
|
||||
;;
|
||||
2)
|
||||
if ! command -v apt &>/dev/null; then
|
||||
printf "This option requires apt package manager, which is not available on your system.\n"
|
||||
printf "Please choose a different database type.\n"
|
||||
continue
|
||||
fi
|
||||
|
||||
if systemctl status mongodb; then
|
||||
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | apt-key add -
|
||||
source /etc/os-release
|
||||
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${UBUNTU_CODENAME}/mongodb-org/5.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-5.0.list
|
||||
apt update
|
||||
apt install mongodb -y
|
||||
systemctl daemon-reload
|
||||
systemctl enable mongodb
|
||||
fi
|
||||
systemctl start mongodb
|
||||
if systemctl status mongodb; then
|
||||
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | apt-key add -
|
||||
source /etc/os-release
|
||||
printf "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${UBUNTU_CODENAME}/mongodb-org/5.0 multiverse\n" | tee /etc/apt/sources.list.d/mongodb-org-5.0.list
|
||||
apt update
|
||||
apt install mongodb -y
|
||||
systemctl daemon-reload
|
||||
systemctl enable mongodb
|
||||
fi
|
||||
systemctl start mongodb
|
||||
|
||||
db_url=mongodb://localhost:27017
|
||||
db_name=Moon_Userbot
|
||||
db_type=mongodb
|
||||
break
|
||||
;;
|
||||
3)
|
||||
db_name=db.sqlite3
|
||||
db_type=sqlite3
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Invalid choice!"
|
||||
;;
|
||||
db_url=mongodb://localhost:27017
|
||||
db_name=Moon_Userbot
|
||||
db_type=mongodb
|
||||
break
|
||||
;;
|
||||
3)
|
||||
db_name=db.sqlite3
|
||||
db_type=sqlite3
|
||||
break
|
||||
;;
|
||||
*)
|
||||
printf "${RED}Invalid choice!${NC}\n"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Generate .env file with collected variables
|
||||
cat > .env << EOL
|
||||
cat >.env <<EOL
|
||||
API_ID=${api_id}
|
||||
API_HASH=${api_hash}
|
||||
STRINGSESSION=
|
||||
@@ -268,47 +273,44 @@ EOL
|
||||
# Adjust the ownership of the Moon-Userbot directory
|
||||
chown -R $SUDO_USER:$SUDO_USER .
|
||||
|
||||
|
||||
# Configure the bot based on selected installation type
|
||||
while true; do
|
||||
# Prompt for installation type and execute accordingly
|
||||
echo
|
||||
echo "Choose installation type:"
|
||||
echo "[1] PM2"
|
||||
echo "[2] Systemd service"
|
||||
echo "[3] Custom (default)"
|
||||
printf "${YELLOW}Choose installation type:${NC}\n"
|
||||
printf "[1] PM2\n"
|
||||
printf "[2] Systemd service\n"
|
||||
printf "[3] Custom (default)\n"
|
||||
read -r -p "> " install_type
|
||||
|
||||
case $install_type in
|
||||
1)
|
||||
if ! command -v apt &>/dev/null; then
|
||||
echo "This option requires apt package manager, which is not available on your system."
|
||||
echo "Please choose a different installation type."
|
||||
continue
|
||||
fi
|
||||
1)
|
||||
if ! command -v apt &>/dev/null; then
|
||||
printf "This option requires apt package manager, which is not available on your system.\n"
|
||||
printf "Please choose a different installation type.\n"
|
||||
continue
|
||||
fi
|
||||
|
||||
if ! command -v pm2 &>/dev/null; then
|
||||
curl -fsSL https://deb.nodesource.com/setup_17.x | bash
|
||||
apt install nodejs -y
|
||||
npm install pm2 -g
|
||||
su -c "pm2 startup" $SUDO_USER
|
||||
env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u $SUDO_USER --hp /home/$SUDO_USER
|
||||
fi
|
||||
su -c "pm2 start main.py --name Moon --interpreter python3" $SUDO_USER
|
||||
su -c "pm2 save" $SUDO_USER
|
||||
if ! command -v pm2 &>/dev/null; then
|
||||
curl -fsSL https://deb.nodesource.com/setup_17.x | bash
|
||||
apt install nodejs -y
|
||||
npm install pm2 -g
|
||||
su -c "pm2 startup" $SUDO_USER
|
||||
env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u $SUDO_USER --hp /home/$SUDO_USER
|
||||
fi
|
||||
su -c "pm2 start main.py --name Moon --interpreter python3" $SUDO_USER
|
||||
su -c "pm2 save" $SUDO_USER
|
||||
|
||||
echo
|
||||
echo "============================"
|
||||
echo "Great! Moon-Userbot installed successfully and running now!"
|
||||
echo "Installation type: PM2"
|
||||
echo "Start with: \"pm2 start Moon\""
|
||||
echo "Stop with: \"pm2 stop Moon\""
|
||||
echo "Process name: Moon"
|
||||
echo "============================"
|
||||
break
|
||||
;;
|
||||
2)
|
||||
cat > /etc/systemd/system/Moon.service << EOL
|
||||
printf "${GREEN}============================\\n"
|
||||
printf "Great! Moon-Userbot installed successfully and running now!\n"
|
||||
printf "Installation type: PM2\n"
|
||||
printf "Start with: \"pm2 start Moon\"\n"
|
||||
printf "Stop with: \"pm2 stop Moon\"\n"
|
||||
printf "Process name: Moon\n"
|
||||
printf "============================${NC}\n"
|
||||
break
|
||||
;;
|
||||
2)
|
||||
cat >/etc/systemd/system/Moon.service <<EOL
|
||||
[Unit]
|
||||
Description=Service for Moon Userbot
|
||||
[Service]
|
||||
@@ -321,35 +323,33 @@ Group=${SUDO_USER}
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOL
|
||||
systemctl daemon-reload
|
||||
systemctl start Moon
|
||||
systemctl enable Moon
|
||||
systemctl daemon-reload
|
||||
systemctl start Moon
|
||||
systemctl enable Moon
|
||||
|
||||
echo
|
||||
echo "============================"
|
||||
echo "Great! Moon-Userbot installed successfully and running now!"
|
||||
echo "Installation type: Systemd service"
|
||||
echo "Start with: \"sudo systemctl start Moon\""
|
||||
echo "Stop with: \"sudo systemctl stop Moon\""
|
||||
echo "============================"
|
||||
break
|
||||
;;
|
||||
3)
|
||||
echo
|
||||
echo "============================"
|
||||
echo "Great! Moon-Userbot installed successfully!"
|
||||
echo "Installation type: Custom"
|
||||
echo "Start with: \"python3 main.py\""
|
||||
echo "============================"
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Invalid choice! Please enter 1, 2, or 3."
|
||||
;;
|
||||
printf "${GREEN}============================\\n"
|
||||
printf "Great! Moon-Userbot installed successfully and running now!"
|
||||
printf "Installation type: Systemd service"
|
||||
printf "Start with: \"sudo systemctl start Moon\""
|
||||
printf "Stop with: \"sudo systemctl stop Moon\""
|
||||
printf "============================${NC}\n"
|
||||
break
|
||||
;;
|
||||
3)
|
||||
printf "${GREEN}============================\\n"
|
||||
printf "Great! Moon-Userbot installed successfully!"
|
||||
printf "Installation type: Custom"
|
||||
printf "Start with: \"python3 main.py\""
|
||||
printf "============================${NC}\n"
|
||||
break
|
||||
;;
|
||||
*)
|
||||
printf "Invalid choice! Please enter 1, 2, or 3."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
su -c "python3 install.py ${install_type}" $SUDO_USER || exit 3
|
||||
su -c "python3 install.py ${install_type}" $SUDO_USER || exit 3
|
||||
|
||||
# Adjust the ownership of the Moon-Userbot directory again as a final step
|
||||
chown -R $SUDO_USER:$SUDO_USER .
|
||||
chown -R $SUDO_USER:$SUDO_USER .
|
||||
|
||||
Reference in New Issue
Block a user