Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Community > The Lounge > Computers & IT



Reply
 
LinkBack Thread Tools
Old August 6th, 2011, 12:46 PM   #1 (permalink)
Senior Member
 
Join Date: Mar 2011
Posts: 2,464
 
Device(s):
Thanks: 1,142
Thanked 1,012 Times in 474 Posts
Default Wrote my own checksum verifier

I needed a way to verify a checksum for a .ISO file I downloaded recently. I wasn't happy with the checksum verifiers I found (GUI, bloated, etc.) so I wrote my own. Simple, fast and runs great in Ubuntu.

Code:
#!/bin/bash
# Filename: csum.sh
# Version: 0.1
# Requires: md5sum, sha1sum, sed, bash
# Author: Ian MacGregor (aka ardchoille)
# License: GPL
# This script creates and verifies checksums
# with the option to save created checksum to file

mypath="$HOME"

getfilepath()
{
    myfile="/path/file"
    while [ ! -f $myfile ]
    do
        echo "Please enter the path and filename:"
        read myfile
        if [ ! -f $myfile ]
        then
            echo "The path you entered does not exist." 
            echo
        else
            return
        fi
    done
}

getsum()
{
    mysum=""
    while [ ! $mysum ]
    do
        echo "Please enter the expected checksum:"
        read mysum
        if [ ! $mysum ]
        then
            echo "You must provide a checksum to verify." 
            echo
        else
            return
        fi
    done
}

createmd5sum()
{
    getfilepath
    echo "Working..."
    cmd5sum=`md5sum "$myfile"`
    echo
    echo "MD5SUM report:"
    echo $cmd5sum
    echo
    echo "Save this MD5SUM report to $mypath/mymd5report?"
    echo "1" "Yes"
    echo "2" "No"
    echo "====================="
    echo "Please select 1 or 2"
    read mysavereport
    case $mysavereport in
    "1") echo $cmd5sum >> $mypath/mymd5report ; cmd5sum="" ; myfile="" ; mysavereport="" ; return ;;
    "2") cmd5sum="" ; myfile="" ; mysavereport="" ; return ;;
    *) echo "Please select 1 or 2" ;;
    esac
}

createsha1sum()
{
    getfilepath
    echo "Working..."
    csha1sum=`sha1sum "$myfile"`
    echo
    echo "SHA1SUM report:"
    echo $csha1sum
    echo
    echo "Save this SHA1SUM report to $mypath/mysha1report?"
    echo "1" "Yes"
    echo "2" "No"
    echo "====================="
    echo "Please select 1 or 2"
    read mysavereport
    case $mysavereport in
    "1") echo $csha1sum >> $mypath/mysha1report ; csha1sum="" ; myfile="" ; mysavereport="" ; return ;;
    "2") csha1sum="" ; myfile="" ; mysavereport="" ; return ;;
    *) echo "Please select 1 or 2" ;;
    esac
}

verifymd5sum()
{
    getfilepath
    echo
    getsum
    echo "Working..."
    checkfile=`md5sum "$myfile" | sed 's/ .*//'`
    echo
    if [ "$checkfile" = "$mysum" ]
    then
        echo "The expected md5sum matches the file's md5sum." 
    else
        echo "The checksums do not match." 
    fi
    echo
    echo "Press the Enter key for Main Menu..."
    read
    checkfile=""
    myfile=""
    mysum=""
    return
}

verifysha1sum()
{
    getfilepath
    echo
    getsum
    echo "Working..."
    checkfile=`sha1sum "$myfile" | sed 's/ .*//'`
    echo
    if [ "$checkfile" = "$mysum" ]
    then
        echo "The expected sha1sum matches the file's sha1sum." 
    else
        echo "The checksums do not match." 
    fi
    echo
    echo "Press the Enter key for Main Menu..."
    read
    checkfile=""
    myfile=""
    mysum=""
    return
}

while :
do
    clear
    echo "===================================="
    echo "Main Menu" 
    echo "===================================="
    echo "1" "Create an MD5 checksum for a file"
    echo "2" "Create an SHA1 checksum for a file"
    echo "3" "Verify a file by its MD5 checksum"
    echo "4" "Verify a file by its SHA1 checksum"
    echo "5" "Quit"
    echo "===================================="
    echo "Please select 1,2,3,4, or 5"
    read mych
    case $mych in
    "1") clear ; createmd5sum ;;
    "2") clear ; createsha1sum ;;
    "3") clear ; verifymd5sum ;;
    "4") clear ; verifysha1sum ;;
    "5") clear ; exit 0 ;;
    *) echo "Please select 1,2,3,4, or 5" ;;
    esac
done

__________________

ardchoille is offline  
Reply With Quote
The Following 2 Users Say Thank You to ardchoille For This Useful Post:
alostpacket (August 18th, 2011), johnlgalt (September 5th, 2011)
Sponsors
Old August 7th, 2011, 12:00 PM   #2 (permalink)
Antidisestablishmentarian
 
johnlgalt's Avatar
 
Join Date: Oct 2009
Location: 3rd Rock
Posts: 8,431
 
Device(s): Motorola® DROID® BIONIC®
Thanks: 1,836
Thanked 1,610 Times in 1,154 Posts
Send a message via ICQ to johnlgalt Send a message via MSN to johnlgalt Send a message via Yahoo to johnlgalt Send a message via Skype™ to johnlgalt johnlgalt@gmail.com
Default

Nice script. Surprised you didn't opt for md5sum command built into Ubuntu (and derivative) builds, though....

https://help.ubuntu.com/community/HowToMD5SUM
__________________

Files for the Motorola® DROID® BIONIC®:
Motorola USB drivers v5.5.0- 32bit | Motorola USB drivers v5.5.0- 64bit | Motorola RSD Lite v5.7
johnlgalt is online now  
Reply With Quote
The Following User Says Thank You to johnlgalt For This Useful Post:
alostpacket (August 18th, 2011)
Old August 8th, 2011, 01:05 AM   #3 (permalink)
nkk
Senior Member
 
nkk's Avatar
 
Join Date: Mar 2010
Posts: 747
 
Device(s): HTC Thunderbolt (rooted, ROMS switch to often to keep updating this). Have owned the Droid Incredib
Thanks: 72
Thanked 676 Times in 269 Posts
Default

But what is fun about just using a built in utility? We use Linux so we can tweak, even if a bit unnecessarily, right?

Anyway, the script looks good. I usually opt for md5sum, but to each his own.

-Nkk
nkk is offline  
Reply With Quote
The Following 2 Users Say Thank You to nkk For This Useful Post:
alostpacket (August 18th, 2011), ardchoille (August 8th, 2011)
Old September 5th, 2011, 10:02 PM   #4 (permalink)
Frank Burns Eats Worms!
 
9to5cynic's Avatar
 
Join Date: Feb 2011
Location: Evo Root Forum, Lounge, Forum Games.
Posts: 3,280
 
Device(s): Evo 4G - CleanRom 2.0 (April '12)
Thanks: 1,761
Thanked 1,122 Times in 785 Posts
Send a message via AIM to 9to5cynic
Default

Awesome. Way to go. I'll try this next time I need to md5 anything.

(Perhaps retire md5sum?)
9to5cynic is offline  
Reply With Quote
Old October 23rd, 2011, 10:21 PM   #5 (permalink)
Senior Member
 
Join Date: Mar 2011
Posts: 2,464
 
Device(s):
Thanks: 1,142
Thanked 1,012 Times in 474 Posts
Default

Quote:
Originally Posted by johnlgalt View Post
Nice script. Surprised you didn't opt for md5sum command built into Ubuntu (and derivative) builds, though....

https://help.ubuntu.com/community/HowToMD5SUM
My script uses the md5sum and sha1sum commands in a single script. Eh, it was fun writing the script
ardchoille is offline  
Reply With Quote
Old October 24th, 2011, 03:25 AM   #6 (permalink)
Member
 
Join Date: May 2011
Location: Near Stirling, Scotland
Posts: 138
 
Device(s): HTC Desire HD on Cyanogen CM7 (for now)
Thanks: 10
Thanked 29 Times in 20 Posts
Default

Cracking well done
Haggistech is offline  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Community > The Lounge > Computers & IT User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 03:17 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo