Skip to content

Commit

Permalink
Added checksum api docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
wayneeseguin committed Mar 27, 2012
1 parent 1766ad9 commit 8c75b64
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions bin/checksum/type
@@ -0,0 +1,44 @@
#!/bin/sh

set -v # Turn on verbose logging, so that the following will present a tutorial.

# checksum(s) module api is loaded with the line 'api/checksum' in an
# extension's shell/includes file.

# First we declare the 'sum' variable, a string variable that we will use later
# to store a checksum in.
typeset sum

# First we generate a test file
file write string 'Chicken' to "/tmp/checksum-source-file"

# We will now run the checksum using a sha256 algorithm type, this will print the results to
checksum type sha256 file "/tmp/checksum-source-file"

# We will now run the checksum using a sha256 algorithm type and store it into
# the variable named 'sum'
checksum type sha256 file "/tmp/checksum-source-file" variable sum

# Notice that there was no output to STDOUT, now let's see what is in the
# variable 'sum'
log ${sum}

# We now calculate the checksum and store the result in a specified target file.
checksum type sha256 file "/tmp/checksum-source-file" \
to "/tmp/checksum-source-file.checksum"

# Notice that there was no output to STDOUT, now let's see what is in the
# file "/tmp/checksum-source-file"
cat "/tmp/checksum-source-file"

# Let's compare the checksum against the word 'narfnarf', this should not match.
if checksum type sha256 file "/tmp/checksum-source-file" checksum "narfnarf"
then log 'checksum matches!'
else log 'checksum does not match!' ; fi

# Now if we compare the checksum of the source file against the checksum
# computed earlier it should match.
if checksum type sha256 file "/tmp/checksum-source-file" checksum "${sum}"
then log 'checksum matches!'
else log 'checksum does not match!' ; fi

1 change: 1 addition & 0 deletions shell/includes
@@ -1,6 +1,7 @@
api/array api/array
api/command api/command
api/config api/config
api/checksum
api/dates api/dates
api/files api/files
api/interactive api/interactive
Expand Down

0 comments on commit 8c75b64

Please sign in to comment.