archive tools with -y switch to answer yes

This commit is contained in:
Q
2020-01-12 23:18:15 +02:00
parent 473b337a38
commit 045106a3a5
2 changed files with 14 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ function helpexit() {
echo "Usage: $BS [-z/-n/--rm]"
echo " -z Compress."
echo " -n No compression. [default]"
echo " -y Dont ask before starting the archival."
echo " --rm Remove source folders after archival."
exit
@@ -59,9 +60,11 @@ NOCOMPRESSION=1
COMPRESSION=0
SUFFIX=tar
REMOVE=0
YES=0
for ((i=1; i<=${#@}; i++)) {
[[ "${!i}" = "-h" ]] && helpexit
[[ "${!i}" = "--help" ]] && helpexit
[[ "${!i}" = "-y" ]] && { YES=1; continue; }
[[ "${!i}" = "-z" ]] && { COMPRESSION=1; NOCOMPRESSION=0; COMPRESSCMD="| gzip"; SUFFIX=tgz; continue; }
[[ "${!i}" = "--rm" ]] && { REMOVE=1; continue; }
[[ "${!i}" = "-"* ]] && helpexit
@@ -83,8 +86,10 @@ echo -n $S"Archive the following files to '$archive_name' "
}
echo $Z
for file in "${REALFILES[@]}"; do echo "'$file'"; done
if [[ $YES -eq 0 ]]; then
printf "$S<ctrl-c> to quit$Z\n"
read foo
fi
set -o pipefail
SIZE=$( find "${REALFILES[@]}" -type f -printf %s"\n" | count_size )

View File

@@ -9,6 +9,7 @@ function helpexit() {
echo "Usage: $BS [-z/-n/--rm] [folder name(s)]"
echo " -z Compress."
echo " -n No compression. [default]"
echo " -y Dont ask before starting the archival."
echo " --nl Do not store a separate file list."
echo " --rm Remove source folders after archival."
echo " folder name: If given, archive only the named folder(s)."
@@ -65,10 +66,12 @@ DEPTH=1
FOLDERS=( )
REMOVE=0
KEEP_LIST=1
YES=0
for ((i=1; i<=${#@}; i++)) {
[[ "${!i}" = "-h" ]] && helpexit
[[ "${!i}" = "--help" ]] && helpexit
[[ "${!i}" = "-n" ]] && { continue; } # obsolete behaviour
[[ "${!i}" = "-y" ]] && { YES=1; continue; }
[[ "${!i}" = "-z" ]] && { COMPRESSION=1; NOCOMPRESSION=0; COMPRESSCMD="| gzip"; SUFFIX=tgz; continue; }
[[ "${!i}" = "--nl" ]] && { KEEP_LIST=0; continue; }
[[ "${!i}" = "--rm" ]] && { REMOVE=1; continue; }
@@ -91,8 +94,10 @@ echo -n $S"Archive the following folders "
}
echo $Z
for folder in "${REALFOLDERS[@]}"; do echo "'$folder'"; done
if [[ $YES -eq 0 ]]; then
printf "$S<ctrl-c> to quit$Z\n"
read foo
fi
set -o pipefail
for d in "${REALFOLDERS[@]}"; do