#!/bin/bash


#Preupgrade Assistant performs system upgradability assessment
#and gathers information required for successful operating system upgrade.
#Copyright (C) 2013 Red Hat Inc.
#Petr Stodulka <pstodulk@redhat.com>
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.
. /usr/share/preupgrade/common.sh
#END GENERATED SECTION


CLEANCONFD="$VALUE_TMP_PREUPGRADE/cleanconf"
DIRTYCONFD="$VALUE_TMP_PREUPGRADE/dirtyconf"


setrconf=/etc/setroubleshoot/setroubleshoot.cfg
result=$RESULT_PASS

check_dirty() {
  [ -f "${DIRTYCONFD}${1}" ] && {
    log_debug "The $1 file was previously stored in the dirtyconf file. It will be removed and stored in the cleanconf file."
    rm -f "${DIRTYCONFD}${1}"
  }
}

grep -q "${setrconf}" $VALUE_CONFIGCHANGED && {
  #TODO: add check that file is owned by native rpm
  result=$RESULT_FIXED
  log_slight_risk "The /etc/setroubleshoot/setroubleshoot.cfg configuration file has been renamed on the new system to '/etc/setroubleshoot/setroubleshoot.conf'."
  cp -a --parents $setrconf ${CLEANCONFD}${setrconf%.cfg}.conf
  check_dirty "${setrconf}"

  cat > solution.txt  <<EOF
The /etc/setroubleshoot/setroubleshoot.cfg configuration file has been renamed on the new system to '/etc/setroubleshoot/setroubleshoot.conf'.
The renamed file can be migrated automatically, so it is backed up to '$CLEANCONFD' and removed from '$DIRTYCONFD'.
EOF
}

for i in /etc/selinux/targeted/setrans.conf /etc/selinux/restorecond.conf; do
  grep -q "$i" $VALUE_CONFIGCHANGED && {
    cp -a --parents "$i" "${CLEANCONFD}${i}"
    check_dirty "$i"
  }
done

exit $result
