Last active
March 14, 2016 12:41
-
-
Save tripox/3c1a6247d4aa9fcdea24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Purpose: Compare a file sha512/md5 with a sha512/md5 string | |
# Usage: <file> <sha512/md5 string> | |
# Author: Mathias Larsen <tripox@tripox.dk> | |
bold=$(tput bold) | |
red=$bold$(tput setaf 1) | |
green=$bold$(tput setaf 2) | |
blue=$bold$(tput setaf 4) | |
reset=$(tput sgr0) | |
# Argument variables | |
file=$1 | |
user_input=`echo $2 | awk '{print tolower($0)}'` | |
# Exit if arguments are missing or argument 1 is not a file | |
[ ! -f $file ] && echo "${red}First argument must be a file!" && exit | |
[ -z $file ] && echo "${red}Missing file in 1st argument" && exit | |
[ -z $user_input ] && echo "${red}Missing checksum in 2nd argument" && exit | |
# Get checksum of file | |
checksum=`shasum -a 512 $file | cut -d " " -f1` && type=SHA512 | |
[ `echo $user_input | wc -c | cut -d " " -f7` == 33 ] && checksum=`md5 $file | cut -d " " -f4` && type=MD5 | |
# Match and output results | |
[ $checksum == $user_input ] && echo "${green}Everything is fine!${reset} \n" || echo "${red}Not matching!${reset} \n" | |
echo "${blue}Filename:${reset} $file" | |
echo "${blue}File checksum:${reset} $checksum ($type)" | |
echo "${blue}User input checksum:${reset} $user_input ($type)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment