#!/bin/bash
#
# Author: Honza Horak <hhorak@redhat.com>
#
# Description:
# This script just does a back-up of /var/yp/Makefile

. /usr/share/preupgrade/common.sh

#END GENERATED SECTION

. ../common.sh

CONFIG_FILE="/var/yp/Makefile"

backup_config "${CONFIG_FILE}" || exit $RESULT_NOT_APPLICABLE

# patch Makefile to apply changes we did in RHEL 7
TEST_DIR=$(pwd)
pushd "${VALUE_TMP_PREUPGRADE}/$(dirname $CONFIG_FILE)"
patch --no-backup-if-mismatch <"${TEST_DIR}/ypMakefile-rhel-7.patch"
if [ $? -ne 0 ] ; then
    read -r -d '' PROBLEM_DESC <<EOF
Fixing the ${CONFIG_FILE} file failed. You might have wrong MINUID/MINGID
definitions in that file, and YPPUSH_ARGS might be missing there.
EOF
    log_high_risk "${PROBLEM_DESC}"
    exit $RESULT_FAIL
else
    log_debug "Fixing the ${CONFIG_FILE} file succeeded."
    echo "
The ${CONFIG_FILE} file was fixed successfully in the ${VALUE_TMP_PREUPGRADE}/${CONFIG_FILE} file.
Copy it back manually after the upgrade.

" > solution.txt
fi
popd

exit $RESULT_FIXED

