#! /bin/bash
# Script post install pour Debian 13 trixie
# Laurent.B MAJ 24/09/2025
#
nomdecode=$(lsb_release -cs 2>/dev/null)
echo "$nomdecode détectée" 

repcourant=$(pwd)

cf='\033[0m'
blanc='\033[1m'
vert='\033[1;32m'
rouge='\033[31m'
jaune='\033[1;33m'
bleu='\033[34m'
violet='\033[35m'

debug=1
#debug=0

function pause { if [ $debug == 1 ]; then echo "Mode DEBUG Activé - Pause" && read;fi }

pause

apt -y install vim byobu pcp tilix htop
update-alternatives --set editor /usr/bin/vim.basic


if ( journalctl -k|egrep 'ERROR.*radeon.*requires firmware installed');then
 apt -f install firmware-amd-graphics
fi

pause

if ( journalctl -k|egrep 'firmware');then
 echo "Firmware peut-être manquant"
fi



#wget http://l.iut-nimes.fr/maintenance/raccourcis-clavier-gnome.sh
#gsettings set "org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:" name "Terminal"
#gsettings set "org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:" command "x-terminal-emulator"
#gsettings set "org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:" binding "<Ctrl><Alt>T"

pause

: <<'Fin'


if [ ! -e /opt/p ];then mkdir /opt/p;fi
cd /opt/p
chmod +x /opt/p/p
if ( wget -N http://l.iut-nimes.fr/maintenance/p-$nomdecode -O p 2>&1|grep "enregistré" );then chmod +x /opt/p/p;echo "Script mis à jour, merci de le relancer /opt/p/p" && exit 0;fi
if [ -e $repcourant/p ];then rm $repcourant/p;fi
if [ -e $repcourant/t ];then rm $repcourant/t;fi
if [ -e $repcourant/f ];then rm $repcourant/f;fi
if [ -e $repcourant/tilix-profil-dconf-v1 ];then rm $repcourant/tilix-profil-dconf-v1;fi
if [ -e $repcourant/ms.tar.gz ];then rm $repcourant/ms.tar.gz;fi


echo -e "\n $vert-- Script $cf $blanc POST INSTALL $cf et de $bleu maintenance $cf pour $jaune Debian $violet $nomdecode -- $cf \n"

echo -e "\n\n-- Activation des dépots tierces --\n"
pause
if (grep "non-free-firmware" /etc/apt/sources.list|grep "contrib"|egrep "non-free$|non-free ");then
 echo "Dépots tierces déjà activé"
else
 wget http://l.iut-nimes.fr/maintenance/sources.list-$nomdecode -O /etc/apt/sources.list
 echo "Activation des dépots tierces par remplacement du source.list"
fi


#script nettoyage
echo -e "\n $vert-- Mise en place du script nettoyage noyau  -- $cf \n"
pause
cd /usr/local/sbin/
wget -N http://l.iut-nimes.fr/maintenance/nettoyage && chmod +x /usr/local/sbin/nettoyage
cd -
nettoyage


echo -e "\n $vert-- Mise à jour des paquets -- $cf \n"
pause
apt update && apt -y dist-upgrade &&

echo -e "\n $bleu -- Installation des outils de bases -- $cf \n"i
pause
apt -y install net-tools deborphan vim bwm-ng ssh byobu  gpm htop dstat synaptic gdebi vlc lshw gparted x11vnc iotop apt-show-versions inxi pbzip2 pigz lbzip2 lzip plzip p7zip mpv lftp rsync bash-completion\
&&


for i in adm dialout fax cdrom floppy tape sudo audio dip video plugdev scanner lpadmin netdev sambashare vboxusers; do adduser lbarrail $i;done

apt-get clean

#Colorisation du prompt bash
sed -i 's@#force_color_prompt=yes@force_color_prompt=yes@' /root/.bashrc
sed -i 's#\[\\033\[01;32m\\]\\u@\\h\\\[\\033\[00m\\]:\\\[\\033\[01;34m\\]\\w\\\[\\033#\[\\e\[1;31m\\]\\u@\\\[\\e\[1;32m\\]\\h\\\[\\e\[00m\\]:\\\[\\e\[1;34m\\]\\w\\\[\\e#' /root/.bashrc
for i in /home/* /etc/skel
do
 sed -i 's@#force_color_prompt=yes@force_color_prompt=yes@' $i/.bashrc
 sed -i 's#\[\\033\[01;32m\\]\\u@\\h\\\[\\033\[00m\\]:\\\[\\033\[01;34m\\]\\w\\\[\\033#\[\\e\[1;32m\\]\\u@\\\[\\e\[1;33m\\]\\h\\\[\\e\[00m\\]:\\\[\\e\[1;34m\\]\\w\\\[\\e#' $i/.bashrc
done

#Ajout de polices
echo -e "\n $vert-- Ajout des polices Windows7  -- $cf \n"
pause
wget -N http://l.iut-nimes.fr/polices/ms.tar.gz
tar -I pigz -xf ms.tar.gz -C /usr/local/share/fonts/
rm -rf /usr/local/share/fonts/office

#Serveur vnc
echo -e "\n $vert-- Ajout du serveur vnc perso x11vnc  -- $cf \n"
pause
wget -N http://l.iut-nimes.fr/vnc/vncsrv
cp vncsrv /usr/local/bin/
chmod +x /usr/local/bin/vncsrv

echo -e  "\n $vert Paquets locaux ou obsolètes $cf"
pause
apt purge $(apt-show-versions | grep 'No available version' | awk '{print $1}')

wget -N l.iut-nimes.fr/f
chmod +x /opt/p/f

#Pour Debian 11 bullseye
if ( lsb_release -c|grep 'bullseye' )
then
echo -e "\n $bleu -- Debian Bullseye détectée -- $cf \n"
pause
 apt -y install chrome-gnome-shell tilix firmware-misc-nonfree vulkan-tools gnome-remote-desktop flatpak task-french-desktop chromium-l10n
fi

wget -N l.iut-nimes.fr/t
chmod +x t && ./t
touch /etc/rc.local && chmod +x /etc/rc.local


nettoyage

#Info sur la machine
echo -e  "\n $vert Info sur la machine via l'utilitaire inxi $cf"
echo -e "\n inxi -Fx \n"
inxi -Fx

echo "xhci_hcd.quirks=262144"
echo "systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target"
echo "systemctl umask sleep.target suspend.target hibernate.target hybrid-sleep.target"

Fin

