#!/bin/sh
VERT="\\033[1;32m"
NORMAL="\\033[0;39m"
ROUGE="\\033[1;31m"
ROSE="\\033[1;35m"
BLEU="\\033[1;34m"
BLANC="\\033[0;02m"
BLANCLAIR="\\033[1;08m"
JAUNE="\\033[1;33m"
CYAN="\\033[1;36m"

# Le fichier /proc/cpuinfo contient des information sur le processeur

# Extraction des donnes (ne marche que s'il y a un seul processeur)
MODEL=`cat /proc/cpuinfo | grep "model name" | tr -s " " | cut -d ":" -f 2`
FREQ=`cat /proc/cpuinfo | grep "MHz" | tr -s " " | cut -d ":" -f 2 | cut -d "." -f1 | sed -e "s/ //"`

# le fichier /proc/loadavg contient la charge du processeur
# charge utilisateur	system		nice
CHARGEINSTANT=`cat /proc/loadavg | cut -d " " -f 1`
CHARGEINSTANTP=`echo "scale=10 ; $CHARGEINSTANT*100" | bc -l `
CHARGEMOYENNE=`cat /proc/loadavg | cut -d " " -f 2`
MEMLIBRE=`free | cut -b 34-41 | head -2 | tail -1`
CHARGEMOYENNEP=`echo "scale=10 ; $CHARGEMOYENNE*100" | bc -l `
PROCESSUS=`cat /proc/loadavg | cut -d " " -f 4 | cut -d "/" -f 2`
VERSION=`cat /proc/version`
PARTITIONS=`cat /proc/partitions | cut -b 23-30 | sed -e's/name/nom\ :\ /'`
PARTITIONS_NB=`cat /proc/partitions | nl | cut -b 5-6 | tail -1` 
CARTEGRAPH=`cat /etc/X11/xorg.conf | grep BoardName | sed -e's/BoardName/Carte Graphique :/'`
DRIVERVID=`cat /etc/X11/xorg.conf | grep Driver | tail -1 | sed -e's/Driver/Driver de la carte graphique :/'`
CARTESON=`cat /proc/asound/cards | tail -1`
DRIVERSON=`cat /proc/asound/version`
LOGNAME=`printenv | grep LOGNAME | sed -e's/LOGNAME=/login\ :\ /'`
TYPEBUREAU=`printenv | grep GDMSESSION | sed -e's/GDMSESSION=/type de bureau\ :\ /'`
MONITEUR=`cat /etc/X11/xorg.conf | grep Monitor | grep SaX | sed -e's/Option/\ :\ /' | tr -s " " " " | cut -d " " -f 4,5`
NBTOTDOSS=`ls -a -l | grep ^d | wc -l`
NBDOSS=`ls -l | grep ^d | wc -l`
NBDOSSCACH=$(($NBTOTDOSS - $NBDOSS))
NBTOTFIC=`ls -a -l | grep ^- | wc -l`
NBFIC=`ls -l | grep ^- | wc -l`
NBFICCACH=$(($NBTOTFIC - $NBFIC))

temps=0

clear

function analysePs() {
   local mem=0
   local cpu=0
   read
   while read ; do
      local icpu=`echo $REPLY | tr -s " " | cut -d " " -f 3`
      local imem=`echo $REPLY | tr -s " " | cut -d " " -f 4`
      mem=`echo "scale=2; $mem + $imem " | bc`
      cpu=`echo "scale=2; $cpu + $icpu " | bc`
   done
   echo $mem $cpu
   return 0
}

filtre='.*'
if [ $# -gt 0 ] ; then
  if [ $1 == "-user" ] ; then
     filtre=$2
  else
     echo "$0 [-user ident | -help]"
     echo "Affiche l'utilisation CPU et Memoire de la machine ou d'un utilisateur en particulier"
  fi
fi

ret=`ps aux | grep "$filtre" | analysePs`
gmem=`echo $ret | cut -d " " -f 1`
gcpu=`echo $ret | cut -d " " -f 2`



# Affichage
until [ $temps -eq 6 ]; do
echo "





"
echo -e "$ROUGE""		 ###############################################"
echo -e "$ROUGE""		 ## Ce script a ete realise avec la Suse 10.1 ##"
echo -e "$ROUGE""	 	 ###############################################""$NORMAL"
echo "

"
echo "		              _,,,_"
echo " 		           .'     \`'."
echo " 		          /     ____ \\"
echo " 		          |  .-'_  _\\/"
echo " 		          \_/   a  a|"
echo " 		          (,\`     \ |         .----. "
echo " 		           |     -' |        /|     '--."
echo " 		            \   '=  /        ||    ]|   \`-."
echo " 		            /\`-.__.'         ||    ]|    ::|"
echo " 		         .-'\`-.__ \\__        ||    ]|    ::|"
echo " 		        /        \`\`  \`.      ||    ]|    ::|"
echo " 		      _ |     \\     \\  \\     \\|    ]|   .-'" 
echo " 		     / \\|      \\    |   \\     L.__  .--'("
echo " 		    |   |\      \`.  |    \  ,---|_      \\---------,"
echo " 		    |   | '.      './\\    \\/ .--._|=-    |_      /|"
echo " 		    |   \\   '.     \`'.'. /\`\\/ .-'          '.   / | "
echo " 		    |   |     \`'.     \`;-:-;\`)|             |-./  |"
echo " 		    |   /_       \`'--./_  \` )/'-------------')/)  |"
echo " 		    \   | \`\"\"\"\"----\"\`\\//\`\"\"\`/,===..'\`\`\`\`\`\`\`\`\`/ (  |"
echo " 		     |  |            / \`---\` \`==='          /   ) | "
echo " 		     /  \\           /                      /   (  |"
echo " 		    |    '------.  |'--------------------'|     ) |"
echo " 		     \\           \`-|                      |    /  |"
echo " 		     \\           \`-|                      |    /  |"
echo " 		      \`--...,______|                      |   (   | "
echo " 		             | |   |                      |    ) ,|"
echo " 		             | |   |                      |   ( /||"
echo " 		             | |   |                      |   )/ \`\""
echo " 		            /   \\  |                      |  (/ "
echo " 		          .' /I\\ '.|                      |  /)"
echo " 		       .-'_.'/ \\'. |                      | / "
echo " 		       \`\`\`  \`\"\"\"\` \`| .-------------------.|| "
echo " 		                   \`\"\`                   \`\"\`  "
echo "


"
echo "				chargement "$(($temps * 20))"\%"

if [ $temps -eq 0 ]; then
	echo "			[                         ]"
fi
if [ $temps -eq 1 ]; then
	echo -e "			["$JAUNE"#####                    "$NORMAL"]"
fi	
if [ $temps -eq 2 ]; then
	echo -e	"			["$JAUNE"##########               "$NORMAL"]"
fi
if [ $temps -eq 3 ]; then
	echo -e "			["$JAUNE"###############          "$NORMAL"]"
fi
if [ $temps -eq 4 ]; then
	echo -e "			["$JAUNE"####################     "$NORMAL"]"
fi
if [ $temps -eq 5 ]; then
	echo -e "			["$JAUNE"#########################"$NORMAL"]"
fi

temps=$(($temps + 1))
echo "



"
sleep 1
clear
done


clear
choix=0
while [ $choix -ne 12 ]; do
	echo -e "$JAUNE" "
			 _______________________
			[  ___________________  ]
			[ [  "$BLEU"____       ____  "$JAUNE"] ]
			[ |  "$BLEU"|__|       |__|  "$JAUNE"| ]
			[ |         "$BLEU"|         "$JAUNE"| ]
			[ |         "$BLEU"|         "$JAUNE"| ]
			[ |                   | ]
			[ |      "$BLEU"\_____/      "$JAUNE"| ]
			[ |___________________| ]______
			[_______________________]      )
		 	 ______________(_________      (
			[ "$ROUGE"L L L L L L L L L L L L"$JAUNE"]     )
			[ "$ROUGE"LLLLLLLLLLLLLLLLLLLLLL "$JAUNE"]    "$CYAN"_"$JAUNE"("$CYAN"_
			"$JAUNE"[ "$ROUGE"LLLLLLLLLLLLLLLLLLLLLL "$JAUNE"]   "$CYAN"|_|_|
			"$JAUNE"[________________________]   "$CYAN"|   |
       		                                     |___| 		


"
	echo -e $BLEU "
		-----------------------------------------
		|  QUELLES INFORMATIONS VOULEZ-VOUS ?  |" $NORMAL
	echo -e $BLEU "		----------------------------------------

" $NORMAL
	echo "		1 Informations repertoire courant
"
	echo "		2 Informations processeur
"
	echo "		3 Utilisation globale du CPU et de la memoire
"
	echo "		4 Information systeme
"
	echo "		5 Partitionnement du disque dur
"
	echo "		6 Occupation des disques
"
	echo "		7 Informations composants
"
	echo "		8 Informations usb et peripheriques connectes
"
	echo "		9 Informations Utilisateur
"
	echo "		10 Informations Diverses
"
	echo "		11 Credits
"
	echo "		12 Quitter"

read choix
case $choix in
	'1') 	clear
		echo "


		"
		echo -e $BLEU"		# Informations repertoire courant"
		echo -e "		---------------------------------
		" $NORMAL
		echo "  + Adresse du répertoire courant : `pwd`"
		echo "  + Taille du répertoire courant : `du -sh`"
		echo "  + Il contient "$NBTOTDOSS" repertoires, dont "$NBDOSSCACH" repertoires caches"
		echo "  + Il contient "$NBTOTFIC" fichiers, dont "$NBFICCACH" fichiers caches"
		echo "

		"
	echo -e "$CYAN" "      
	            ______
	           (      )         "$ROUGE"|--_-- "$VERT"__--__
	           "$CYAN"| "$ROUGE"@  @ "$CYAN"|         "$ROUGE"|     |"$VERT"      |
	           "$CYAN"|  \\/  |         "$ROUGE"|     |"$VERT"      |
	          "$CYAN"_| \\--/ |_         "$ROUGE"--_--|"$VERT"      |
	         "$CYAN"/          \\      "$BLEU" |      "$JAUNE"__--__ 
	        "$CYAN"/ /| ____ |\\ \\      "$BLEU"|     "$JAUNE"|      |
	       "$CYAN"| | ||    || | |     "$BLEU"|     "$JAUNE"|      |
	       "$CYAN"|_| || a  || |_|      "$BLEU"--_--"$JAUNE"|__--__| 
	           "$CYAN"||____||
	           |"$JAUNE"/\\__"$JAUNE"/\\| 
	           "$JAUNE"[_]  [_]
	"

		read
		clear
	;;
	'2') 	clear
		echo "


		"
		echo -e $BLEU"		# Informations processeur"
		echo -e "		-------------------------
		" $NORMAL
		echo "  + Modele :"$MODEL"("$FREQ" Mhz)"
		echo "  + Charge actuelle du processeur :"$CHARGEINSTANTP"%"
		echo "  + Charge moyenne sur 5 minutes :"$CHARGEMOYENNEP"%"
		echo "  + Il y a actuellement "$PROCESSUS" processus lances sur le systeme"
		echo "

		"
		 echo -e "$NORMAL" "
	
	                  _______________                                                         
       	                 /        _     /\\                                 
       	                /        "$VERT"| \\   "$NORMAL"/ /"$JAUNE"|                                     
       	               "$NORMAL"/"$VERT"__  |\\/| |  | "$NORMAL"/ / "$JAUNE"|                                      
       	              "$NORMAL"/"$VERT"|  | |  | |_ /"$NORMAL"/ /"$JAUNE"|                                         
       	             "$NORMAL"/ "$VERT"|--| |  |    "$NORMAL"/ / "$JAUNE"|                                            
       	            "$NORMAL"/  "$VERT"|  |        "$NORMAL"/ /"$JAUNE"|
       	           "$NORMAL"/______________/ / "$JAUNE"|
       	          "$NORMAL" \\______________\\/"$JAUNE"|
       	            |               |

	"

		read
		clear
	;;
	'3') 	clear
		echo "


		"
		echo -e $BLEU"		# Utilisation globale du CPU et de la memoire"
		echo -e "		---------------------------------------------
		" $NORMAL	
		echo "  + Utilisation de la memoire a : $gmem % (aux arrondis prets)"
		echo "  + Memoire libre : "$MEMLIBRE"ko"
		echo "  + Utilisation du cpu a : $gcpu % (aux arrondis prets)"
		echo "
		"
	echo -e "$NORMAL" "         
           _______________________________
          [           "$ROSE" _                  "$NORMAL"]
          ["$ROSE"_         _| |_                "$NORMAL"]
          ["$ROSE" |_      | | | |  _            "$NORMAL"]
          ["$ROSE" | |    _| | | |_| |_         "$NORMAL" ]
          ["$ROSE" | |  _| | | | | | | |_   _   "$NORMAL" ]
          ["$ROSE" | |_| | | | | | | | | |_| |_  "$NORMAL"]
          ["$ROSE" | | | | | | | | | | | | | | | "$NORMAL"]
          ["$ROSE"_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|"$NORMAL"_]
	"

		read
		clear
	;;
	'4') 	clear
		echo "


		"
		echo -e $BLEU"		# Information systeme"
		echo -e "		---------------------
		" $NORMAL
		echo "  + Nom du systeme d'exploitation : `uname -s`"
		echo "  + Numero de version : `uname -r`"
		echo "  + Type de systeme d'exploitation : `uname -o`"
		echo "
		"
	 echo -e "$VERT" "  
         	      ______
	             |      |
	             |      |
	             |      |
	             |______|
	             |_"$ROUGE"[]"$VERT"___|    
	               "$NORMAL")  (
	              (    )
	           "$VERT"___"$NORMAL"/"$VERT"_  _"$NORMAL"\_"$VERT"__
	          |_"$ROUGE"[]"$VERT"__||_"$ROUGE"[]"$VERT"__|
	             
	"
		read
		clear
	;;
	'5') 	clear
		echo "


		"
		echo -e $BLEU"		# Partitionnement du disque dur"
		echo -e "		-------------------------------
		" $NORMAL
		echo "  + Il y a "$PARTITIONS_NB" partitions"
		echo "    "$PARTITIONS""
		echo "
		"
		read
		clear
	;;
	'6') 	clear
		echo "


		"
		echo -e $BLEU"		# Occupation des disques"
		echo -e "		------------------------
		" $NORMAL
		echo "`df -h`"
		echo "
		"
	 echo -e "$VERT" "  
	            _______________
	           |\\ "$BLEU"LINUX"$VERT"\\       \\
	           \\ \\______\\       \\
	            \\ \\ "$JAUNE"FREE "$VERT"\\ DOOM  "$VERT"\\
	             \\ \\______\\       \\   
	              \\ \\      \\_______\\
	               \\ \\ "$ROUGE"LEGO STARWARS"$VERT"\\
	                \\ \\______________\\       
	                 \\|_____"$ROUGE"[]"$VERT"________|             
	"
		read
		clear
	;;
	'7') 	clear
		echo "


		"
		echo -e $BLEU"		# Informations composants"
		echo -e "		-------------------------
		" $NORMAL
		echo "  +"$CARTEGRAPH""
		echo "  +"$DRIVERVID""
		echo "  + modele de la carte son : "$CARTESON""
		echo "  + drivers : "$DRIVERSON""
		echo "  + drivers des disques"
		echo "`cat /proc/ide/drivers`"
		echo "  + Nom u moniteur : "$MONITEUR""
		echo "
		"
	echo -e "$CYAN" "      
	                __________
	               |\\         \\                          
	               | \\         \\
	               |  \\         \\
	               |   \\         \\
	               |    \\_________\\               
	               |    |"$ROUGE" _______ "$CYAN"|
	               |    |"$ROUGE"[_______]"$CYAN"|
	               |    |  "$ROUGE"   ___ "$CYAN"|
	               \    |  "$ROUGE"  [___]"$CYAN"|
	                \   | "$BLEU"  _    "$CYAN" |
	                 \  | "$BLEU" (_)   "$CYAN" |
	                  \ |         |
	                   \|_________|            
	
	"
		read
		clear
	;;
	'8') 	clear
		echo "


		"
		echo -e $BLEU"		# Informations usb et peripheriques connectes"
		echo -e "		---------------------------------------------
		" $NORMAL
		echo "`lsusb` "
  	if [ "$?" -eq "0" ]; then
	echo "  + Nombre de port(s) USB :"
	lspci | grep "USB" | wc -l
	if [ `lspci | grep "Ethernet" | wc -l` -ne "0" ]; then
	    echo "  + Nom du(des) peripherique(s) Ethernet :"
	    	lspci | grep "Ethernet" | cut -d ":" -f 3
	fi
	if [ `lspci | grep "Network" | wc -l` -ne "0" ]; then
	    echo "  + Nom du(des) peripherique(s) Wifi :"
	    	lspci | grep "Network" | cut -d ":" -f 3
	fi
    fi
		echo "
		"
	echo -e "$NORMAL" "  
	            
	                      "$JAUNE" ____________	
	                      "$JAUNE"|            |
	            "$CYAN" _________"$JAUNE"|            |"$CYAN"_____
	            |\\        "$JAUNE"|            |"$CYAN"     \\ 
	            | \\______["$JAUNE"|"$CYAN"____________"$JAUNE"|"$CYAN"]_____\\
	            "$CYAN"| |       ______________      |
	            "$CYAN"| |      ["$JAUNE"|____________|"$CYAN"]     |
	           "$CYAN" \\ |  "$ROUGE"HP  "$CYAN"|______________|     |
	            "$CYAN" \\|______ \\\             \\_____|
	                       \\\_____________\\ 
	                       \\|_____________|    
	"
		read
		clear
	;;
	'9') 	clear
		echo "


		"
		echo -e $BLEU"		# Informations Utilisateur"
		echo -e "		--------------------------
		" $NORMAL
		echo "  + nom de l'utilisateur : `cat /etc/passwd | grep $USERNAME | cut -d ":" -f 5`" 
		echo "  + "$LOGNAME""
		echo "  + user ID : `id -u`"
		echo "  + groupe ID : `id -g`"
		echo "  + "$TYPEBUREAU""
		echo "  + `printenv | grep ^HOME | sed -e's/HOME=/repertoire personnel\ :\ /'`"
		echo "  + l'ordi est allume depuis `uptime | cut -b 15-20`"
		echo "
"
	 echo -e "$JAUNE" "  
	               ///////
	             "$ROSE" |      |
	             @| "$BLEU"a  a "$ROSE"|@
	              |  /   |
	              | "$ROUGE"\__/ "$ROSE"|
	              |_ -- _|
	           "$BLEU"_____"$ROUGE"|  |"$BLEU"_____
	          /      \/      \\
	         /  /|        |\  \             
		"
			read
		clear
	;;
        '10')    clear
                echo "


                "
                echo -e $BLEU"		# Informations Diverses"
                echo -e "		-----------------------
                " $NORMAL
                echo "  + Ce programme est ouvert depuis `echo $[$SECONDS/3600]h$[($SECONDS/60)%60]mn$[$SECONDS%60]s`"
                echo "  + il est `date | cut -d " " -f4`"
		echo "  + Nous sommes le `date +%A` `date +%d` `date +%B` `date +%y`"
                echo "  + Ce qui correspond au `date +%j`ème jour de l'année"
                read
                clear
        ;;
    '11')clear
	echo -e "$ROUGE" "  
	  
	                   ' ~ '              
	                  ~_\|/_~  
	                  ~ /|\ ~
	        "$JAUNE"   ' ~ ' "$ROUGE"  '~| ~'   
	         "$JAUNE"  ~_\|/_~   "$ROUGE"|             
	          "$JAUNE" ~ /|\ ~   "$ROUGE"|  "$BLEU" ' ~ '          
	          "$JAUNE"  ' ~ \    "$ROUGE"| "$BLEU" ~_\|/_~        
	               "$JAUNE"  \   "$ROUGE"|  "$BLEU" ~/|\ ~         
	                 "$JAUNE" \  "$ROUGE"|  "$BLEU" / ~ ' 
	                 "$JAUNE"  \ "$ROUGE"| "$BLEU" / 
	"
	echo -e "$NORMAL"
	echo ""
	echo -e $BLEU"			    # Credit"
	echo -e "			    --------
"$NORMAL
	echo "		   Ce script a ete ecrit par:"
	echo ""
	echo "			 Thibaut LUTZ"
	echo "  			      et"
	echo "			Romain LE JEUNE"
	echo ""
	echo " 		Etudiants en 1ere annee d Info (Groupe5)"
	echo "	 	         a l IUT d Aubiere"
	echo ""
	echo "      Nous remerciont nos parents, nos amis, la famille:"
	echo "pour leur comprehension et pour nous avoir soutenu et encourage"
	echo "             dans ce terrible periple qui fut le notre"
	echo ""
	read ; clear
	echo "" ;;


esac

if [ $choix -eq 12 ]; then
clear
echo "




"
echo -e "$JAUNE" "  
		               ///////
		             "$ROSE" |      |
		             @| "$BLEU"a  a "$ROSE"|@
		     ____     |  /   |
		    |||||| _  | "$ROUGE"\__/ "$ROSE"|
		    |    |//  |_ -- _|
		     \___/ "$BLEU"_____"$ROUGE"|  |"$BLEU"_____
		     |  | /      \/      \\
		     \  \/  /|        |\  \             
		      \____/ |        | \  \ 
"
echo -e "$NORMAL"
echo "

"
echo "			      A BIENTOT"  
sleep 2
fi
clear
done

done
