Downloaded File: Automated Verification

george udosen
3 min readSep 15, 2018

--

We all spend time downloading files off the internet and most time we don’t bother to check their validity and authenticity most times it’s tedious for most of us. I decided to write a tool that does that with little or no effort from our side for Linux users of course.

Here is the script to get it done by mere right clicking on the file in question and supplying the “checksum” to be used for the verification:

#!/usr/bin/env bashset -e# Create variables to hold the algorithm to use
opt1="sha256"
opt2="md5sum"
algotype="$(zenity --height=275 --width=300 --list --radiolist --text "Choose Algorithm to Use" --column 'Select...' --column 'Algorithm' FALSE "$opt1" FALSE "$opt2")"# Use selected algorithm
if [[ "$algotype" == "$opt1" ]]
then
# Carry out md5sum on the file
r="$(grep -Eo "^.* " <<< "$($algotype -a "$1")")"
elif [[ "$algotype" == "$opt2" ]]
then
# Do sha256 on the file
r="$(grep -Eo "^.* " <<< "$($algotype "$1")")"
else
exit 1
fi
# Remove white space
r="$(printf "%s" "$r" | tr -d '[:space:]')"
# Get the checksum for verification from user
shasum="$(zenity --height=200 --width=350 --entry --title "Checksum Value" --text "Please enter the checksum" --entry-text "add checksum here")"
# Remove white space
shasum="$(printf "%s" "$shasum" | tr -d '[:space:]')"
if [[ "$shasum" == "add checksum here" || "$shasum" == " " ]]
then
zenity --error --text "A checksum is required! "
exit 1
else
if [[ "$r" == "$shasum" ]]
then
zenity --info --height=100 --width=100 --title "Success! " --text "The file is ok! "
exit 0
else
zenity --height=100 --width=200 --error --text "Checksum mismatch! "
exit 1
fi
fi
exit 0

This code would be placed in any location but I placed mine in my /home/$USER/bin which is in my “PATH” so I can access it from any where on my system.

To make this appear in the right click menu you will need the venerable tool FileManager-Actions Configuration Tool, see here for how to set that up:

You should see this when you use the tool:

I used the “zenity” tool to bring up these dialogue boxes.

How does one use the tool?

You just download the file to verify, and copy the checksum value to use. When you right on the file you select the menu item to do a file verification. You will be asked to choose which algorithm you intend to use, I just include “md5”, and “sha256” you can always modify the script and add whichever algorithm you use often. With that a dialogue box will ask for the checksum to verify the file against and on success or failure it will display a dialogue box to inform the users.

--

--

george udosen
george udosen

Written by george udosen

DevOps | FullStack developer | Python::Flask | GCP Cloud Certified | AWS & AZURE Cloud Savy | Linux Sysadmin | Google IT Support

No responses yet