You are Here:
Linux Lite 6.6 FINAL Released - Support for 22 Languages Added - See Release Announcement Section



A simple way to check MD5sum

Author (Read 33663 times)

0 Members and 3 Guests are viewing this topic.

Re: A simple way to check MD5sum
« Reply #27 on: September 05, 2018, 08:40:49 PM »
 

tuto

  • New to Forums
  • *
  • 5
    Posts
  • Reputation: 0
  • Linux Lite Member
    • View Profile

  • CPU: Dual Core Intel(R) Celeron(R) CPU 847 @ 1.10GHz

  • MEMORY: 2Gb

  • VIDEO CARD: Intel 2nd Generation Core Processor Family Integrated Graphics Controller
Hi, community.

@misko_2083 and @ralphy,  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: [Select]
#!/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
« Last Edit: September 05, 2018, 08:55:41 PM by tuto »
 

Re: A simple way to check MD5sum
« Reply #26 on: May 31, 2017, 09:53:36 AM »
 

ralphy

  • PayPal Supporter
  • Gold Level Poster
  • *****
  • 741
    Posts
  • Reputation: 117
  • Linux Lite Developer
    • View Profile
@Vera


A month ago I switched the script to yad. I will add it to my repo so it can be easily installed. It creates the Thunar contextual menu option on install too and adds an option to copy the final sum to clipboard.


« Last Edit: May 31, 2017, 10:15:18 AM by ralphy »
https://unlockforus.com

Sorry for seeming stupid and preferring Linux - I just don't know any better.

 

Re: A simple way to check MD5sum
« Reply #25 on: May 31, 2017, 07:26:55 AM »
 

Vera

  • PayPal Supporter
  • Forum Regular
  • *****
  • 140
    Posts
  • Reputation: 16
  • Enjoying Linux Lite.
    • View Profile

  • CPU: Intel Quad Core 1.6GHz

  • MEMORY: 8Gb

  • VIDEO CARD: AMD Radeon
That's an exciting way of adding it to a GUI through Thunar.

On LinuxLite, when I've needed to check MD5 (or other hash sums) I've just gone for a simple approach and used the command line with the built-in md5sum function (or sha1sum or sha256sum depending what function I want to use). It has worked well for me when checking copied or downloaded ISO's against original. I haven't used it for anything more advanced than that though.

I do like the addition to Thunar that you mentioned since it would allow the function to always just "be there" as an option for doing checksum of any file via GUI, which definitely is helpful. Thanks for the tutorial.
Using Linux Lite for everything now. I put it on my desktop and my laptop. Woohoo!
 

Re: A simple way to check MD5sum
« Reply #24 on: April 03, 2017, 10:49:42 AM »
 

ralphy

  • PayPal Supporter
  • Gold Level Poster
  • *****
  • 741
    Posts
  • Reputation: 117
  • Linux Lite Developer
    • View Profile

Name: Checksum
Description: Calculates  checksum.
Command: /usr/scripts/checksum %f
Pattern: *
Appearance: Check all the boxes except Directories

save the script as checksum
make executable
copy the file to /usr/scripts

I find the script rather useful. I've modified it to allow users to select a file just by launching the script. If the custom action in Thunar is configured, it will allow users to right-click and select files without prompting to browse for the file.

Extract and move the extracted files to their respective locations.

/usr/scripts/checksum
/usr/share/applications/checksum.desktop

Here is what it looks like:











Cheers!


Code: [Select]
#!/bin/bash
# Misko_2083, Ralphy
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"; rm -f $TMPF & exit 0; }
"$checksum" "$file" | tee >(cut -d ' ' -f1 > $TMPF) |zenity --window-icon="info" --width=240 --progress --title="$dialog" --text="File:<b> ${file##*/} </b>\n\n- Calculating $dialog. Please wait..." --pulsate --auto-close
action_cancel
action_sum
done
exit
« Last Edit: April 03, 2017, 11:50:07 AM by ralphy »
https://unlockforus.com

Sorry for seeming stupid and preferring Linux - I just don't know any better.

 

Re: A simple way to check MD5sum
« Reply #23 on: January 14, 2017, 06:51:50 PM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3237
    Posts
  • Reputation: 305
    • View Profile
    • Try to Grow

  • Kernel: 4.x
Appreciate the help. Unsure why is not default on Windows 10 for me. So I had used the tool.





 

Re: A simple way to check MD5sum
« Reply #22 on: January 14, 2017, 02:27:39 PM »
 

firenice03

  • Rockin' the FREE World
  • Global Moderator
  • Platinum Level Poster
  • *****
  • 1848
    Posts
  • Reputation: 284
  • Linux Lite Member
    • View Profile

  • CPU: AMD E2//Atom X5//AMD Phenom II X2

  • MEMORY: 4Gb

  • VIDEO CARD: AMD Mullin Radeon R2//Intel//AMD/ATI RS880

  • Kernel: 5.x
If Vista and newer - Powershell should be installed by default, you can run the below command to check the MD5 checksum.. May alleviate the need to download a tool so you can dive right into a LL install  8) LOL

Its in tutorials as well: https://www.linuxliteos.com/forums/tutorials/md5-checksum-for-windows/msg22470/#msg22470

Command to paste into Powershell:
Code: [Select]
if ( $($(CertUtil -hashfile C:PATH_to_FILE\File_name.iso MD5)[1] -replace " ","") -eq "PASTE_HASH_between_quotes" ) { echo "ok" }
C:PATH_to_FILE\File_name.iso -- The full path and the .iso file
"PASTE_HASH_between_quotes" -- Paste the supplied hash

If the hash checks out it returns an ok.. If not it will be blank...
LL4.8 UEFI 64 bit ASUS E402W - AMD E2 (Quad) 1.5Ghz  - 4GB - AMD Mullins Radeon R2
LL5.8 UEFI 64 bit Test UEFI Kangaroo (Mobile Desktop) - Atom X5-Z8500 1.44Ghz - 2GB - Intel HD Graphics
LL4.8 64 bit HP 6005- AMD Phenom II X2 - 8GB - AMD/ATI RS880 (HD4200)
LL3.8 32 bit Dell Inspiron Mini - Atom N270 1.6Ghz - 1GB - Intel Mobile 945GSE Express  -- Shelved
BACK LL5.8 64 bit Dell Optiplex 160 (Thin) - Atom 230 1.6Ghz - 4GB-SiS 771/671 PCIE VGA - Print Server
Running Linux Lite since LL2.2
 

Re: A simple way to check MD5sum
« Reply #21 on: January 14, 2017, 12:56:18 PM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3237
    Posts
  • Reputation: 305
    • View Profile
    • Try to Grow

  • Kernel: 4.x
When changing from Windows to Linux Lite, you can in Windows use, WinMD5 free, to verify the download.
 

Re: A simple way to check MD5sum
« Reply #20 on: December 08, 2014, 10:02:32 PM »
 

anon222

  • Muted
  • Gold Level Poster
  • *
  • 688
    Posts
  • Reputation: 192
  • Linux Lite Member
    • View Profile

  • CPU: Dual core Pentium E5700 3GHz

  • MEMORY: 3Gb

  • VIDEO CARD: GeForce GT 430
Wow!  Excellent job misko_2083!

Just loaded it on my LL 2.0 desktop -- works great.
Thanks. It was mlsmith's idea to merge the scripts.
I think I need a sub menu in my right-click menu for all of misko's and Jerry's scripts.  ;)
Or, you could modify my script and add all of right-click menu items in a list. ;)
 

Re: A simple way to check MD5sum
« Reply #19 on: December 07, 2014, 04:14:31 PM »
 

Mike

  • Forum Regular
  • ***
  • 212
    Posts
  • Reputation: 26
  • Linux Lite Enthusiast
    • View Profile
I think I need a sub menu in my right-click menu for all of misko's and Jerry's scripts.  ;)
 

Re: A simple way to check MD5sum
« Reply #18 on: December 07, 2014, 12:04:30 PM »
 

gold_finger

  • Documentation Writer
  • Platinum Level Poster
  • *****
  • 1094
    Posts
  • Reputation: 325
  • Linux Lite Member
    • View Profile

  • CPU: Intel Core2 Duo E7500 3.0GHz

  • MEMORY: 4Gb

  • VIDEO CARD: Intel 4 Series Integrated Graphics
Wow!  Excellent job misko_2083!

Just loaded it on my LL 2.0 desktop -- works great.
Try Linux Beginner Search Engine for answers to Linux questions.
 

Re: A simple way to check MD5sum
« Reply #17 on: December 07, 2014, 09:07:14 AM »
 

anon222

  • Muted
  • Gold Level Poster
  • *
  • 688
    Posts
  • Reputation: 192
  • Linux Lite Member
    • View Profile

  • CPU: Dual core Pentium E5700 3GHz

  • MEMORY: 3Gb

  • VIDEO CARD: GeForce GT 430
You're welcome so much. :)
 

Re: A simple way to check MD5sum
« Reply #16 on: December 07, 2014, 08:17:30 AM »
 

Mike

  • Forum Regular
  • ***
  • 212
    Posts
  • Reputation: 26
  • Linux Lite Enthusiast
    • View Profile
Outstanding! Thanks so much misko.
 

Re: A simple way to check MD5sum
« Reply #15 on: December 07, 2014, 04:33:53 AM »
 

anon222

  • Muted
  • Gold Level Poster
  • *
  • 688
    Posts
  • Reputation: 192
  • Linux Lite Member
    • View Profile

  • CPU: Dual core Pentium E5700 3GHz

  • MEMORY: 3Gb

  • VIDEO CARD: GeForce GT 430
Here it is:


Name: Checksum
Description: Calculates  checksum.
Command: /usr/scripts/checksum %f
Pattern: *
Appearance: Check all the boxes except Directories

save the script as checksum
make executable
copy the file to /usr/scripts

Code: [Select]
#!/bin/bash
# Misko_2083

file="$@"

MD5=(`echo "" | awk '{print "TRUE","MD5", $0}'`)
SHA1=(`echo "" | awk '{print "FALSE","SHA-1", $0}'`)
SHA224=(`echo "" | awk '{print "FALSE","SHA-224", $0}'`)
SHA256=(`echo "" | awk '{print "FALSE","SHA-256", $0}'`)
SHA384=(`echo "" | awk '{print "FALSE","SHA-384", $0}'`)
SHA512=(`echo "" | awk '{print "FALSE","SHA-512", $0}'`)

selection=$(zenity --list --radiolist --height=300 --title="Checksum" --text="File:  <b>${file##*/}</b>\nPick the hash algorithm." --column="Pick" --column="Hash" "${MD5[@]}" "${SHA1[@]}" "${SHA224[@]}" "${SHA256[@]}" "${SHA384[@]}" "${SHA512[@]}")

# If Quit is clicked then exit
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
exit 0
fi

echo $selection | grep "MD5" > /dev/null
if [ $? = 0 ];then
md5sum "$file" | tee >(cut -d ' ' -f1 > /tmp/sum) |zenity --progress --title="MD5sum" --text="Calculating MD5 for:\n${file##*/}" --pulsate --auto-close

# If Cancel is clicked then remove temporary file and exit
if [ "${PIPESTATUS[2]}" -ne "0" ]; then
rm /tmp/sum
exit 0
fi

sum=`cat /tmp/sum`
zenity --info --title="MD5sum" --text="MD5sum : $sum\nFile :          ${file##*/}"
rm /tmp/sum
exit 0
fi

echo $selection | grep "SHA-1" > /dev/null
if [ $? = 0 ];then
sha1sum "$file" | tee >(cut -d ' ' -f1 > /tmp/sum) |zenity --progress --title="SHA-1" --text="Calculating SHA-1 for:\n${file##*/}" --pulsate --auto-close

# If Cancel is clicked then remove temporary file and exit
if [ "${PIPESTATUS[2]}" -ne "0" ]; then
rm /tmp/sum
exit 0
fi

sum=`cat /tmp/sum`
zenity --info --title="SHA-1" --text="SHA-1: $sum\nFile :    ${file##*/}"
rm /tmp/sum
exit 0
fi

echo $selection | grep "SHA-224" > /dev/null
if [ $? = 0 ];then
sha224sum "$file" | tee >(cut -d ' ' -f1 > /tmp/sum) |zenity --progress --title="SHA-224" --text="Calculating SHA-224 for:\n${file##*/}" --pulsate --auto-close

# If Cancel is clicked then remove temporary file and exit
if [ "${PIPESTATUS[2]}" -ne "0" ]; then
rm /tmp/sum
exit 0
fi

sum=`cat /tmp/sum`
zenity --info --title="SHA-224" --text="SHA-224 : $sum\nFile :         ${file##*/}"
rm /tmp/sum
exit 0
fi

echo $selection | grep "SHA-256" > /dev/null
if [ $? = 0 ];then
sha256sum "$file" | tee >(cut -d ' ' -f1 > /tmp/sum) |zenity --progress --title="SHA-256" --text="Calculating SHA-256 for:\n${file##*/}" --pulsate --auto-close

# If Cancel is clicked then remove temporary file and exit
if [ "${PIPESTATUS[2]}" -ne "0" ]; then
rm /tmp/sum
exit 0
fi

sum=`cat /tmp/sum`
zenity --info --title="SHA-256" --text="SHA-256 : $sum\nFile :         ${file##*/}"
rm /tmp/sum
exit 0
fi

echo $selection | grep "SHA-384" > /dev/null
if [ $? = 0 ];then
sha384sum "$file" | tee >(cut -d ' ' -f1 > /tmp/sum) |zenity --progress --title="SHA-384" --text="Calculating SHA-384 for:\n${file##*/}" --pulsate --auto-close

# If Cancel is clicked then remove temporary file and exit
if [ "${PIPESTATUS[2]}" -ne "0" ]; then
rm /tmp/sum
exit 0
fi

sum=`cat /tmp/sum`
zenity --info --title="SHA-384" --text="SHA-384 : $sum\nFile :         ${file##*/}"
rm /tmp/sum
exit 0
fi

echo $selection | grep "SHA-512" > /dev/null
if [ $? = 0 ];then
sha512sum "$file" | tee >(cut -d ' ' -f1 > /tmp/sum) |zenity --progress --title="SHA-512" --text="Calculating SHA-512 for:\n${file##*/}" --pulsate --auto-close

# If Cancel is clicked then remove temporary file and exit
if [ "${PIPESTATUS[2]}" -ne "0" ]; then
rm /tmp/sum
exit 0
fi

sum=`cat /tmp/sum`
zenity --info --title="SHA-512" --text="SHA-512 : $sum\nFile :         ${file##*/}"
rm /tmp/sum
exit 0
fi

« Last Edit: December 07, 2014, 06:23:01 AM by misko_2083 »
 

Re: A simple way to check MD5sum
« Reply #14 on: December 06, 2014, 09:13:03 PM »
 

anon222

  • Muted
  • Gold Level Poster
  • *
  • 688
    Posts
  • Reputation: 192
  • Linux Lite Member
    • View Profile

  • CPU: Dual core Pentium E5700 3GHz

  • MEMORY: 3Gb

  • VIDEO CARD: GeForce GT 430
Do you think it might be better as a single script where you select which Checksum to verify? I imagine a dialog pops up where the user can choose SHA1 or MD5.
Hmm, great idea. :)  Thank you. I'll set md5 as default one and add SHA256.
Once it's ready, I'll post here.
 

Re: A simple way to check MD5sum
« Reply #13 on: December 06, 2014, 10:38:11 AM »
 

Mike

  • Forum Regular
  • ***
  • 212
    Posts
  • Reputation: 26
  • Linux Lite Enthusiast
    • View Profile
Thank you! Do you think it might be better as a single script where you select which Checksum to verify? I imagine a dialog pops up where the user can choose SHA1 or MD5.
 

 

-->
X Close Ad

Linux Lite 6.6 FINAL Released - Support for 22 Languages Added - See Release Announcement Section