1*24226c4fSGopichand Paturi#!/bin/bash
2*24226c4fSGopichand Paturi
3*24226c4fSGopichand Paturi# @brief Packaging the dump, applying the header
4*24226c4fSGopichand Paturi# and transferring to dump location.
5*24226c4fSGopichand Paturifunction custom_package()
6*24226c4fSGopichand Paturi{
7*24226c4fSGopichand Paturi    tar -Jcf "$name_dir.bin" -C \
8*24226c4fSGopichand Paturi        "$(dirname "$name_dir")" "$(basename "$name_dir")"
9*24226c4fSGopichand Paturi    # shellcheck disable=SC2181 # need output from `tar` in above if cond.
10*24226c4fSGopichand Paturi    if [ $? -ne 0 ]; then
11*24226c4fSGopichand Paturi        echo "$($TIME_STAMP)" "Could not create the compressed tar file"
12*24226c4fSGopichand Paturi        rm -r "$name_dir.bin"
13*24226c4fSGopichand Paturi        return "$INTERNAL_FAILURE"
14*24226c4fSGopichand Paturi    fi
15*24226c4fSGopichand Paturi
16*24226c4fSGopichand Paturi    echo "Adding Dump Header :"$HEADER_EXTENSION
17*24226c4fSGopichand Paturi    ("$HEADER_EXTENSION")
18*24226c4fSGopichand Paturi
19*24226c4fSGopichand Paturi    cat "$name_dir.bin" | tee -a "/tmp/dumpheader_$EPOCHTIME" > /dev/null
20*24226c4fSGopichand Paturi    #remove the temporary name specific directory
21*24226c4fSGopichand Paturi    rm -rf "$name_dir"
22*24226c4fSGopichand Paturi    mv "/tmp/dumpheader_$EPOCHTIME" "$name_dir"
23*24226c4fSGopichand Paturi
24*24226c4fSGopichand Paturi    echo "$($TIME_STAMP)" "Report is available in $dump_dir"
25*24226c4fSGopichand Paturi    if [ "$TMP_DIR" == "$dump_dir" ] || [ "$TMP_DIR/" == "$dump_dir" ]; then
26*24226c4fSGopichand Paturi        return "$SUCCESS"
27*24226c4fSGopichand Paturi    fi
28*24226c4fSGopichand Paturi
29*24226c4fSGopichand Paturi    #copy the compressed tar file into the destination
30*24226c4fSGopichand Paturi    cp "$name_dir" "$dump_dir"
31*24226c4fSGopichand Paturi    if [ $? -ne 0 ]; then
32*24226c4fSGopichand Paturi        echo "Failed to copy the $name_dir to $dump_dir"
33*24226c4fSGopichand Paturi        rm "$name_dir.bin"
34*24226c4fSGopichand Paturi        return "$INTERNAL_FAILURE"
35*24226c4fSGopichand Paturi    fi
36*24226c4fSGopichand Paturi
37*24226c4fSGopichand Paturi    #Remove the temporary copy of the file
38*24226c4fSGopichand Paturi    rm -rf "$name_dir.bin" "$name_dir"
39*24226c4fSGopichand Paturi}
40*24226c4fSGopichand Paturi
41*24226c4fSGopichand Paturi# Executing function
42*24226c4fSGopichand Paturicustom_package
43