134 lines
3.3 KiB
Bash
Executable File
134 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
DIR=/opt/grabber/
|
|
SUCCESS_LOG=/var/log/grabber/grabber-success.log
|
|
ERROR_LOG=/var/log/grabber/grabber-error.log
|
|
SUM="$DIR/summary.txt"
|
|
|
|
|
|
#lspci -nn > $DIR/lspci.cmd
|
|
#lsusb > $DIR/lsusb.cmd
|
|
#apt list --installed > $DIR/apt.cmd
|
|
#systemd-analyze > $DIR/systemd-analyze.cmd
|
|
#systemd-analyze blame | head -n 10 > $DIR/systemd-blame.cmd
|
|
#lscpu > $DIR/lscpu.cmd
|
|
#lshw-gtk > $DIR/lshw-gtk.cmd
|
|
#inxi > $DIR/inxi.cmd
|
|
#lsmem > $DIR/lsmem.cmd
|
|
|
|
|
|
# Affichage du texte de démarrage
|
|
|
|
echo " ++++++++++++++++++++++++++++++++++"
|
|
echo " + Welcome to Grabber +"
|
|
echo " ++++++++++++++++++++++++++++++++++"
|
|
echo " "
|
|
echo "Hello $USER !"
|
|
echo ". . ."
|
|
echo "Tout les fichiers crées se trouveront dans le dossier /opt/grabber ;)"
|
|
echo " "
|
|
|
|
#Array File
|
|
declare -a DEVICES
|
|
mapfile -t DEVICES < <(lsblk -dn -o NAME |grep -v loop)
|
|
|
|
declare -A FILES
|
|
FILES=(
|
|
"sources_list.file" "/etc/apt/sources.list"
|
|
"passwd.file" "/etc/passwd"
|
|
"group.file" "/etc/group"
|
|
"ssh_config.file" "/etc/ssh/ssh_config"
|
|
)
|
|
|
|
declare -A COMMANDES
|
|
COMMANDES=(
|
|
[lspci.cmd]="lspci -nn"
|
|
[lsusb.cmd]="lsusb"
|
|
[apt.cmd]="apt list --installed"
|
|
[systemd-analyze.cmd]="systemd-analyze"
|
|
[systemd-blame.cmd]="systemd-analyze blame | head -n 10"
|
|
[lscpu.cmd]="lscpu"
|
|
[inxi.cmd]="inxi"
|
|
[lsmem.cmd]="lsmem"
|
|
)
|
|
|
|
treat_cmd() {
|
|
echo "Création fichier: $@"
|
|
$2 >$DIR/$1
|
|
if [ $? -eq 0 ]; then
|
|
echo "[OK]: Fichier $1 généré" > $SUCCESS_LOG
|
|
else
|
|
echo "[ECHEC]: Erreur à la génération de $1 => Code de sortie $?" > $ERROR_LOG
|
|
fi
|
|
}
|
|
|
|
|
|
treat_file() {
|
|
echo "Copie de fichier: $@"
|
|
cat $2 |grep -v '^#' |grep -v '^$' >$DIR/$1
|
|
if [ $? -eq 0 ]; then
|
|
echo "[OK]: Fichier $1 généré" >> $SUCCESS_LOG
|
|
else
|
|
echo "[ECHEC]: Erreur à la génération de $1 => Code de sortie $?" >> $ERROR_LOG
|
|
fi
|
|
}
|
|
|
|
for cmd in "${!COMMANDES[@]}"; do
|
|
treat_cmd $cmd "${COMMANDES[$cmd]}"
|
|
done
|
|
|
|
for file in "${!FILES[@]}"; do
|
|
treat_file $file "${FILES[$file]}"
|
|
done
|
|
|
|
|
|
declare -A PARTITIONS_BY_DISK
|
|
for disk in ${DEVICES[@]}; do
|
|
disk_path=$(printf '/dev/%s' "$disk")
|
|
disk_parts=$(lsblk -nr -o PKNAME,PATH $disk_path |grep -vE "^ " |cut -d \ -f2)
|
|
PARTITIONS_BY_DISK[$disk]=${disk_parts[@]}
|
|
done
|
|
|
|
echo " "
|
|
echo "Combien de disques sur l'ordinateur ? ${#DEVICES[@]}"
|
|
echo "keys: ${!PARTITIONS_BY_DISK[@]}"
|
|
echo "values: ${PARTITIONS_BY_DISK[@]}"
|
|
|
|
|
|
|
|
hardware() {
|
|
echo " "
|
|
echo "[HARDWARE]"
|
|
echo "CPU=$(lscpu -eMODELNAME |tail -n1)"
|
|
echo "CPU_ID=$(sudo dmidecode -t processor |grep ID |cut -d: -f2)"
|
|
RAM_SIZE=$(lsmem |grep "Mémoire partagée" |cut -d: -f2 |sed 's/\ //g')
|
|
RAM_GEN=$(sudo dmidecode -t memory |grep Type: |grep -v Unknown |tail -n1 |cut -d: -f2 |sed 's/\ //')
|
|
echo "RAM=$RAM_SIZE $RAM_GEN"
|
|
echo "RAM_SIZE=$RAM_SIZE"
|
|
echo "RAM_GEN=$RAM_GEN"
|
|
|
|
sizes=$(lsblk -dnb |grep -v loop |grep -v boot |tr -s " " |cut -d \ -f4)
|
|
STOCKAGE_TOTAL=0
|
|
for SIZE in ${sizes[@]};do
|
|
STOCKAGE_TOTAL+=$SIZE
|
|
done
|
|
STOCKAGE_TOTAL=$(numfmt --to iec $STOCKAGE_TOTAL)
|
|
echo "STOCKAGE_TOTAL=$STOCKAGE_TOTAL"
|
|
} >$SUM
|
|
|
|
|
|
software() {
|
|
echo " "
|
|
echo "[SOFTWARE]"
|
|
echo "OS=$(lsb_release -a |grep Description |cut -f2)"
|
|
echo "ARCH=$(uname -m)"
|
|
echo "DESKTOP=$XDG_CURRENT_DESKTOP"
|
|
echo "WM=$XDG_SESSION_TYPE"
|
|
echo "KERNEL=$(uname -r)"
|
|
} >>$SUM
|
|
|
|
hardware
|
|
software
|
|
echo " "
|
|
echo "Le fichier summary.txt contient les infos hardware et software du système"
|
|
echo "À bientôt ;)"
|