See the Security and Bug Fixes Section - Grub EFI Install Updates Fix Sticky


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A simple way to check MD5sum
#27
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..

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
Reply


Messages In This Thread
A simple way to check MD5sum - by misko_2083 - 08-20-2014, 12:59 AM
Re: A simple way to check MD5sum - by Valtam - 08-20-2014, 01:07 AM
Re: A simple way to check MD5sum - by rokytnji - 08-20-2014, 02:30 AM
Re: A simple way to check MD5sum - by misko_2083 - 08-20-2014, 09:11 AM
Re: A simple way to check MD5sum - by misko_2083 - 10-10-2014, 01:42 PM
Re: A simple way to check MD5sum - by rokytnji - 10-10-2014, 02:54 PM
Re: A simple way to check MD5sum - by misko_2083 - 10-10-2014, 03:36 PM
Re: A simple way to check MD5sum - by rokytnji - 10-10-2014, 05:00 PM
Re: A simple way to check MD5sum - by misko_2083 - 10-11-2014, 05:19 PM
Re: A simple way to check MD5sum - by rokytnji - 10-11-2014, 05:39 PM
Re: A simple way to check MD5sum - by mlsmith - 12-06-2014, 03:25 AM
Re: A simple way to check MD5sum - by misko_2083 - 12-06-2014, 06:25 AM
Re: A simple way to check MD5sum - by mlsmith - 12-06-2014, 03:38 PM
Re: A simple way to check MD5sum - by misko_2083 - 12-07-2014, 02:13 AM
Re: A simple way to check MD5sum - by misko_2083 - 12-07-2014, 09:33 AM
Re: A simple way to check MD5sum - by mlsmith - 12-07-2014, 01:17 PM
Re: A simple way to check MD5sum - by misko_2083 - 12-07-2014, 02:07 PM
Re: A simple way to check MD5sum - by gold_finger - 12-07-2014, 05:04 PM
Re: A simple way to check MD5sum - by mlsmith - 12-07-2014, 09:14 PM
Re: A simple way to check MD5sum - by misko_2083 - 12-09-2014, 03:02 AM
Re: A simple way to check MD5sum - by bitsnpcs - 01-14-2017, 05:56 PM
Re: A simple way to check MD5sum - by firenice03 - 01-14-2017, 07:27 PM
Re: A simple way to check MD5sum - by bitsnpcs - 01-14-2017, 11:51 PM
Re: A simple way to check MD5sum - by ralphy - 04-03-2017, 02:49 PM
Re: A simple way to check MD5sum - by Vera - 05-31-2017, 11:26 AM
Re: A simple way to check MD5sum - by ralphy - 05-31-2017, 01:53 PM
Re: A simple way to check MD5sum - by tuto - 09-06-2018, 12:40 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)