From 48c241b38308baf097af2f415b5508ba6dc8e349 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 25 Jul 2024 17:41:18 -0400 Subject: [PATCH] added sha sums for verifiable updates via salt --- src/dockerutils.sh.sha256 | 1 + src/sum.sh | 41 +++++++++++++++++++++++++++++++++++++++ src/sum.sh.sha256 | 1 + sum.sh | 33 +++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 src/dockerutils.sh.sha256 create mode 100644 src/sum.sh create mode 100644 src/sum.sh.sha256 create mode 100755 sum.sh diff --git a/src/dockerutils.sh.sha256 b/src/dockerutils.sh.sha256 new file mode 100644 index 0000000..d74e023 --- /dev/null +++ b/src/dockerutils.sh.sha256 @@ -0,0 +1 @@ +a2577b1eb4dfc9dd142bc8bc91f6c569101eef61d1c47ddbd4e9625079fdb5a4 diff --git a/src/sum.sh b/src/sum.sh new file mode 100644 index 0000000..7169c99 --- /dev/null +++ b/src/sum.sh @@ -0,0 +1,41 @@ +# /etc/profile.d/sum.sh + +# Ensure the script is sourced +if [[ "${BASH_SOURCE[0]}" == "${0}" || "${(%):-%N}" == "$0" ]]; then + echo "This script should be sourced, not executed." + exit 1 +fi + +# Function to generate SHA-256 hashes for .sh files in a given directory +generate_sha256_hashes() { + local src_dir="$1" + + # Check if the directory exists + if [ ! -d "$src_dir" ]; then + echo "Directory $src_dir does not exist." + return 1 + fi + + # Determine the command to use for calculating SHA-256 + local hash_cmd + if command -v sha256sum >/dev/null 2>&1; then + hash_cmd="sha256sum" + elif command -v shasum >/dev/null 2>&1; then + hash_cmd="shasum -a 256" + else + echo "Neither sha256sum nor shasum command is available." + return 1 + fi + + # Loop through all .sh files in the directory + for file in "$src_dir"/*.sh; do + # Skip if no .sh files are found + [ -e "$file" ] || continue + + # Calculate the SHA-256 hash and save it to a .sha256 file + $hash_cmd "$file" | awk '{ print $1 }' > "$file.sha256" + done + + echo "SHA-256 hashes have been saved in .sha256 files." +} + diff --git a/src/sum.sh.sha256 b/src/sum.sh.sha256 new file mode 100644 index 0000000..ccdff62 --- /dev/null +++ b/src/sum.sh.sha256 @@ -0,0 +1 @@ +e92965ba035990ee5cb81afc1dda199949521264897f4ec37b99fe6a96c14344 diff --git a/sum.sh b/sum.sh new file mode 100755 index 0000000..c4561f1 --- /dev/null +++ b/sum.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Directory containing the .sh files +src_dir="./src" + +# Check if the directory exists +if [ ! -d "$src_dir" ]; then + echo "Directory $src_dir does not exist." + exit 1 +fi + +# Determine the command to use for calculating SHA-256 +if command -v sha256sum >/dev/null 2>&1; then + hash_cmd="sha256sum" +elif command -v shasum >/dev/null 2>&1; then + hash_cmd="shasum -a 256" +else + echo "Neither sha256sum nor shasum command is available." + exit 1 +fi + +# Loop through all .sh files in the directory +for file in "$src_dir"/*.sh; +do + # Skip if no .sh files are found + [ -e "$file" ] || continue + + # Calculate the SHA-256 hash and save it to a .sha256 file + $hash_cmd "$file" | awk '{ print $1 }' > "$file.sha256" +done + +echo "SHA-256 hashes have been saved in .sha256 files." +