114 lines
2.9 KiB
Bash
114 lines
2.9 KiB
Bash
#!/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
|
|
|
|
vpns=$(nmcli connection show | grep vpn | awk '{print $1}')
|
|
|
|
config_file="config.txt"
|
|
if [ -f "$config_file" ]; then
|
|
source "$config_file"
|
|
else
|
|
echo "Config file not found."
|
|
exit 1
|
|
fi
|
|
|
|
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
|
|
echo 'schedule error, exiting...'
|
|
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 [ -f "./Microsoft-Rewards-bot/$vpn.json" ]
|
|
then
|
|
gnome-terminal -- sh -c "cd Microsoft-Rewards-bot && python ms_rewards_farmer.py --dont-check-for-updates --shuffle --session --superfast --on-finish exit --no-webdriver-manager --accounts-file $vpn.json --discord $webhook; exit; exec bash" &
|
|
read -t 2
|
|
echo "Script started"
|
|
read -t 1
|
|
break
|
|
else
|
|
echo "File ./Microsoft-Rewards-bot/$vpn.json does not exist, skipping starting bot for this VPN"
|
|
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 |