Hi, community.
[member=378]misko_2083[/member] and [member=6629]ralphy[/member], this is great script. Thank you.
I do known not much about shell scripting, but I modify this checksum script for hash check, such as in gtkhash application.
Any improvement is welcome.
I am sorry by bad English language use; I am learning, yet..
[member=378]misko_2083[/member] and [member=6629]ralphy[/member], this is great script. Thank you.
I do known not much about shell scripting, but I modify this checksum script for hash check, such as in gtkhash application.
Any improvement is welcome.
I am sorry by bad English language use; I am learning, yet..
Code:
#!/bin/bash
# Autors: Misko_2083, Ralphy
# Tomado desde: https://www.linuxliteos.com/forums/tutorials/a-simple-way-to-check-md5sum/15/
# Adapted by : tuto
#
# #####################################################################
# Images
ic="/usr/share/icons/Faenza/actions/32/system-run.png"
# ### User selected file.
file="$@"
if [ -z "$@" ]; then
szPath=$(zenity --file-selection --title="Checksum - Select file..." --file-filter='Image files (ISO,IMG) | *.iso *.ISO *.img *.IMG' --file-filter='All files | *')
if [ "$?" -eq "1" ]; then
exit 0
else
file="$szPath"
fi
fi
while (true); do
MD5=(`echo "" | awk '{print "md5sum","✍","MD5", $0}'`)
SHA1=(`echo "" | awk '{print "sha1sum","✍","SHA-1", $0}'`)
SHA224=(`echo "" | awk '{print "sha224sum","✍","SHA-224", $0}'`)
SHA256=(`echo "" | awk '{print "sha256sum","✍","SHA-256", $0}'`)
SHA384=(`echo "" | awk '{print "sha384sum","✍","SHA-384", $0}'`)
SHA512=(`echo "" | awk '{print "sha512sum","✍","SHA-512", $0}'`)
# ### Main dialog.
selected=$(zenity --list --width=180 --height="248" --window-icon="$ic" --hide-header --title=" Checksum" \
--text="File: <b>${file##*/}</b>\n\nSelect the Hash algorithm\n" --hide-column="1" --separator="," \
--print-column="1,3" \
--column="Checksum" \
--column="" \
--column="Hash" "${MD5[@]}" "${SHA1[@]}" "${SHA224[@]}" "${SHA256[@]}" "${SHA384[@]}" "${SHA512[@]}")
# ### If quit is clicked then exit.
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
exit 0
fi
# ### Read selection and split it.
checksum=$(awk -F, '{print $1}' <<<$selected)
dialog=$(awk -F, '{print $2}' <<<$selected)
if [ "$checksum" == "" ]; then
zenity --warning --window-icon="warning" --text="\nNo Hash algorithm was selected. Please, try again. " --timeout="3"; continue
else
:
fi
# ### Temp sum file.
TMPF="/tmp/sum"
# ### Common function - If cancel then remove $TMPF and exit.
action_cancel() { if [ "${PIPESTATUS[2]}" -ne "0" ]; then
rm $TMPF; exit 0
fi
}
action_sum() { sum=`cat $TMPF`; zenity --info --title="$dialog" --text="\nFile:<b> ${file##*/} </b>\n\n$dialog: $sum" --ok-label="Ok"; rm -f $TMPF
}
action_compare() { zenity --question --window-icon="$ic" --title="Hash Check" --text="You want verify the calculated hash?" --cancel-label="No" --ok-label="Yes"
if [ "$?" != "0" ]; then
exit 0
else
ctrlsum=`zenity --entry --window-icon="$ic" --title="Hash Check" --text="Enter a control sum value" --cancel-label="Close" --ok-label="Ok"`;
if [ "$ctrlsum" != "" ] && [ "$ctrlsum" == "$sum" ]; then
zenity --info --window-icon="$ic" --title="Hash Check" --text="<b>Checksum</b> is correct.\nThe file is complete."
elif [ "$ctrlsum" != "" ] && [ "$ctrlsum" != "$sum" ]; then
zenity --error --title="Hash Check" --text="<b>Checksum no match</b>.\nThe file is incomplete or corrupt."; continue
else
exit 0
fi
exit 0
fi
}
"$checksum" "$file" | tee >(cut -d ' ' -f1 > $TMPF) | zenity --window-icon="info" --progress --title="$dialog" --text="File:\n<b> ${file##*/} </b>\n\n- Calculating $dialog. Please, wait..." --pulsate --auto-close
action_cancel
action_sum
action_compare
done
exit