From 967d2d6468dc4b1b0cfa7f859913e5ff2be0949f Mon Sep 17 00:00:00 2001 From: zacharias Date: Sun, 13 Apr 2025 13:35:32 +0200 Subject: [PATCH] initial commit --- PKGBUILD | 14 ++++++++++++++ comp.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 PKGBUILD create mode 100644 comp.sh diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..b2a9c87 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,14 @@ +# PKGBUILD +pkgname=comp +pkgver=1.0 +pkgrel=1 +pkgdesc="Simple folder compression with pv and pigz" +arch=('any') +license=('MIT') +deps=('tar' 'pv' 'pigz') +source=('comp') +mdsums=('SKIP') + +package() { + install -Dm755 "$srcdir/comp.sh" "$pkgdir/usr/bin/comp" +} diff --git a/comp.sh b/comp.sh new file mode 100644 index 0000000..ca6fec1 --- /dev/null +++ b/comp.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Usage: comp [output_fildename] + +# Check if input folder is provided +if [[ -z "$1" ]]; then + echo "Usage: comp [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!"