You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
996 B
Bash
44 lines
996 B
Bash
#!/bin/bash
|
|
optstring="o:"
|
|
declare -i abort=0
|
|
|
|
# TODO: Add help option to display usage.
|
|
# TODO: Consider a switch for per-file progress bars rather than a whole-operation one.
|
|
|
|
if [ ! -e "$(which pv)" ]; then
|
|
echo "Error: pv does not seem to be installed. Exiting."
|
|
exit 1
|
|
fi
|
|
|
|
while getopts ${optstring} args; do
|
|
case $args in
|
|
o) output_file=${OPTARG} ;;
|
|
:) echo "Output file required." ;;
|
|
esac
|
|
done
|
|
shift $((OPTIND-1))
|
|
|
|
echo "Concatenating files..."
|
|
declare -i total_size=0
|
|
for fname in "$@"; do
|
|
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")
|
|
total_size=$((total_size+current_file_size))
|
|
# TODO: Use something more legible than bytes.
|
|
echo "Adding ${fname} at ${total_size}b."
|
|
fi
|
|
done
|
|
|
|
if [ $abort -eq 0 ]; then
|
|
cat "$@" | pv -epts "$total_size" > "$output_file"
|
|
echo "Done!"
|
|
else
|
|
echo "Errors occurred, concatenation aborted."
|
|
fi
|