moved calls out of global space to main function, preparing for usage with strict mode

This commit is contained in:
sometimesuseful 2024-11-12 14:17:59 +00:00
parent e4bce4beef
commit a43d991a3b

View file

@ -1,12 +1,10 @@
#!/bin/bash
# This script packs a file or directory into a 7z archive with the given password.
# It can (optionally) split the archives into volumes of a fixed size in megabytes.
source colors.sh
source functions.sh
archive_dir="$(dirname "$0")/../archives"
input_file="${1}"
archive_pwd="${2}"
size="$3"
trap 'cleanup' EXIT
cleanup() {
[[ -n "$archive" ]] && rm -f "$archive*"
@ -72,10 +70,25 @@ create_archive() {
7z a -mhe=on "-p${archive_pwd}" "$volumes" "$archive" "${input_file}" >&2
}
trap cleanup 1 2 3 6
main() {
archive_dir="$(dirname "$0")/../archives"
input_file="${1}"
archive_pwd="${2}"
size="$3"
check_dependencies
check_input
set_volumes
generate_name
create_archive
check_dependencies
check_input
set_volumes
generate_name
create_archive
}
# Missing arguments must be caught here when using `set -e`, otherwise
# the script will exit prematurely without logging the error.
if (( $# == 3 )); then
main "$@"
else
log_err "Missing arguments"
exit 2
fi