You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
196 lines
6.2 KiB
196 lines
6.2 KiB
#!/bin/bash
|
|
# Script d'évaluateur de la SAE 1.03
|
|
# Auteur: Rémi LAVERGNE
|
|
|
|
VERSION="v1.0.0"
|
|
SCRIPT_URL="https://codefirst.iut.uca.fr/git/remi.lavergne/sae103-evaluateur/raw/branch/master/scripts/evaluateur.sh"
|
|
|
|
# Vérification de version
|
|
check_version() {
|
|
echo "Vérification de la version du script..."
|
|
remote_version=$(curl -s "$SCRIPT_URL" | grep -E '^VERSION=' | cut -d'"' -f2)
|
|
if [ "$remote_version" != "$VERSION" ]; then
|
|
echo -e "\\e[33mUne nouvelle version du script est disponible : $remote_version\\e[0m"
|
|
read -p "Voulez-vous mettre à jour ? (o/n) : " response
|
|
if [[ "$response" =~ ^[Oo]$ ]]; then
|
|
update_script
|
|
fi
|
|
else
|
|
echo -e "\\e[32mVous utilisez la dernière version du script : $VERSION\\e[0m"
|
|
fi
|
|
}
|
|
|
|
# Mise à jour automatique du script
|
|
update_script() {
|
|
echo "Téléchargement de la dernière version depuis CodeFirst..."
|
|
curl -o "$0" "$SCRIPT_URL" && chmod +x "$0"
|
|
echo -e "\\e[32mMise à jour réussie. Relancez le script pour appliquer les modifications.\\e[0m"
|
|
exit 0
|
|
}
|
|
|
|
total_points=0
|
|
total_tests=0
|
|
|
|
print_status() {
|
|
total_tests=$((total_tests + 1))
|
|
if [ "$1" -eq 0 ]; then
|
|
total_points=$((total_points + 1))
|
|
echo -e "\\e[32mOK\\e[0m - $2"
|
|
else
|
|
echo -e "\\e[31mKO\\e[0m - $2"
|
|
fi
|
|
}
|
|
|
|
history -a # Pour sauvegarder l'historique des commandes dans le fichier ~/.bash_history
|
|
clear
|
|
|
|
check_version
|
|
|
|
echo -e "\\e[33mSi certains tests sont toujours en rouge, faites la commande 'history -a' puis relancez l'évaluateur.\\e[0m"
|
|
|
|
# ========================================
|
|
# Section 1
|
|
# ========================================
|
|
echo -e "\\e[1mSection 1: Installation des outils/paquets\\e[0m"
|
|
|
|
# Étape 1: Outils pour éditer une image vectorielle (Inkscape ou GIMP)
|
|
[ -x /usr/bin/inkscape ] || [ -x /usr/bin/gimp ]
|
|
print_status $? "Avoir (au moins) un outil pour éditer une image vectorielle."
|
|
|
|
# Étape 2: Outils pour compiler un programme C (gcc, g++, clang)
|
|
[ -x /usr/bin/gcc ] || [ -x /usr/bin/g++ ] || [ -x /usr/bin/clang ]
|
|
print_status $? "Avoir (au moins) un outil pour compiler un programme C."
|
|
|
|
# Étape 3: Navigateur web (Firefox ou Chromium)
|
|
[ -x /usr/bin/firefox-esr ] || [ -x /usr/bin/chromium ]
|
|
print_status $? "Avoir un navigateur web."
|
|
|
|
# Étape 4: Lister les paquets installés
|
|
grep -Fq 'apt list --installed' ~/.bash_history
|
|
print_status $? "Lister les paquets installés."
|
|
|
|
# Étape 5: Savoir supprimer un paquet
|
|
dpkg -s nano &> /dev/null
|
|
print_status $? "Supprimer le paquet 'nano', utiliser VIM."
|
|
|
|
# Etape 6: Mettre à jour les paquets disponibles
|
|
grep -Fq 'apt update' ~/.bash_history
|
|
print_status $? "Mettre à jour la liste des paquets disponibles."
|
|
|
|
# Etape 7: Mettre à jour les paquets installés
|
|
grep -Fq 'apt upgrade' ~/.bash_history
|
|
print_status $? "Mettre à jour les paquets installés."
|
|
|
|
|
|
|
|
|
|
# ========================================
|
|
# Section 2
|
|
# ========================================
|
|
echo -e "\\n\\e[1mSection 2: Utilisateurs et groupes\\e[0m"
|
|
|
|
# Étape 1: Créer un utilisateur
|
|
grep -q '^bob:' /etc/passwd
|
|
print_status $? "Créer l'utilisateur 'bob'."
|
|
|
|
# Étape 2: Modifier un mot de passe
|
|
grep -Fq 'passwd bob' ~/.bash_history
|
|
print_status $? "Modifier le mot de passe de l'utilisateur 'bob'."
|
|
|
|
# Étape 3: Créer un groupe
|
|
grep -q '^dev:' /etc/group
|
|
print_status $? "Créer le groupe 'dev'."
|
|
|
|
# Étape 4: Ajouter un utilisateur à un groupe
|
|
grep -q '^dev:' /etc/group && grep -q '^bob:.*dev' /etc/group
|
|
print_status $? "Ajouter l'utilisateur 'bob' au groupe 'dev'."
|
|
|
|
# Etape 5: Supprimer un utilisateur
|
|
grep -q '^john:' /etc/passwd
|
|
if [ $? -eq 0 ]; then
|
|
echo -e "\\e[31mKO\\e[0m - L'utilisateur 'john' existe encore, il doit être supprimé."
|
|
else
|
|
total_points=$((total_points + 1))
|
|
total_tests=$((total_tests + 1))
|
|
echo -e "\\e[32mOK\\e[0m - L'utilisateur 'john' a été supprimé."
|
|
fi
|
|
|
|
|
|
|
|
|
|
# ========================================
|
|
# Section 3
|
|
# ========================================
|
|
echo -e "\\n\\e[1mSection 3: Manipulation de fichiers\\e[0m"
|
|
|
|
# Etape 1: Afficher l'espacement disque disponible
|
|
grep -Fq 'df' ~/.bash_history
|
|
print_status $? "Afficher l'espace disque disponible."
|
|
|
|
|
|
|
|
|
|
# ========================================
|
|
# Section 4
|
|
# ========================================
|
|
echo -e "\\n\\e[1mSection 4: Partitions\\e[0m"
|
|
|
|
# Etape 1: Afficher les partitions sur le disque (option -l)
|
|
grep -Fq 'fdisk -l' ~/.bash_history
|
|
print_status $? "Afficher les partitions."
|
|
|
|
# Etape 2: Partitionner un disque pour créer une partition primaire
|
|
grep -Fq 'fdisk' ~/.bash_history
|
|
print_status $? "Partitionner un disque (partition primaire)."
|
|
|
|
# Etape 3: Créer un système de fichier
|
|
grep -Fq 'mkfs' ~/.bash_history
|
|
print_status $? "Créer un système de fichier dans une partition."
|
|
|
|
# Etape 4: Créer une partition SWAP
|
|
grep -Fq 'mkswap' ~/.bash_history
|
|
print_status $? "Créer une partition d'échange (SWAP)."
|
|
|
|
|
|
|
|
|
|
# ========================================
|
|
# Section 5
|
|
# ========================================
|
|
echo -e "\\n\\e[1mSection 5: Clé USB & périphériques\\e[0m"
|
|
|
|
# Etape 1: Lister le matériel présent sur la machine (lspci ou lshw)
|
|
grep -Fq 'lspci' ~/.bash_history || grep -Fq 'lshw' ~/.bash_history
|
|
print_status $? "Lister le matériel présent sur la machine."
|
|
|
|
# Etape 2: Savoir identifier sur quels bus ils sont connectés (lspci -b)
|
|
grep -Fq 'lsusb' ~/.bash_history
|
|
print_status $? "Lister les bus connectés pour le matériel."
|
|
|
|
# Etape 3: Vérifier quel module gère un périphérique (lspci -nnv)
|
|
grep -Fq 'lspci -nnv' ~/.bash_history
|
|
print_status $? "Vérifier quel module gère un périphérique."
|
|
|
|
# Etape 4: Lister les modules chargés
|
|
grep -Fq 'lsmod' ~/.bash_history
|
|
print_status $? "Lister les modules chargés en mémoire."
|
|
|
|
|
|
|
|
|
|
# ========================================
|
|
# Affichage des résultats finaux
|
|
# ========================================
|
|
echo -e "\\n========================================"
|
|
echo -e "\\e[1mRÉSULTATS FINAUX\\e[0m"
|
|
echo -e "========================================"
|
|
echo -e "Tests réussis : $total_points / $total_tests"
|
|
|
|
note=$((total_points * 20 * 100 / total_tests))
|
|
integer_part=$((note / 100))
|
|
decimal_part=$((note % 100))
|
|
|
|
formatted_note="${integer_part}.$(printf "%02d" $decimal_part)"
|
|
|
|
echo -e "\\e[1mNote finale : $formatted_note / 20\\e[0m"
|