removed check_dependencies in favor of functions.sh version, modified cleanup to use new log function, fixed trap signals

This commit is contained in:
sometimesuseful 2024-11-12 15:14:02 +00:00
parent 3c1060a84f
commit f363327a34

27
modules/archive.sh Executable file → Normal file
View file

@ -4,21 +4,12 @@
source colors.sh
source functions.sh
trap 'cleanup' EXIT
trap 'cleanup' ERR INT
cleanup() {
[[ -n "$archive" ]] && rm -f "$archive*"
echo "Cleaned up all $archive files" >&2
}
check_dependencies() {
if ! mkdir -p "$archive_dir"; then
echo "ERROR: Unable to create archive directory"
exit 1
elif ! command -v 7z 2>&1 >/dev/null; then
echo "ERROR: 7z must be installed"
exit 1
if [[ -n "$archive" ]]; then
rm -f "${archive}"*
log "INFO" "Cleaning up $(basename $archive) remains before exit"
fi
}
@ -76,7 +67,13 @@ main() {
archive_pwd="${2}"
size="$3"
check_dependencies
check_dependencies "7z"
if ! mkdir -p "$archive_dir"; then
log "ERROR" "Unable to create archive directory"
exit 1
fi
check_input
set_volumes
generate_name
@ -89,6 +86,6 @@ main() {
if (( $# == 3 )); then
main "$@"
else
log_err "Missing arguments"
log "ERROR" "Missing arguments"
exit 2
fi