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

test: Reply
 
LinkBack Thread Tools
Old August 6th, 2011, 12:46 PM   #1 (permalink)
Senior Member
Thread Author (OP)
 
ardchoille's Avatar
 
Join Date: Mar 2011
Location: Seattle
Gender: Male
Posts: 3,684
 
Device(s):
Carrier: Not Provided

Thanks: 1,957
Thanked 1,959 Times in 856 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

Advertisements
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)
sponsored links
Old August 7th, 2011, 12:00 PM   #2 (permalink)
Antidisestablishmentarian
 
johnlgalt's Avatar
 
Join Date: Oct 2009
Location: 3rd Rock
Gender: Male
Posts: 9,395
 
Device(s): Motorola® DROID® BIONIC®
Carrier: VZW

Thanks: 2,168
Thanked 1,919 Times in 1,362 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.9.0 | Motorola RSD Lite v5.7
My DropBox Referral link
johnlgalt is offline  
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: 758
 
Device(s): Samsun Galaxy Nexus (Verizon)
Carrier: Not Provided

Thanks: 73
Thanked 682 Times in 272 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)
Senior Member
 
9to5cynic's Avatar
 
Join Date: Feb 2011
Location: /home/
Posts: 4,858
 
Device(s): Galaxy S3 (Verizon) Evo 4G - retired/rooted
Carrier: Verizon

Thanks: 3,066
Thanked 1,763 Times in 1,189 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
Thread Author (OP)
 
ardchoille's Avatar
 
Join Date: Mar 2011
Location: Seattle
Gender: Male
Posts: 3,684
 
Device(s):
Carrier: Not Provided

Thanks: 1,957
Thanked 1,959 Times in 856 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: 214
 
Device(s): Samsung Galaxy S3 LTE i9305
Carrier: Not Provided

Thanks: 12
Thanked 39 Times in 28 Posts
Default

Cracking well done
Haggistech is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Forums Community > The Lounge > Computers & IT
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 08:54 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.