Rename $k to $device
This commit is contained in:
parent
4a46f213b1
commit
caa057fdb8
36
fullusb.sh
36
fullusb.sh
|
@ -1,7 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# script to copy data on usb keys
|
# Script to copy data on usb keys
|
||||||
|
|
||||||
# dependances : aptitude install ncurses-bin parted dosfstools (mlabel devenu inutile)
|
# dependencies : aptitude install ncurses-bin parted dosfstools
|
||||||
|
# mlabel is now useless
|
||||||
|
|
||||||
# text color in bash
|
# text color in bash
|
||||||
normal=$(tput sgr0)
|
normal=$(tput sgr0)
|
||||||
|
@ -11,12 +12,11 @@ green=$(tput setaf 2)
|
||||||
# dependencies check
|
# dependencies check
|
||||||
i=0
|
i=0
|
||||||
for arg in "tput" "parted" "mkdosfs"; do
|
for arg in "tput" "parted" "mkdosfs"; do
|
||||||
|
hash "${arg}"
|
||||||
hash "${arg}"
|
if [[ $? -gt 0 ]]; then
|
||||||
if [[ $? -gt 0 ]]; then
|
|
||||||
printf "%40s\n" "${red}Error: Could not find \"$arg\" application.${normal}";
|
printf "%40s\n" "${red}Error: Could not find \"$arg\" application.${normal}";
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
[[ $i -eq 0 ]] || exit $i
|
[[ $i -eq 0 ]] || exit $i
|
||||||
|
|
||||||
|
@ -54,29 +54,29 @@ case $keysearchid in
|
||||||
# if $keysearchid=1: for i in 1
|
# if $keysearchid=1: for i in 1
|
||||||
# if $keysearchid=2: for i in 1 2
|
# if $keysearchid=2: for i in 1 2
|
||||||
do
|
do
|
||||||
[[ $i == 1 ]] && k="sdb" || k="sdc" # if 3 or more keys this line has to be adapt
|
[[ $i == 1 ]] && device="sdb" || device="sdc" # if 3 or more keys this line has to be adapt
|
||||||
parted -s /dev/$k mklabel msdos
|
parted -s /dev/"${device}" mklabel msdos
|
||||||
parted /dev/$k mkpart -a optimal primary fat32 0% 100%
|
parted /dev/"${device}" mkpart -a optimal primary fat32 0% 100%
|
||||||
mkdosfs -F 32 -I -n $keylabel /dev/${k}1
|
mkdosfs -F 32 -I -n $keylabel /dev/"${device}"1
|
||||||
# fatlabel /dev/${k}1 $keylabel # Cette commande est remplacée par l’option -n de la commande précédente
|
# fatlabel /dev/${device}1 $keylabel # Cette commande est remplacée par l’option -n de la commande précédente
|
||||||
mkdir "${mountpath}"$k
|
mkdir "${mountpath}""${device}"
|
||||||
mount /dev/${k}1 "${mountpath}"$k
|
mount /dev/"${device}"1 "${mountpath}""${device}"
|
||||||
cp -r $wherethefilesare/* "${mountpath}"$k/
|
cp -r $wherethefilesare/* "${mountpath}""${device}"/
|
||||||
sync
|
sync
|
||||||
# Generate the md5sum for the mountpoint
|
# Generate the md5sum for the mountpoint
|
||||||
pushd "${mountpath}""${k}"
|
pushd "${mountpath}""${device}"
|
||||||
find . -type f -exec md5sum {} \; | sort > "${destmd5}"
|
find . -type f -exec md5sum {} \; | sort > "${destmd5}"
|
||||||
popd
|
popd
|
||||||
# Umount the key
|
# Umount the key
|
||||||
umount "${mountpath}"$k
|
umount "${mountpath}""${device}"
|
||||||
rmdir "${mountpath}"$k
|
rmdir "${mountpath}""${device}"
|
||||||
# Compare the md5sum
|
# Compare the md5sum
|
||||||
diff -q "${sourcemd5}" "${destmd5}"
|
diff -q "${sourcemd5}" "${destmd5}"
|
||||||
if [[ $? -gt 0 ]]; then
|
if [[ $? -gt 0 ]]; then
|
||||||
printf "%40s\n" "${red}Error: MD5 diff detected.${normal}";
|
printf "%40s\n" "${red}Error: MD5 diff detected.${normal}";
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
printf "%40s\n" "${green}MD5 check OK for ${k}.${normal}"
|
printf "%40s\n" "${green}MD5 check OK for ${device}.${normal}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
printf "%40s\n" "${green}DONE${normal}"
|
printf "%40s\n" "${green}DONE${normal}"
|
||||||
|
|
Loading…
Reference in New Issue