This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Checksum tools on right-click menu

28

Votes
28
0
Tags: dolphin, checksum, filemanager, file-manager dolphin, checksum, filemanager, file-manager dolphin, checksum, filemanager, file-manager
(comma "," separated)
vishalrao
Registered Member
Posts
157
Karma
0
OS
A context menu (right-click menu) entry called "checksum" say with options for md5, sha1, sha256 etc would be useful to quickly verify file integrity. If not a new menu entry, then perhaps in the "properties" view of a file there should be a new tab called "checksums" which can be calculated on demand...

Last edited by bcooksley on Sat Apr 04, 2009 9:10 pm, edited 1 time in total.


"Thou shalt not follow the null pointer for at its end madness and chaos lie."
vishalrao
Registered Member
Posts
157
Karma
0
OS
Any suggestions to add such a context menu myself? I'm running KDE 4.3 RC2 and would like to add right-click menus for files in dolphin to invoke checksum tools and display in a dialog... (unless something is already out there...)

edit: oops, sorry for posting a question in a brainstorm post :-)

Found the following link in the mean time, will look at it: http://techbase.kde.org/Development/Tut ... vice_Menus

(didnt know it was called "service menu" so wasnt sure what to search for until now)


"Thou shalt not follow the null pointer for at its end madness and chaos lie."
vishalrao
Registered Member
Posts
157
Karma
0
OS
And a quickie solution! Place the following code as a .desktop file in a "ServiceMenus" subdirectory in either of the paths shown by:

Code: Select all
kde4-config --path services


checksum.desktop file:

Code: Select all
[Desktop Entry]
Type=Service
Icon=dolphin
Actions=ShowMD5Hash;ShowSHA1Hash;ShowSHA256Hash
ServiceTypes=KonqPopupMenu/Plugin
MimeType=all/allfiles

[Desktop Action ShowMD5Hash]
Exec=md5sum %U | xargs kdialog --title "MD5 hash" --msgbox
Icon=dolphin
Name=Show MD5 hash

[Desktop Action ShowSHA1Hash]
Exec=sha1sum %U | xargs kdialog --title "SHA1 hash" --msgbox
Icon=dolphin
Name=Show SHA1 hash

[Desktop Action ShowSHA256Hash]
Exec=sha256sum %U | xargs kdialog --title "SHA256 hash" --msgbox
Icon=dolphin
Name=Show SHA256 hash


"Thou shalt not follow the null pointer for at its end madness and chaos lie."
vishalrao
Registered Member
Posts
157
Karma
0
OS
Improvements to the checksum tool to add 2 new features: Actually try to verify the file integrity by searching for stored checksum files and also display a progress dialog (throbber) while the checksum is being verified so you know something is happening :)

Copy the following code as root/sudo into a script file, say checkhash.sh, into /usr/bin after making it executable.

Code: Select all
#! /bin/sh
toolname=`echo $1 | sed "s/\(.*\)/\L\1sum/"`
filepath=`echo $2 | sed "s/\(.*\/\).*/\1/"`
hashfile=`echo $1 | sed "s/\(.*\)/\U\1SUMS/"`
dialogtitle=`echo $1 | sed "s/\(.*\)/\U\1/"`
dcopRef=`kdialog --progressbar "Checking $dialogtitle hash, please wait..." 0 --title "Check $dialogtitle Hash"`
result=`$toolname $2`
filename=`echo $result | sed "s/^\([0-9a-z]*\) .*\/\(.*\)/\2/g"`
checksum=`echo $result | sed "s/^\([0-9a-z]*\) .*\/\(.*\)/\1/g"`
lookup=`grep ${filename} ${filepath}*${hashfile}* 2>/dev/null | grep ${checksum} 2>/dev/null`
findhash=`grep ${checksum} ${filepath}*${hashfile}* 2>/dev/null`
findfile=`grep ${filename} ${filepath}*${hashfile}* 2>/dev/null`
integrity=`if [ "${findfile}file" = "file" ]; then echo unknown; else if [ "${lookup}sum" = "sum" ]; then echo bad; else echo good; fi; fi;`
qdbus $dcopRef org.kde.kdialog.ProgressDialog.close
kdialog --title "Check $dialogtitle Hash" --msgbox "Filename: ${filename}\nChecksum: ${checksum}\nIntegrity: ${integrity}"


Change the checksum.desktop file mentioned in earlier post to have the following code instead:

Code: Select all
[Desktop Entry]
Type=Service
Icon=security-high
Actions=CheckMD5Hash;CheckSHA1Hash;CheckSHA256Hash
ServiceTypes=KonqPopupMenu/Plugin
MimeType=all/allfiles

[Desktop Action CheckMD5Hash]
Exec=checkhash.sh md5 %U
Icon=security-high
Name=Check MD5 Hash

[Desktop Action CheckSHA1Hash]
Exec=checkhash.sh sha1 %U
Icon=security-high
Name=Check SHA1 Hash

[Desktop Action CheckSHA256Hash]
Exec=checkhash.sh sha256 %U
Icon=security-high
Name=Check SHA256 Hash


This is to showcase my lame shell scripting skillz, I'm sure this can be cleaned up some more and bugs found and fixed.

Right now, based on convention, it will try to generate the checksum and compare it with any checksums stored in files with SHA256SUMS or MD5SUMS etc in the name. Usually when you download an ISO or something the same web location has the SHA1SUMS file which you normally download to the same local folder.

Works well for me after some quick testing, hope it works for you...


"Thou shalt not follow the null pointer for at its end madness and chaos lie."
vishalrao
Registered Member
Posts
157
Karma
0
OS
Screenshots:

Image

Image

Image


"Thou shalt not follow the null pointer for at its end madness and chaos lie."
andre_orwell
Registered Member
Posts
181
Karma
1
We definitely need more Indians on this forum :-)


andre_orwell, :-[
vishalrao
Registered Member
Posts
157
Karma
0
OS
heh.

but: bug bug bug, i think it cant handle spaces in the paths :D


"Thou shalt not follow the null pointer for at its end madness and chaos lie."
User avatar
alex789
Registered Member
Posts
25
Karma
0
OS
more corrected is:
(i add "" to work with file names, which contain " "(space))

vishalrao wrote:Copy the following code as root/sudo into a script file, say checkhash.sh, into /usr/bin after making it executable.
Code: Select all
#! /bin/sh
toolname=`echo $1 | sed "s/\(.*\)/\L\1sum/"`
filepath=`echo $2 | sed "s/\(.*\/\).*/\1/"`
hashfile=`echo $1 | sed "s/\(.*\)/\U\1SUMS/"`
dialogtitle=`echo $1 | sed "s/\(.*\)/\U\1/"`
dcopRef=`kdialog --progressbar "Checking $dialogtitle hash, please wait..." 0 --title "Check $dialogtitle Hash"`
result=`$toolname "$2"`
filename=`echo $result | sed "s/^\([0-9a-z]*\) .*\/\(.*\)/\2/g"`
checksum=`echo $result | sed "s/^\([0-9a-z]*\) .*\/\(.*\)/\1/g"`
lookup=`grep ${filename} ${filepath}*${hashfile}* 2>/dev/null | grep ${checksum} 2>/dev/null`
findhash=`grep ${checksum} ${filepath}*${hashfile}* 2>/dev/null`
findfile=`grep ${filename} ${filepath}*${hashfile}* 2>/dev/null`
integrity=`if [ "${findfile}file" = "file" ]; then echo unknown; else if [ "${lookup}sum" = "sum" ]; then echo bad; else echo good; fi; fi;`
qdbus $dcopRef org.kde.kdialog.ProgressDialog.close
kdialog --title "Check $dialogtitle Hash" --msgbox "Filename: ${filename}\nChecksum: ${checksum}\nIntegrity: ${integrity}"


Change the checksum.desktop file mentioned in earlier post to have the following code instead:

Code: Select all
[Desktop Entry]
Type=Service
Icon=security-high
Actions=CheckMD5Hash;CheckSHA1Hash;CheckSHA256Hash
ServiceTypes=KonqPopupMenu/Plugin
MimeType=all/allfiles

[Desktop Action CheckMD5Hash]
Exec=checkhash.sh md5 "%U"
Icon=security-high
Name=Check MD5 Hash

[Desktop Action CheckSHA1Hash]
Exec=checkhash.sh sha1 "%U"
Icon=security-high
Name=Check SHA1 Hash

[Desktop Action CheckSHA256Hash]
Exec=checkhash.sh sha256 "%U"
Icon=security-high
Name=Check SHA256 Hash


Last edited by alex789 on Tue Jul 28, 2009 11:37 am, edited 1 time in total.
vishalrao
Registered Member
Posts
157
Karma
0
OS
I think this line needs to be corrected, but I will check it maybe during the weekend:

Code: Select all
filepath=`echo $2 | sed "s/\(.*\/\).*/\1/"`


"Thou shalt not follow the null pointer for at its end madness and chaos lie."
vishalrao
Registered Member
Posts
157
Karma
0
OS
@alex: oh i see, you fixed this line to add the double-quotes, thanks! i will try it to see if it works:

Code: Select all
result=`$toolname "$2"`


edit:

also needed to do the same (add double quotes) for the 2 lines using grep and the filepath line:

Code: Select all
...
filepath=`echo "$2" | sed "s/\(.*\/\).*/\1/"`
...
lookup=`grep "${filename}" ${filepath}*${hashfile}* 2>/dev/null | grep ${checksum} 2>/dev/null`
...
findfile=`grep "${filename}" ${filepath}*${hashfile}* 2>/dev/null`


i think its working better now, thanks!


"Thou shalt not follow the null pointer for at its end madness and chaos lie."
dtonhofer
Registered Member
Posts
7
Karma
0
Very cool. I'm going to nitpick on the use of quotes around %U in the .desktop file though. They are not necessary and indeed prohibited:

According to

http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s06.html :

"Field codes must not be used inside a quoted argument, the result of field code expansion inside a quoted argument is undefined. The %F and %U field codes may only be used as an argument on their own."


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]