Unix/Linux Go Back    


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

SHA1 verification script

OS X (Apple)


Tags
bash, mac os, openssl, sha1, sha1sum

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-15-2017   -   Original Discussion by Ardzii
Ardzii's Unix or Linux Image
Ardzii Ardzii is offline
Registered User
 
Join Date: Dec 2016
Last Activity: 24 February 2017, 7:52 AM EST
Posts: 19
Thanks: 19
Thanked 0 Times in 0 Posts
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 Unix and Linux 02-15-2017   -   Original Discussion by Ardzii
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 16 June 2018, 3:08 AM EDT
Location: Loughborough
Posts: 1,268
Thanks: 379
Thanked 344 Times in 269 Posts
  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 Unix and Linux 02-15-2017   -   Original Discussion by Ardzii
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 June 2018, 3:55 PM EDT
Location: Aachen, Germany
Posts: 12,919
Thanks: 429
Thanked 3,968 Times in 3,649 Posts
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
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 08:27 PM.