29 lines
605 B
Bash
29 lines
605 B
Bash
|
#!/bin/bash
|
||
|
|
||
|
# Vérifie si le bon nombre d'arguments est fourni
|
||
|
if [ "$#" -ne 2 ]; then
|
||
|
echo "Usage: $0 <expected_hash> <file_path>"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
expected_hash=$1
|
||
|
file_path=$2
|
||
|
|
||
|
# Vérifie si le fichier existe
|
||
|
if [ ! -f "$file_path" ]; then
|
||
|
echo "Error: File $file_path does not exist."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# Calculer le hash SHA-256 du fichier et le comparer avec le hash attendu
|
||
|
echo "$expected_hash $file_path" | sha256sum -c - > /dev/null 2>&1
|
||
|
|
||
|
# Vérifier le code de sortie de sha256sum
|
||
|
if [ $? -eq 0 ]; then
|
||
|
echo "Hash match: OK"
|
||
|
exit 0
|
||
|
else
|
||
|
echo "Hash match: FAILED"
|
||
|
exit 1
|
||
|
fi
|