#!/bin/bash

print_title_1()
{
    echo -e "\e[104m====> $1                                                                                                    \e[0m"
}

print_title_2()
{
    echo -e "\e[35m   => $1\e[0m"
}

print_title_3()
{
    echo -e "\e[33m     => $1\e[0m"
}

print_result()
{
    if [ $1 -eq 0 ]
    then
        echo -e "\e[32m  $2 => Success \e[0m"
    else
        echo -e "\e[31m  $2 => Error \e[0m" >&2
    fi
}

check_internet()
{
    if [[ -z $1 ]] ; then
        url="https://debs.photo-me.eu"
    else
        url=$1
    fi
    wget -q --spider $url

    result=$?
    if [ $result ]; then
        sudo apt update --allow-releaseinfo-change
        result=$?
    fi

    return $result
}

show_error()
{
    print_result 1 $1
    zenity --error --text="${1}" --width=500 --height=350
}
