Restructure repo layout and document conventions

Move legacy systemscripts into scripts/display and scripts/setup.
Rehome stray top-level tools into their domain folders.
Archive narrow experiments and outdated codegrab leftovers.
Remove empty legacy directories and stale root files.
Expand macOS metadata ignores and update the README with the refined repository structure.
This commit is contained in:
tke
2026-03-07 18:54:32 +01:00
parent cf17b37a7d
commit fd515742b5
27 changed files with 170 additions and 359 deletions

View File

@@ -0,0 +1,50 @@
#!/bin/bash
# Function to get size of file or block device
get_size() {
if [ -b "$1" ]; then # Check if input is a block device
size=$(sudo blockdev --getsize64 "$1")
else # Assume input is a file
size=$(stat --format="%s" "$1")
fi
echo $size
}
# Check if at least two arguments are provided
if [ $# -lt 2 ]; then
echo "Usage: $0 <source> <target> [test count]"
exit 1
fi
source="$1"
target="$2"
count="${3:-100}" # Default to 100 tests if not specified
# Ensure the source and target exist
if [ ! -e "$source" ] || [ ! -e "$target" ]; then
echo "Error: Source or target does not exist."
exit 1
fi
size=$(get_size "$source") # Get size in bytes
if [ $? -ne 0 ] || [ -z "$size" ] || [ "$size" -eq 0 ]; then
echo "Error: Failed to get size of the source."
exit 1
fi
interval=$((size / count))
for ((i=0; i<count; i++)); do
offset=$((i * interval))
percent=$((i * 100 / count))
# Use printf to overwrite the current line with the offset and percentage
printf "\r%$(tput cols)s\rComparing at offset $offset... (${percent}%%)"
if ! cmp --bytes=1M "$source" "$target" --ignore-initial=$offset > /dev/null 2>&1; then
echo -e "\nMismatch or error at offset $offset"
exit 1 # Exit after the first mismatch
fi
done
# Clear the line after the loop finishes successfully and print success message
printf "\r%$(tput cols)s\r"
echo "No mismatches found."

57
tools/hashing/trunc_by_hash.py Executable file
View File

@@ -0,0 +1,57 @@
import hashlib
import sys
# trunc_by_hash.py
# This script is a tool to verify the hash of a file and truncate it based on the hash value. It accepts two command line arguments: a expected hash value and a file path. The expected hash value is used to identify the hash type and the file path is the path to the file that needs to be verified and truncated.
# The script supports the following hash types: md5, sha1, sha224, sha256, sha512, sha3_224, sha3_384, and sha3_512. If the length of the expected hash is not one of these, the script will return an error message.
# The script verifies the hash of the file by reading it byte by byte and updating the hash. It will exit as soon as the hash matches the expected hash. The length of the matching file is returned.
# If the hash verification is successful, the script will print out the matching file length and an example command line to truncate the file using the 'head' command in Linux.
#
# Usage: python trunc_by_hash.py <expected_hash> <file_path>
#
# Example:
# python trunc_by_hash.py a0c1088973901485715076c131029c1c5d57998d783fe9fec4fd9920ad94f282 file.dat
def verify_file_hash(file_path, expected_hash):
hash_functions = {
32: hashlib.md5,
40: hashlib.sha1,
56: hashlib.sha224,
64: hashlib.sha256,
96: hashlib.sha512,
128: hashlib.sha3_224,
160: hashlib.sha3_384,
256: hashlib.sha3_512,
}
hash_function = hash_functions.get(len(expected_hash))
if hash_function is None:
print('Error: Unsupported hash type')
return None
with open(file_path, 'rb') as f:
hash = hash_function()
print(f'Hash Type Identified: {hash.name}')
byte = f.read(1)
while byte:
hash.update(byte)
if hash.hexdigest() == expected_hash:
return f.tell()
byte = f.read(1)
return None
if __name__ == '__main__':
if len(sys.argv) != 3:
print('Usage: python trunc_by_hash.py <expected_hash> <file_path>')
sys.exit(1)
expected_hash = sys.argv[1].lower()
file_path = sys.argv[2]
matching_length = verify_file_hash(file_path, expected_hash)
if matching_length is None:
print('Hash verification failed.')
else:
print('Hash verification succeeded. Matching file length: {} bytes'.format(matching_length))
print(f'Example tail command: head -c {matching_length} {file_path} > truncated_file')