diff --git a/scripts/xpress b/scripts/xpress new file mode 100755 index 00000000..1f6a0f4a --- /dev/null +++ b/scripts/xpress @@ -0,0 +1,67 @@ +#!/bin/bash + +# Error handling +set -e + +# For styling/colorizing output +txtbld=$(tput bold) +txtblue=${txtbld}$(tput setaf 4) +txtgreen=${txtbld}$(tput setaf 2) +txtred=${txtbld}$(tput setaf 1) +txtyellow=${txtbld}$(tput setaf 3) +txtwhite=${txtbld}$(tput setaf 7) + + +# To be implemented: +# dependencies=("echo" "sed" "tar" "zip" "bzip2" "gzip" "gunzip" "pax" "7z" "ar" "cpio" "brotli" "lzip" "rzip" "xz" "zstd") + +# Main Dependency check +dependencies=("echo" "sed" "tput") +numdependencies=3 +missingdependencies=0 +for ((i = 0; i < numdependencies; i++)) ; +do + if ! command -v "${dependencies[$i]}" &> /dev/null + then + echo "${txtred}dependency not met: ${dependencies[$i]}${txtwhite}" + missingdependencies=$((missingdependencies+1)) + fi +done + +# Intro Prompt +echo "${txtgreen}xpress: a simple shell script for compressing common file formats" + +# Reset output style +tput bold & tput setaf 7 + +# grabs the extension string +extension=$(echo "${1}" | sed 's/^[^\..:]*[\..]//') + +# grabs the filename/directoryname string +fdname=$(echo "${1}" | sed 's/\..*$//') + +# Simply copy and paste, changing extension string and extraction method below +if [ "${extension}" == "tgz" ] ; then + # Dependency check + dependencies=("echo" "tar" "gzip") + numdependencies=3 + missingdependencies=0 + for ((i = 0; i < numdependencies; i++)) ; + do + if ! command -v "${dependencies[$i]}" &> /dev/null + then + echo "${txtred}dependency not met: ${dependencies[$i]}${txtwhite}" + missingdependencies=$((missingdependencies+1)) + fi + done + + if [ $missingdependencies -gt 0 ] ; then + echo "${txtred}Please install needed dependencies${txtwhite}" + exit 1 + fi + + echo "${txtblue}compressing .tgz...${txtyellow}" + # main extraction method + tar -cvzf "${1}" "${fdname}" &> /dev/null + echo ".tgz compression finished!${txtwhite}" +fi diff --git a/scripts/xtract b/scripts/xtract index 4b13f643..6e6473ca 100755 --- a/scripts/xtract +++ b/scripts/xtract @@ -52,6 +52,11 @@ if [ "${extension}" == "tgz" ] ; then fi done + if [ $missingdependencies -gt 0 ] ; then + echo "${txtred}Please install needed dependencies${txtwhite}" + exit 1 + fi + echo "${txtblue}decompressing .tgz...${txtyellow}" # main extraction method tar zxvf "${1}" &> /dev/null