feat: Add variable name_suffix; Pass shellcheck; Discard useless variables from main script

This commit is contained in:
ge
2022-06-29 21:27:35 +03:00
parent 3d514678e7
commit aaa7a5c2d3
11 changed files with 177 additions and 147 deletions

View File

@ -26,16 +26,17 @@ handler::tar() {
local uri
local src_path
local dst_path
local opts
local archive
local exclude
local file_ext
uri="$1"
# shellcheck disable=SC2154
dst_path="$__main_target_path"
parse_uri "$uri"
# shellcheck disable=SC2154
if [ -f "$path" ] || [ -d "$path" ]; then
src_path="$path"
else
@ -51,15 +52,8 @@ handler::tar() {
# Exit if tar is not installed
is_installed tar
# Overwrire __tar_options
if [ -n "$tar_options" ]; then
opts="$tar_options"
else
opts="$__tar_options"
fi
# Overwrite __tar_exclude
if [ "$tar_exclude" ]; then
# Set tar_exclude
if [ -n "$tar_exclude" ]; then
for item in "${tar_exclude[@]}"; do
exclude+=" --exclude $item"
done
@ -67,6 +61,9 @@ handler::tar() {
exclude=
fi
# Set options
tar_options="${tar_options:--acf}"
# Select filename extension by compression type.
if [ "$compression" ]; then
# Make sure for the `--auto-compress` is enabled in __tar_options
@ -99,14 +96,14 @@ handler::tar() {
[ "$__verbose" ] && {
echo "Source path: $src_path"
echo "Destination path: $dst_path"
echo "Run command: tar $exclude $opts $archive $src_path"
echo "Run command: tar $exclude $tar_options $archive $src_path"
}
log "Archiving $src_path to $archive ..."
log "Run command: tar $exclude $opts $archive $src_path"
log "Run command: tar $exclude $tar_options $archive $src_path"
# Run tar
try tar "$exclude" "$opts" "$archive" "$src_path"
try tar "$exclude" "$tar_options" "$archive" "$src_path"
# Append path to 'backups' array
backups+=("$archive")