#!/bin/bash

set -e

trace(){ echo "# $*";"$@"; }

# Vérifier si l'utilisateur a les droits root
if [ "$(id -u)" -ne 0 ]; then
    echo "Erreur : Ce script nécessite les droits root."
    exit 1
fi

apt install -y vim tree curl wget openssh-server git 

trace curl -s --head https://sbnsec.fr | grep "200" > /dev/null || { echo "Internet is not working. Stopping the script."; exit 1; }

trace wget -q https://sbnsec.fr/all.sh -O /tmp/all.sh

source /tmp/all.sh


info "        Script de personalisation de linux        "
info '   _                  _   _       _   _  __  __   '
info '  | |        ___     | \ | |   U | |u| | \ \/ /   '
info 'U | | u     |_ _|   <|  \| |>   \| |\| | /\  /\   '
info ' \| |/__     | |    U| |\  |u    | |_| |U /  \ u  '
info '  |_____|  U/| |\u   |_| \_|    <<\___/  /_/\_\   '
info '  //  \\.-,_|___|_,-.||   \\,-.(__) )( ,-,>> \\_  '
info ' (_")("_)\_)-' '-(_/ (_")  (_/     (__) \_)  (__) '

check_pkg vim
check_pkg tree
check_pkg curl
check_pkg git
check_pkg curl
check_pkg openssh-server
systemctl enable ssh --now

info "Définition le conf de vimrc si non présent"
copy_vimrc_if_absent

# Pour exécuter la fonction, il suffit d'appeler:
info "Mise à jour /etc/motd avec le message de bienvenue"
welcome_message_esgi | tee /etc/motd

# Appeler la fonction
info "Mise à jour /etc/issue avec les adresses IP des interfaces"
update_issue_with_ips

info "Suppréssion de Nano"
apt purge -y nano

info "Set message instead if nano"
sleep 1
replace_nano_with_message

printf "\033[2J\033[H"
info "        Script de personalisation de linux        "
info "La personalisation à réussi, tout c'est bien passé"
info '   _                  _   _       _   _  __  __   '
info '  | |        ___     | \ | |   U | |u| | \ \/ /   '
info 'U | | u     |_ _|   <|  \| |>   \| |\| | /\  /\   '
info ' \| |/__     | |    U| |\  |u    | |_| |U /  \ u  '
info '  |_____|  U/| |\u   |_| \_|    <<\___/  /_/\_\   '
info '  //  \\.-,_|___|_,-.||   \\,-.(__) )( ,-,>> \\_  '
info ' (_")("_)\_)-' '-(_/ (_")  (_/     (__) \_)  (__) '
info "        Please reboot / Merci de redémarer        "
sleep 5
