| #!/bin/bash |
| |
| # @brief Packaging the dump, applying the header |
| # and transferring to dump location. |
| function custom_package() |
| { |
| tar -Jcf "$name_dir.bin" -C \ |
| "$(dirname "$name_dir")" "$(basename "$name_dir")" |
| # shellcheck disable=SC2181 # need output from `tar` in above if cond. |
| if [ $? -ne 0 ]; then |
| echo "$($TIME_STAMP)" "Could not create the compressed tar file" |
| rm -r "$name_dir.bin" |
| return "$INTERNAL_FAILURE" |
| fi |
| |
| echo "Adding Dump Header :"$HEADER_EXTENSION |
| ("$HEADER_EXTENSION") |
| |
| cat "$name_dir.bin" | tee -a "/tmp/dumpheader_$EPOCHTIME" > /dev/null |
| #remove the temporary name specific directory |
| rm -rf "$name_dir" |
| mv "/tmp/dumpheader_$EPOCHTIME" "$name_dir" |
| |
| echo "$($TIME_STAMP)" "Report is available in $dump_dir" |
| if [ "$TMP_DIR" == "$dump_dir" ] || [ "$TMP_DIR/" == "$dump_dir" ]; then |
| return "$SUCCESS" |
| fi |
| |
| #copy the compressed tar file into the destination |
| cp "$name_dir" "$dump_dir" |
| if [ $? -ne 0 ]; then |
| echo "Failed to copy the $name_dir to $dump_dir" |
| rm "$name_dir.bin" |
| return "$INTERNAL_FAILURE" |
| fi |
| |
| #Remove the temporary copy of the file |
| rm -rf "$name_dir.bin" "$name_dir" |
| } |
| |
| # Executing function |
| custom_package |