Home
Man
Search
Today's Posts
Register

OS X is a line of Unix-based graphical operating systems developed, marketed, and sold by Apple.

SHA1 verification script

Tags
bash, mac os, openssl, sha1, sha1sum

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 02-15-2017
Apple SHA1 verification script

Hi guys!

Me again! ...
I'm trying to build (on MacOS directly) a bash script that will help me verify a SHA1 digest (to verify downloads and so on and so forth).

So first off, here's my version of BASH under OSX:
Code:
bash-4.4$

And here's my version of Sierra (macOS):
Code:
10.12.3 (16D32)

and last but not least, here's my code:

Code:
#!/usr/local/bin/bash

declare sha1=""
declare PATH=""
declare verifySha=""

echo
echo
echo
echo " Please enter the path to the file you want to check:"
read PATH
echo
echo " Now the SHA1 provided by the publisher:"
read sha1
echo
echo
verifySha=$(openssl sha1 $PATH)
if [ $sha1 -eq $verifySha ]
then
        echo "OK, same here!"
        echo
        echo
else
        echo "Not the same, try again!"
        echo
        echo
fi



Now, I know that $sha1 and $verifySha will not be the same for now... I need a sed in the middle to extract the sha signature.
But, aside from this minor problem that I will fix soon, I get the error:
Code:
./shaVerif.sh: line 17: openssl: command not found
./shaVerif.sh: line 18: [: 7798b65ae8842768bd2ff068545e0a3fc2dd0140: unary operator expected

Anyone has any idea why the openssl command does not work in a bash script? (Obviously, when I try to pass the command outside of the script, it works!).
# 2  
Old 02-15-2017
  1. declare PATH="" GULP, this removes all the paths to any executables.
  2. [ $sha1 -eq $verifySha ] should read [ "$sha1" = "$verifySha" ] .
This is just a starter, I have not checked your logic, but this should help you out at least...

Last edited by rbatte1; 02-15-2017 at 10:36 AM.. Reason: Converted textual list to formatted numbered list and corrected spellings
# 3  
Old 02-15-2017
As wisecracker said, openssl is not found because you removed the PATH info that bash uses to find commands. Use a different file name or - less recommendable - the absolute path to openssl.
With bash 4.4 you should be able to use "here strings"; no need to use sed or other. Try:
Code:
read dummy verifySha <<< $(openssl sha1 $FILEPATH)

Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Field verification script help galford Shell Programming and Scripting 2 10-31-2013 04:32 PM
Verification on shell script nimafire Shell Programming and Scripting 8 09-23-2013 09:29 AM
Script Verification k33k00 Shell Programming and Scripting 1 04-07-2012 08:32 AM
sha1 question locoroco Shell Programming and Scripting 12 03-07-2011 01:07 AM
Script for verification of Data corruption manish_tcs_hp Shell Programming and Scripting 4 12-07-2010 09:14 PM
SHA1 hash calculation ahsaas42 Programming 4 07-03-2010 03:35 PM
parse csv file, sha1 hash and output FreddyG Shell Programming and Scripting 11 01-28-2009 01:17 PM
Email address verification script Ramdas Shell Programming and Scripting 4 01-15-2007 02:51 AM
Verification of a script already running - where to do it miwinter UNIX for Dummies Questions & Answers 2 08-07-2006 11:32 AM
verification? sheranjem UNIX for Dummies Questions & Answers 3 06-06-2005 02:08 PM


All times are GMT -4. The time now is 10:10 AM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password