1*a96df3e3SDeepa Karthikeyan#!/bin/sh 2*a96df3e3SDeepa Karthikeyan 3*a96df3e3SDeepa Karthikeyanbase_dir="/var/lib/phosphor-software-manager/hostfw" 4*a96df3e3SDeepa Karthikeyanro_dir="/media/hostfw/running-ro" 5*a96df3e3SDeepa Karthikeyanrunning_dir="${base_dir}/running" 6*a96df3e3SDeepa Karthikeyanfile_recovered=0 7*a96df3e3SDeepa Karthikeyan 8*a96df3e3SDeepa Karthikeyanif [ -f "${ro_dir}/81e00994.lid" ]; then 9*a96df3e3SDeepa Karthikeyan #look for the DEVTREE and the preserved files 10*a96df3e3SDeepa Karthikeyan filesList=$(grep 'PRESERVED\|DEVTREE' "${ro_dir}/81e00994.lid") 11*a96df3e3SDeepa Karthikeyan for eachFile in ${filesList}; do 12*a96df3e3SDeepa Karthikeyan eachFile=${eachFile##partition*=} 13*a96df3e3SDeepa Karthikeyan eachFile=$(echo "${eachFile}" | cut -d "," -f 1) 14*a96df3e3SDeepa Karthikeyan #check if it is a symbolic link 15*a96df3e3SDeepa Karthikeyan if [ -L "${running_dir}/${eachFile}" ]; then 16*a96df3e3SDeepa Karthikeyan # get the symlink target file 17*a96df3e3SDeepa Karthikeyan eachFile="$(readlink "${running_dir}/${eachFile}")" 18*a96df3e3SDeepa Karthikeyan if [ -f "${running_dir}/${eachFile}" ] && [ -f "${ro_dir}/${eachFile}" ]; then 19*a96df3e3SDeepa Karthikeyan runsize="$(stat -c '%s' "${running_dir}/${eachFile}")" 20*a96df3e3SDeepa Karthikeyan rosize="$(stat -c '%s' "${ro_dir}/${eachFile}")" 21*a96df3e3SDeepa Karthikeyan # Partition size may have changed or became corrupted 22*a96df3e3SDeepa Karthikeyan # restoring the file from the readonly copy 23*a96df3e3SDeepa Karthikeyan if [ "$runsize" != "$rosize" ]; then 24*a96df3e3SDeepa Karthikeyan cp -p ${ro_dir}/"${eachFile}" ${running_dir}/"${eachFile}" 25*a96df3e3SDeepa Karthikeyan # Log PEL to indicate such 26*a96df3e3SDeepa Karthikeyan busctl call xyz.openbmc_project.Logging \ 27*a96df3e3SDeepa Karthikeyan /xyz/openbmc_project/logging \ 28*a96df3e3SDeepa Karthikeyan xyz.openbmc_project.Logging.Create Create "ssa{ss}" \ 29*a96df3e3SDeepa Karthikeyan xyz.openbmc_project.Software.Version.Error.HostFile \ 30*a96df3e3SDeepa Karthikeyan xyz.openbmc_project.Logging.Entry.Level.Error 3 "FILE_NAME" \ 31*a96df3e3SDeepa Karthikeyan "${eachFile}" "CURRENT_FILE_SIZE" "${runsize}" "EXPECTED_FILE_SIZE" \ 32*a96df3e3SDeepa Karthikeyan "${rosize}" 33*a96df3e3SDeepa Karthikeyan 34*a96df3e3SDeepa Karthikeyan file_recovered=1 35*a96df3e3SDeepa Karthikeyan fi 36*a96df3e3SDeepa Karthikeyan fi 37*a96df3e3SDeepa Karthikeyan fi 38*a96df3e3SDeepa Karthikeyan done 39*a96df3e3SDeepa Karthikeyan #one or more files could be recovered. So trigger dump outside the while loop 40*a96df3e3SDeepa Karthikeyan if [ $file_recovered -eq 1 ]; then 41*a96df3e3SDeepa Karthikeyan # Initiate dump 42*a96df3e3SDeepa Karthikeyan busctl call xyz.openbmc_project.Dump.Manager \ 43*a96df3e3SDeepa Karthikeyan /xyz/openbmc_project/dump/bmc xyz.openbmc_project.Dump.Create \ 44*a96df3e3SDeepa Karthikeyan CreateDump "a{sv}" 0 45*a96df3e3SDeepa Karthikeyan fi 46*a96df3e3SDeepa Karthikeyanfi