OS X (Apple)

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

SHA1 verification script


👤 Login to reply

    #1  
Old 02-15-2017
Ardzii Ardzii is offline
Registered User
 
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!).
Sponsored Links
    #2  
Old 02-15-2017
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
  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 09:36 AM.. Reason: Converted textual list to formatted numbered list and corrected spellings
Sponsored Links
    #3  
Old 02-15-2017
RudiC RudiC is offline Forum Staff  
Moderator
 
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)

Sponsored Links
👤 Login to reply

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 03:32 PM
Verification on shell script nimafire Shell Programming and Scripting 8 09-23-2013 08:29 AM
Script Verification k33k00 Shell Programming and Scripting 1 04-07-2012 07:32 AM
Email address verification script Ramdas Shell Programming and Scripting 4 01-15-2007 01:51 AM
Verification of a script already running - where to do it miwinter UNIX for Dummies Questions & Answers 2 08-07-2006 10:32 AM



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

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





Not a Forum Member?
Forgot Password?