Initial commit

This commit is contained in:
2023-05-11 12:02:10 +02:00
commit efdd9aaeee
2 changed files with 123 additions and 0 deletions

14
README.md Normal file
View File

@@ -0,0 +1,14 @@
# README
This repo contains the script to manage multiple mcr bot on a single VM/Container.
## Structure
├── start.sh
│ ├── bot-name-1
│ │ ├── ms_rewards_farmer.py
│ ├── bot-name-2
│ │ ├── ms_rewards_farmer.py
│ ├── bot-name-3
│ │ ├── ms_rewards_farmer.py
│ ├── ...

109
start.sh Normal file
View File

@@ -0,0 +1,109 @@
#!/bin/bash
if [ "$(ps -o comm= $PPID)" != "kgx" ]
then
echo "Script is running under $(ps -o comm= $PPID)"
if rpm -q gnome-console >/dev/null; then
echo "gnome-console is already installed"
else
echo "Installing gnome-console"
sudo dnf install gnome-console -y
fi
echo "Restarting script in gnome-console..."
kgx -e "/bin/bash -c 'cd $(dirname "$(readlink -f "$0")"); ./$(basename "$0")'" &
read -t 2
pkill -f "gnome-terminal"
exit
fi
interval=300
schedule=("06:00" "08:00" "10:00" "12:00" "14:00" "16:00" "18:00" "20:00")
vpns=$(nmcli connection show | grep vpn | awk '{print $1}')
retries=3
webhook=''
while true
do
current_time=$(date +%H:%M)
next_index=-1
for i in "${!schedule[@]}"
do
if [[ "$current_time" < "${schedule[$i]}" ]]
then
next_index=$i
break
fi
done
if [ $next_index -eq -1 ]
then
next_index=0
fi
next_time="${schedule[$next_index]}"
if [[ "$current_time" > "${schedule[$next_index]}" ]]
then
next_seconds=$(($(date -d "$next_time +1 day" +%s) - $(date +%s)))
else
next_seconds=$(($(date -d "$next_time" +%s) - $(date +%s)))
fi
if [ $next_seconds -lt 0 ]
then
exit
fi
while [ $next_seconds -gt 0 ]
do
echo -ne "\033[0K\rWaiting for $next_time... (in $next_seconds s) "
read -t 1
next_seconds=$(( $next_seconds - 1 ))
done
echo ""
next_vpn_index=$(( $next_index + 1 ))
vpn=$(echo "$vpns" | sed -n "${next_vpn_index}p")
echo "VPN: $next_vpn_index $vpn"
if [ "$vpn" != "" ]
then
echo "Killing potential previous bot..."
pkill -f "gnome-terminal"
echo "Switching VPN..."
nmcli connection down $(nmcli connection show --active | grep vpn | awk '{print $1}')
attempt=1
while [ $attempt -le $retries ]
do
nmcli connection up $vpn
read -t 2
if nmcli connection show --active | grep -q $vpn
then
echo "VPN connection successfully established"
echo "Starting script..."
if [ -d "./$vpn" ]
then
gnome-terminal -- sh -c "cd ./$vpn && python ms_rewards_farmer.py --dont-check-for-updates --shuffle --session --superfast --on-finish exit --no-webdriver-manager --discord $webhook; exit; exec bash" &
read -t 2
echo "Script started"
read -t 1
break
else
echo "Folder ./$vpn does not exist, skipping starting bot"
read -t 3
break
fi
else
echo "Failed to establish VPN connection (attempt $attempt of $retries)"
if [ $attempt -eq $retries ]
then
echo "Max retries reached, switching to the next available VPN connection"
fi
read -t 1
fi
attempt=$(( $attempt + 1 ))
done
fi
done