Added basic error handling to nyan.

in-use
Emily Frost 5 years ago
parent 702db3c75c
commit b2461a7b89
Signed by: Emily
GPG Key ID: AA5D42849F1CBDC9

26
nyan

@ -1,6 +1,8 @@
#!/bin/bash #!/bin/bash
optstring="o:" optstring="o:"
input_files="" declare -i abort=0
# TODO: Check for dependencies pv and stat.
while getopts ${optstring} args; do while getopts ${optstring} args; do
case $args in case $args in
@ -8,20 +10,28 @@ while getopts ${optstring} args; do
:) echo "Output file required." ;; :) echo "Output file required." ;;
esac esac
done done
shift $((OPTIND-1)) shift $((OPTIND-1))
echo $output_file
echo "Concatenating files..." echo "Concatenating files..."
declare -i total_size=0 declare -i total_size=0
for fname in "$@"; do for fname in "$@"; do
#TODO: Make sure this file exists and isn't a directory! if [ ! -e "$fname" ]; then
abort=1
echo "${fname} does not exist."
elif [ -d "$fname" ]; then
abort=1
echo "${fname} is a directory."
else
current_file_size=$(stat -c%s "$fname") current_file_size=$(stat -c%s "$fname")
let total_size=$total_size+$current_file_size total_size=$((total_size+current_file_size))
echo "${fname} is ${total_size}b and valid." # TODO: Use something more legible than bytes.
echo "Adding ${fname} at ${total_size}b."
fi
done done
if [ $abort -eq 0 ]; then
cat "$@" | pv -epts "$total_size" > "$output_file" cat "$@" | pv -epts "$total_size" > "$output_file"
echo "Done!" echo "Done!"
else
echo "Errors occurred, concatenation aborted."
fi

Loading…
Cancel
Save