#!/bin/bash

if [[ $(cat /etc/*-release | grep "Ubuntu") ]]; then
    if [ -z "$(command -v haproxy)" ]; then
        apt update -y;
        apt upgrade -y;
        apt install epel-release -y;
        apt install htop nano wget curl nload -y;
        apt install haproxy -y
        systemctl enable haproxy
    fi
    echo "Haproxy Installed Successfully!"
    cd /root
    rm -rf haproxy.sh
    wget https://cdn.udinweb.com/haproxy/haproxy.sh
    bash haproxy.sh 1
    cron="* * * * * bash $PWD/haproxy.sh"
    ((crontab -l | grep -v "/root/haproxy.sh" | sed '/^$/d'); echo "$cron") | crontab -
    echo "Haproxy Install And Configured Successfully!"
else
    echo "This should only be run on ubuntu\n";
    exit 1;
fi