From 29ede53675fa09eae13fe31985d291d4b0b42c5c Mon Sep 17 00:00:00 2001 From: markmental Date: Sun, 19 Oct 2025 14:41:30 +0000 Subject: [PATCH] Initial Commit --- .gitignore | 4 ++ README.md | 0 tux-pack | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 tux-pack diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..11dd44c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.tar.gz +*.tar.xz +*.zip + diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/tux-pack b/tux-pack new file mode 100755 index 0000000..06bd179 --- /dev/null +++ b/tux-pack @@ -0,0 +1,118 @@ +#!/usr/bin/env bash +# +# tux-pack — pseudo-OOP Bash archiver +# ----------------------------------- +# Usage: +# tux-pack +# tux-pack -e +# +# Examples: +# tux-pack myfolder tar.gz +# tux-pack -e myarchive.tar.xz +# + +set -euo pipefail + +declare -A TuxPack=( + [input]="" + [format]="" + [output]="" +) + +TuxPack.new() { + local input="$1" + local format="${2:-}" + TuxPack[input]="$input" + TuxPack[format]="$format" +} + +TuxPack.validate_input() { + [[ -e "${TuxPack[input]}" ]] || { + echo "Error: Input not found: ${TuxPack[input]}" >&2 + exit 1 + } +} + +TuxPack.pack() { + local input="${TuxPack[input]}" + local format="${TuxPack[format]}" + local base name + + base="$(basename "$input")" + name="${base%/}" + + case "$format" in + tar.gz) + TuxPack[output]="${name}.tar.gz" + echo "Creating ${TuxPack[output]}..." + tar -czf "${TuxPack[output]}" "$input" + ;; + tar.xz) + TuxPack[output]="${name}.tar.xz" + echo "Creating ${TuxPack[output]}..." + tar -cJf "${TuxPack[output]}" "$input" + ;; + zip) + TuxPack[output]="${name}.zip" + echo "Creating ${TuxPack[output]}..." + zip -qr "${TuxPack[output]}" "$input" + ;; + *) + echo "Error: Unsupported format '$format'" >&2 + exit 1 + ;; + esac + + echo "Done: ${TuxPack[output]}" +} + +TuxPack.extract() { + local archive="$1" + [[ -f "$archive" ]] || { + echo "Error: File not found: $archive" >&2 + exit 1 + } + + case "$archive" in + *.tar.gz) + echo "Extracting $archive..." + tar -xzf "$archive" + ;; + *.tar.xz) + echo "Extracting $archive..." + tar -xJf "$archive" + ;; + *.zip) + echo "Extracting $archive..." + unzip -q "$archive" + ;; + *) + echo "Error: Unsupported archive format." >&2 + exit 1 + ;; + esac + echo "Extraction complete." +} + +usage() { + echo "Usage:" + echo " tux-pack " + echo " tux-pack -e " + exit 1 +} + +# ------------------------- +# Runtime logic +# ------------------------- +if [[ $# -lt 2 ]]; then + usage +fi + +if [[ "$1" == "-e" ]]; then + TuxPack.extract "$2" +else + TuxPack.new "$1" "$2" + TuxPack.validate_input + TuxPack.pack +fi +