checksum check utility - for all common file checksums
Intro
This small utility performs a file hash sum check, the search path is specified in the variable TARGET="$HOME/Downloads"
.
The usage is straight forward start the script with ./checksum.sh
or any other linux way.
Script
1#!/bin/sh
2# by matt | MIT | 2021
3set -Eeuo pipefail
4echo "CHECKSUM Check Utility"
5echo ""
6echo "Reads MD5 and and all SHA checksums."
7echo "The Script performs the following action in background"
8echo "command example: echo 'ee1a961c9e32d6652eecdedde870d601 *$HOME/Downloads/<Filename>' | <shasum>or<md5sum> -c"
9echo ""
10# checksum variable
11read -p "Enter checksum : " CHECKSUM
12# set Search Directory
13TARGET="$HOME/Downloads"
14read -p "Default Search Dir $HOME/Downloads , enter Keyword: " SEARCH_NAME
15FILE=$( find "$TARGET" -iname *"$SEARCH_NAME"* 2> /dev/null )
16# User Output
17if [[ -n "$FILE" ]]; then
18 echo "File Found, processing request..."
19else
20 echo "No match found, Script abort."
21 exit
22fi
23# Checksum Verification
24length=$(expr length "$CHECKSUM")
25if [ "$length" == 32 ]; then
26 echo "Checking MD5 checksum.."
27 echo $CHECKSUM' *'$FILE | md5sum -c
28else
29 echo "checking SHA checksum.."
30 echo $CHECKSUM' *'$FILE | shasum -c
31fi