blob: 7e85110e67f815cf97bba7d5449409e72cbf6007 [file] [log] [blame]
#!/bin/bash
#CONSTANTS
declare -rx HEADER_EXTENSION="$DREPORT_INCLUDE/gendumpheader"
# @brief Packaging the dump, applying the header
# and transferring to dump location.
function custom_package()
{
FILE="/tmp/dumpheader_${dump_id}_${EPOCHTIME}"
echo "performing dump compression $name_dir"
if [ "$dump_type" = "$TYPE_FAULTDATA" ]; then
rm -rf $name_dir/dreport.log
rm -rf $name_dir/summary.log
tar -cf "$name_dir.bin" -C "$(dirname "$name_dir")" "$(basename "$name_dir")"
else
tar cf - -C "$(dirname "$name_dir")" "$(basename "$name_dir")" | zstd > "$name_dir.bin"
fi
# 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 "$FILE" > /dev/null
#remove the temporary name specific directory
rm -rf "$name_dir" "$name_dir.bin"
mv $FILE "$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"
return "$INTERNAL_FAILURE"
fi
#Remove the temporary copy of the file
rm -rf "$name_dir"
}
# Executing function
custom_package