initial commit

This commit is contained in:
2025-04-13 13:35:32 +02:00
commit 967d2d6468
2 changed files with 51 additions and 0 deletions

37
comp.sh Normal file
View File

@@ -0,0 +1,37 @@
#!/bin/bash
# Usage: comp <folder_to_compress> [output_fildename]
# Check if input folder is provided
if [[ -z "$1" ]]; then
echo "Usage: comp <folder_to_compress> [output_filename]"
exit 1
fi
INPUT_FOLDER="$1"
# Remove trailing slash from folder name if present
INPUT_FOLDER="${INPUT_FOLDER%/}"
# Determine output filename
if [[ -n "$2" ]]; then
OUTPUT_FILE="$2"
else
OUTPUT_FILE="${INPUT_FOLDER}.tgz"
fi
# Check if input is a valid directory
if [[ ! -d "${INPUT_FOLDER}" ]]; then
echo "Error: '${INPUT_FOLDER}' is not a valid directory"
exit 1
fi
# Get total zie in bytes for progress bar
TOTAL_SIZE=$(du -sb "${INPUT_FOLDER}" | awk '{print $1}')
# Run compression with progress bar
echo "Compressing '${INPUT_FOLDER}' to ' ${OUTPUT_FILE}'..."
tar -cf - "${INPUT_FOLDER} | pv -s "${TOTAL_SIZE}" | pigz > "${OUTPUT_FILE}"
echo "Done!"