Add md5 checksum to ensure all files are OK
This commit is contained in:
parent
fec7c872d9
commit
4a46f213b1
38
fullusb.sh
38
fullusb.sh
|
@ -21,8 +21,8 @@ done
|
|||
[[ $i -eq 0 ]] || exit $i
|
||||
|
||||
# this part depends of the event
|
||||
keylabel="OPTIQUE2015" # label of the keys
|
||||
wherethefilesare="/homes/carre/optique2015" # where are the files you need to copy
|
||||
keylabel="CHOCOLAS" # label of the keys
|
||||
wherethefilesare="/ipr/home.ipr/jegardai/chocolas" # where are the files you need to copy
|
||||
badkeyid="abcd" # depends of key models (lsusb)
|
||||
goodkeyid="058f"
|
||||
|
||||
|
@ -30,6 +30,11 @@ goodkeyid="058f"
|
|||
keysearchbadid=$(lsusb | grep $badkeyid | wc -l)
|
||||
keysearchgoodid=$(lsusb | grep $goodkeyid | wc -l)
|
||||
keysearchid=$(($keysearchbadid+$keysearchgoodid))
|
||||
mountpath="/mnt/usbkey"
|
||||
|
||||
# MD5SUM check
|
||||
sourcemd5="/tmp/source_directory.md5"
|
||||
destmd5="/tmp/destination_directory.md5"
|
||||
|
||||
case $keysearchid in
|
||||
0) printf "%40s\n" "${red}Alert: No usb key detected${normal}" ;;
|
||||
|
@ -40,6 +45,11 @@ case $keysearchid in
|
|||
if [[ $keysearchid != $nbsd ]]; then
|
||||
printf "%40s\n" "${red}Alert: Error 1${normal} Keysearchid: ${keysearchid}"
|
||||
else # if everything is ok
|
||||
# Generate the md5sum for source directory
|
||||
pushd "${wherethefilesare}"
|
||||
find . -type f -exec md5sum {} \; | sort > "${sourcemd5}"
|
||||
popd
|
||||
|
||||
for i in $(seq 1 $keysearchid) # from 1 to $keysearchid by step of 1
|
||||
# if $keysearchid=1: for i in 1
|
||||
# if $keysearchid=2: for i in 1 2
|
||||
|
@ -49,15 +59,29 @@ case $keysearchid in
|
|||
parted /dev/$k mkpart -a optimal primary fat32 0% 100%
|
||||
mkdosfs -F 32 -I -n $keylabel /dev/${k}1
|
||||
# fatlabel /dev/${k}1 $keylabel # Cette commande est remplacée par l’option -n de la commande précédente
|
||||
mkdir /mnt/usbkey$k
|
||||
mount /dev/${k}1 /mnt/usbkey$k
|
||||
cp -r $wherethefilesare/* /mnt/usbkey$k/
|
||||
mkdir "${mountpath}"$k
|
||||
mount /dev/${k}1 "${mountpath}"$k
|
||||
cp -r $wherethefilesare/* "${mountpath}"$k/
|
||||
sync
|
||||
umount /mnt/usbkey$k
|
||||
rmdir /mnt/usbkey$k
|
||||
# Generate the md5sum for the mountpoint
|
||||
pushd "${mountpath}""${k}"
|
||||
find . -type f -exec md5sum {} \; | sort > "${destmd5}"
|
||||
popd
|
||||
# Umount the key
|
||||
umount "${mountpath}"$k
|
||||
rmdir "${mountpath}"$k
|
||||
# Compare the md5sum
|
||||
diff -q "${sourcemd5}" "${destmd5}"
|
||||
if [[ $? -gt 0 ]]; then
|
||||
printf "%40s\n" "${red}Error: MD5 diff detected.${normal}";
|
||||
exit 1
|
||||
else
|
||||
printf "%40s\n" "${green}MD5 check OK for ${k}.${normal}"
|
||||
fi
|
||||
done
|
||||
printf "%40s\n" "${green}DONE${normal}"
|
||||
fi ;;
|
||||
*) printf "%40s\n" "${red}Alert: Error 2${normal}" ;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
|
|
Loading…
Reference in New Issue