diff --git a/.linux/bash/module/archive.sh b/.linux/bash/module/archive.sh index de4f595..1dbbde2 100644 --- a/.linux/bash/module/archive.sh +++ b/.linux/bash/module/archive.sh @@ -30,6 +30,9 @@ archive() # append hash to target name. mv "${target%/*}".tar.xz "${target%/*}"_${date}-$(sha1sum "${target%/*}".tar.xz | cut -d\ -f1).tar.xz + + # report success. + echo -e "${color_green}${status}: done.${color_default}" done } @@ -62,6 +65,9 @@ archive_fast() # append hash to target name. mv "${target%/*}".tar.gz "${target%/*}"_${date}-$(sha1sum "${target%/*}".tar.gz | cut -d\ -f1).tar.gz + + # report success. + echo -e "${color_green}${status}: done.${color_default}" done } @@ -100,15 +106,15 @@ archive_check() # compare hashes, show error on mismatch. if [[ "${actual}" = "${saved}" ]]; then - echo "${status}: OK." + echo "${status}: validation OK." else - echo -e "${color_red}${status}: failed.${color_default}" + echo -e "${color_bred}${status}: validation failed.${color_default}" ((failed++)) fi done # report result. - if [[ ${count} -gt 1 ]]; then + if [[ ${count} -gt 1 ]] || [[ "${*}" = "" ]]; then if [[ ${failed} -gt 0 ]]; then echo -e "${color_bred}Items failed to validate: ${failed}.${color_default}" else @@ -149,21 +155,28 @@ unarchive() # extract if hash matched or show error if not. if [[ "${saved}" = "${actual}" ]]; then echo "${status}: validation OK." + + # figure out the compression tool. + local compressor case "${target##*.}" in "xz") - pv "${target}" | xz -d | tar -xf - + compressor="xz -d" ;; "gz") - pv "${target}" | gzip -d | tar -xf - + compressor="gzip -d" ;; esac + + # extract. + pv "${target}" | ${compressor} | tar -xf - else - echo "${status}: validation failed." + # report validation error & exit. + echo -e "${color_bred}${status}: validation failed.${color_default}" return 1 fi # report extraction complete. - echo "${status}: done." + echo -e "${color_green}${status}: done.${color_default}" done } @@ -211,12 +224,12 @@ archive_name() # check for existing target. if [[ -f "${new_name}" ]]; then - echo -e "${color_red}${status}: already exists.${color_default}" + echo -e "${color_bred}${status}: already exists.${color_default}" return 1 fi # rename. - mv -- "${target}" "${new_name}" && echo "${status}" || echo -e "${color_red}${status}: error.${color_default}" + mv -- "${target}" "${new_name}" && echo "${color_green}${status}${color_default}" || echo -e "${color_bred}${status}: error.${color_default}" done }