Checksum for Linux..

Blank-Icon
Name
Last modified
Size
Description

ParentIconTitle
nfo-Icon
23-Nov-11 05:39 PM
1.43 KB
plain text info
zip-Icon
23-Nov-11 05:26 PM
53.11 KB
ZIP compressed archive
gz-Icon
20-Aug-14 05:35 PM
14.7 KB
GZIP compressed archive
sh-Icon
7-Sep-14 10:19 AM
37.17 KB
unix shell script
sh-Icon
5-Sep-09 09:24 PM
2.43 KB
unix shell script
DIRECTORY-Icon
29-May-17 11:40 PM
infinite
Virtual Link
php#section-Comments-Icon
29-May-17 11:40 PM
growing
Virtual Link

What is Checksum for Linux?

Checksum for Linux is a Bash script which attempts to emulate some of the most basic checksum-like features, effortless recursion, synchronization, multihash™ support and such, with simple operation and nifty KDE/Gome GUI integration, something I needed for a time. Because it is a Bash script, you can run it directly from a console or script. And because it's Linux, you can run it on your NAS.

The Linux version of checksum lacks many (most) of the Windows' version's coolest features. It's been a long while since I worked on this, it has everything I needed, which is how checksum on Windows started, until I started thinking about it more, asking questions and answering your questions about it.

More recently, people have started asking me about the Linux side of checksum, as the popularity of NAS boxes increases, I guess. So I've started thinking about it again. A NAS unit is on my own tech horizon for sure, so whatever work I do will one day come in handy for me too, no doubt.

One day I'll get time to do this area properly. For now, you can grab a copy of the latest checksum for Linux zip (which is also included in the main Windows distribution), as well as check out the script itself (Note: I've added a .sh extension to these web files so the server knows what to do with them).

You can also download a proper "bin" directory in tar.gz format with a complete collection of working symlinks (which the regular distribution doesn't have. Sorry about that!), which should definitely decompress on a Linux box. Of course, you clever Linux types can easily make your own symlinks..

cd /usr/local/bin
ln -s checksum verify
ln -s checksum kverify
etc..

checksum recognizes the name of the symlink it was called from and switches to that mode, you see.

There are a couple of demo shortcuts and symlinks in there, too, for reference and inspiration. For more information, open the checksum script itself (/usr/local/bin/checksum) in a decent text editor, or click checksum.sh, above.

It starts something like this..


#	Welcome to Checksum for Linux - drop-dead simple hashing from your desktop!
#
# 	This is the BASH script part of Checksum for Linux, a simple checksum-like hash creation
# 	& verification package, aiming to recreate the basic point-and-[right-]click hashing
# 	functionality of the original checksum, except in the KDE Desktop environment*.
#
# 	Essentially, it's a handy right-click+GUI front-end for the ever-robust on-board *nix
# 	hashing tools, with a good few shiny knobs on; Features..
#
#	Hash or verify files and folders, even entire volumes, with a click..
#
#		Select "Checksum" from any folder's services menu, and Checksum springs into action,
#		creating MD5 or SHA-* hashes for all files in the folder, and all the folders inside,
#		and all the folders inside that, and so on, aka. "recursively", through the entire
#		directory tree.
#
# 		Select "Verfiy this folder", from your service menu, and Checksum searches the
# 		*entire* directory tree for .md5, .sha*, and .hash files, and verifies them *all*.
#
#	Full Desktop GUI integration.
#
#		The terminal is not required. Create and verify hashes directly from your desktop,
#		using Dolphin/Konqueror/etc. service menus. For output, Checksum supports both
#		kdialog (KDE) and zenity (Gnome) dialogs and notifications. Or you can use the shell.
#
#	Configurable File Masks..
#
#		Checksum only music files, or whatever; with both single and multiple file masks.
#
#	MD5/SHA1/SHA2 hashing algorithms supported.
#
#		Okay, and SHA-384 and SHA-512, because it was so trivial to tag on.
#
#	Intellignet append (syncronization).
#
#		Added a few files to a folder? No problem. With intelligent append, you can simply
#		checksum again, and *only* the new hashes get added. It's all automatic!
#
#	Multihashing_(TM), with generic .hash file handling..
#
#	  As well as full .md5 and .sha1 support, of course!
#
#		So if you upgrade algorithms later, or wish to include multiple hashing algorithms
#		within a single hash file; no problem; checksum can verify them all. As well as
#		inferring security benefits, this enables the use of a cute, generic ".hash"
#		extension for *all* your checksums! (the real reason) One file fits all, baby!
#
# 		Checksum also makes it trivial to create such a file, with intelligent hash append;
#		auto-matically skipping any files already hashed with your current algorithm. Neat.
#
#	Read-only Fall-back
#
#		Checksum can automatically switch to a designated fall-back folder in the event
#		of encountering read-only conditions in the checksumming location.
#
#	Shell use (mostly) supported.
#
#		You want these groovy features in your shell, go for it!
#
#
# Usage:
#
# 	In the shell..
#
#		To create hashes:
#
#			checksum <file|folder>
#
#		To verify hashes:
#
#			verify <checksum file|folder>
#
# 	Of course, the whole point of this, is to have the power of these commands on your
# 	desktop, in the form of some handy services. The accompanying .desktop files enable
# 	you to do exactly this. These simply launch checksum with different switches, instructing
#	Chec ksum to post GUI dialogs, notifications and such in your desktop environment.
#
# 	There is a choice of kdialog (KDE) and zenity (Gnome) GUI reporting, and checksum will
# 	use whatever you specify on the command-line, or with symlinks. You can also force zenity
# 	dialogson KDE, if you prefer. zenity's dialogs and notifications may be superior, but you
# 	lose the ability to "Do not show this message again". FYI; The preferences for those
#	"kdialogs" are in ~/.kde/share/config/checksum.
#
#	Because both systems have advantages (kdialog also has a handy find command, for searching
#	the text dialogs. Pretty neat. But zenity text boxes scroll the output automatically, for
#	example), there is also a "hybrid" setting, where you can use the best bits from each program.
#
#
#	Command-Line Switches..
#
# 	You can override Checksum's behaviour with the use of command line arguments
# 	aka. "switches". These override *everything*, so, for example, if you run Checksum
# 	via the "kchecksum-sha1" symlink, and add the "--md5" switch, you get MD5 hashes.
# 	These also enable you to use checksum without *any* symlinks, if you prefer that.
#
# 	Available switches..
#
#			--verify			force verification mode, regardless of how checksum was called.
#			--kde				use kdialogs (handy, when not using a k* symlink)
# 			--zenity | --zen	force zenity dialogs
#			--hybrid			use hybrid kdialog + zenity GUI system (best of both)
# 			--xl				extensionless hashing (when not default - why oh why!)
# 			--append			set append to true when it is not (again, why?)
# 			--noappend			set append to false
# 			--algo				set hashext="algo", override generic .hash file creation.
# 			--md5 				default algorithm = MD5
# 			--sha | --sha1		default algorithm = SHA-1
# 			--sha2				default algorithm = SHA-256
# 			--sha3				default algorithm = SHA-384
# 			--sha5				default algorithm = SHA-512
#			--mask=file.mask	use regular file globbing patters.
#								e.g.. kchecksum --mask=*.avi /Archive/Movies
#								Multiple masks are okay, in the form.. --mask=*.mp3,*.ogg,*.flac
#
#	NOTE: Switches are applied in the above order, later switches overriding earlier switches.
#
# 	You can also run kchecksum, kverify, etc. (the GUI versions) from the terminal;
# 	handy if you need to debug/troubleshoot some [k|g]checksum/[k|g]verify operation;
# 	the normal output will appear in your terminal. Also see Logging, below.
#
#
# 	Checksum for Linux also comes with a handy Windows Hash File Converter script you can
# 	use to convert any hash files made with windows tools. It does nothing more clever
# 	than switch the linebreaks from DOS to UNIX, but hey, you *can* convert an entire
# 	volume of hash files with one click! See: convert-winhashes for more details.
#
# 	If you have any questions, mail me, or better yet, post them on the Checksum page..
#
# 	http://corz.org/linux/software/checksum/
#
# 	Have fun!
#
# 	;o)
# 	Cor < linux at corz d.t org >
#
#
# 	NOTE: 	Other than my own intense desktop usage, this has had *very* little testing;
#			so all comments, bug reports, etc., will be gratefully received.
#
#	ALSO:	Apologies for all the tabs and spaces in the kdialog titles, but I cannot
#			live with " - kDialog" slapped on there. If this interferes with any desktop
#			automations or somesuch you have running; edit them out. And let me know!
#
# 	*
# 	It should work fine with other Linux desktops, too, but the GUI & activation methods
# 	would need to be tweaked some. Gnome (zenity) dialogs are already coded in, though I
# 	currently have no Gnome desktop to figure out Nautilus' service menus. Real soon, now!
#
# 	**
# 	File systems have "directories", but on a desktop they are called "folders". ;o)


## NOTE{S}:
#

## KDE & Kdialog
#
#	The funky dbus stuff, this requires KDE 4 to function.
#

## Logging..
#
#	When you use checksum from inside your desktop, a logfile is created in
#	/tmp/checksum.log, which contains all the script output (stuff that you might see
#	if you used checksum from the shell). This file is (usually) deleted at boot time,
#	and can be handy meantime. For example, if you added debug echo statements into this
#	script, they could be viewed there. Or if nothing happened, that file may tell you why.
#
#	However, if you prefer, you can disable this logging altogether with a single
#	alteration to the checksum .desktop files - full details inside "checksum.desktop".
#
## ##

## SHA-* support..
#
#	Checksum's default operation is to create and verify MD5 hashes. Unless you have
#	specific security needs, MD5 is perfect for file verification purposes, and is
#	also faster, in use, than any of the SHA-* family of algorithms.
#
#	Having said that, Checksum fully supports both SHA-1 and SHA-256 hashing algorithms.***
#	There is a preference (below) where you can set your preferred default.
#
#	Also, if you use a symlink with a name ending 'sha1', checksum will magically switch
#	to use sha1sum for all its operations. Use "sha2" to get SHA-256; 'kchecksum-sha1',
#	'kchecksum-sha2', etc. Same story in a shell; 'checksum-sha1', etc. You can also use
#	the command-line switches described above. Or a combination of both. Your call.
#
#	Checksum comes with a pre-made selection of .desktop files facilitating easy hashing
#	with the SHA-* hashing algorithms, which most people probably won't need.
#
#	NOTE: If you set your default algorithm to SHA-something, you can override the other
#	way, too, by using a symlink ending in "md5", or by use of the '--md5' switch,
#
#	During *verification*, checksum automatically switches algorithms, depending on
#	the current hash file extension, md5 => MD5; sha1 => SHA-1; sha2 => SHA-256; etc.,
#	so you don't have to set anything special to verify them. One command verifies ALL!
#
#	If you are using a generic extension, e.g. ".hash", checksum will interrogate the
#	file on a line-by-line basis, interrogating the individual hashes, and using
#	whatever tool is most approprite for each individual hash.
#
#	FYI; if you ask checksum to verify a file of a *completely* unknown extension, it
#	will be checked with md5sum, just in case it really is an old checksum file. It
#	will *not* be treated as a generic .hash file. This is by design.
#
#	*** Checksum also supports SHA-384 ('sha3') and SHA-512 ('sha5') hashing.
#		But let's be serious - this is file verification!
#
## ##


## :BEGIN PREFS
#

# Default Hashing Algorithm..	[string]		[default: algorithm='md5']
#
# Choose from 'md5' (for MD5), 'sha1' (SHA-1), or 'sha2' (SHA-256).
#
algorithm='md5'
#
# NOTE: you can override this default algorithm at any time by accessing checksum
# via a symlink of the appropriate name; e.g. 'kchecksum-sha1' for SHA-1 hashing.
# See the notes above, for more details. There's also 'sha3' and 'sha5', for nutters!


# Hashfile extension.		[string {file extension}]		[default: hashext='hash']
#
# Your preferred hash extension (for creating hashes)..
# files of this extension will also be treated as checksum files during verification.
#
hashext='hash'
#
# Checksum fully supports MultiHashing, and will happily verify a mix of MD5 and SHA
# hashes, even mixed up in the same file, hence the ability to use a single, generic
# .hash extension for *all* your hashes, as well as some other goodies.
#
# If you use your /own/ generic extension, you will probably want to also add it to your
# system filetype associations, so it automatically runs with kverify %f, or whatever.
#
# (at the time of writing, checksum doesn't setup .hash files, either; this is planned)
#
# There is also the special value, 'algo', which will use the currrent algorithm as the
# hash extension; e.g. an MD5 checksum file might be called, 'foobar.md5'.  While
# clutterish and less flexible, if you tend to hash very large numbers of small files;
# note; this setting has performance benefits during verification, because there is no
# need to interrogate the hash file line-by-line, or switch hashing tools: the
# extension sets the algorithm. You can also set this at runtime, with switches, so it
# may still be a good idea to leave the generic extension, and specify --algo as needed.
#
# ** IMPORTANT **
#
# DO NOT set this to 'md5', or some other algorithm - use 'algo', and set your default
# algorithm, above, instead.
#


# Append hashes to existing hash files?			[bool {0|1}]	[default: append=1][true]
#
# Checksum can automatically append any hashes you create, onto existing hash files.
# As well as making it trivial to add new files to an existing folder hash, this enables
# you to easily make MultiHashes, adding SHA-1 hashes into an existing MD5 hash file, or
# some other combination of actions. The possibilities are vast. You could easily create
# a hash file that was *ordered*; movies, music, archives, everything else, for example.
#
# Otherwise, set this to 0, and Checksum will ask you if you wish to overwrite existing
# hash files as and when it discovers them. Boring!
#
append=1


# Extensionless Hashes?		[bool {0|1}]			[default: extensionless=1][true]
#
# When hashing individual files, should checksum create 'extensionless' hash files?
# e.g. MyMovie.avi >> 'MyMovie.md5', NOT 'MyMovie.avi.md5' .
#
extensionless=1
#
# As well as being rather elegant, it's rather efficient; a hash for 'foo.avi' can
# be stored alongside hashes for 'foo.mpg', 'foo.html', & 'foo.nfo', etc., in one
# file. During verification, it looks just like a regular folder checksum. wekl!!


# Force Zenity?				[bool {0|1}]				[default: force_zenity=0][false]
#
# If you prefer to use zenity's notifications and dialogs, even when kdialog is available
# on KDE, set this to 1.. NOTE: You can also force zenity by using any of the g* symlinks.
#
force_zenity=0
#
# Don't forget to install zenity!	(sudo aptitude install zenity)


# Hybrid GUI System
#
# This basically uses kdialog where it might be useful to have the "do not show this again"
# option, and zenity for everything else. The advantage of this is three-fold; firstly, you
# get the "Do not show this again" option for dialogs where such things might matter. Secondly,
# you get superior notifications which stay put throughout the length of the entire operation,
# and thirdly, you get a neat icon in your system tray, as opposed to the rather distressing
# kNotifications! Zenity also scrolls its text output to the end (where the errors are), which
# is nice. This was trivial to implement, and trivial for you to customize, if required. See below.
#
hybrid=1
#
# Obviously, for this to work as expected, you need both kdialog and zenity installed.


# Ignore certain file types		[array]
# 								[default: ignore_extensions=('desktop' 'ini' 'lnk' 'directory')]
#
# When creating hashes, checksum will skip files with the following extensions..
# DO Leave a space between each quoted entry. No dots required (unless the extension has one)
#

ignore_extensions=('desktop' 'ini' 'lnk' 'directory' 'nfo' 'm3u' 'pls' 'url' 'sfv')
#
# NOTE:	The 'directory' entry is for '.directory' files, NOT directories!
# NOTE:	Checksum will also automatically skip any hash files.


# Fall-Back location		[folder path]			[default: fallback_dir="~/Hashes"]
#
# If you ask checksum to create hashes of some read-only file/directory/volume, it
# obviously cannot store the hashes in the usual location, and so will use a fall-back.
#
fallback_dir="$HOME/Hashes"
#
# You can use "$HOME" variable to refer to your actual home folder.
# NOTE: You must use double-quotes to expand $VARIABLES. ("$var" not '$var')


# Temp file					[file path]			[default: tmpfile='/tmp/checksum.tmp']
#
# Temporary file for folder verification (usually inside /tmp/). Output from multiple
# checksum files is collected here and posted at the finish. This gets wiped on every run.
#
tmpfile='/tmp/checksum.tmp'
#
# NOTE: The command-line inside any .desktop files used to launch Checksum may also log.
# By default, a semi-permanent (deleted@boot) log will be created in /tmp/checksum.log

# Error Log					[file path]		[default: errlog='/tmp/checksum-errors.log']
#
# Another temporary file, wiped at run-time. Any verification errors are collected
# here and its output is posted at the foot of your verification results.
#
errlog='/tmp/checksum-errors.log'


# Keep the error log?				[bool {0|1}]			[default: append=0][false]
#
# Set this to 1, and the error log (if there is one) will be time-stamped and copied over
# to the working directory at the end of the verification procedure. In actual fact, you
# get a log of the entire operation + the error log joined together.
#
keep_errlog=0


# Dialog Maximum Height
#
# If you have an especially large monitor, you may wish to hack a higher value here..
#
dh_max=600


# Show Times.
#
# If you are testing or something, you might want to enable this. Total time is reported.
# NOTE: this time is sent to stdout, so you will need to either examine checksum.log
# (or whatever it's called in your .desktop files), or else run things from the shell.
show_times=1

#
## :END PREFS


# Note to experienced BASH coders..
#
# I'm an amateur bash coder, but I'd like to be better.
# All suggestions for improvements to Checksum will be warmly received.

2do..

There is still a lot to be done. The verify output is poor in the console (it was designed to be run from my KDE desktop), in that it doesn't give a clear indication of failures at the end of the potentially long list of results, forcing the user to scroll, the scripter to parse.

In time, God-willing, I'll get more work on this done. Real Soon Now!

;o) Cor

Welcome to corz.org!

If something isn't working, I'm probably improving it, try again in a minute. If it's still not working, please mail me!