#!/bin/bash

#Preupgrade Assistant performs system upgradability assessment
#and gathers information required for successful operating system upgrade.
#Copyright (C) 2013 Red Hat Inc.
#Jakub Mazanek <jmazanek@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
check_applies_to "samba-common"
#END GENERATED SECTION
rpm -q samba > /dev/null
if [ $? -ne 0 ];then
    exit $RESULT_NOT_APPLICABLE
fi
POSTUPGRADE_DIR="$POSTUPGRADE_DIR/smb"

if [[ ! -d "$POSTUPGRADE_DIR" ]]; then
    mkdir -p "$POSTUPGRADE_DIR"
fi

SCRIPT_NAME="postupgrade_smb.sh"
POST_SCRIPT="postupgrade.d/$SCRIPT_NAME"
SMB_CFG=$(smbstatus -v | awk -F' = ' '$1 == "using configfile" { print $2 }')

cp -f $POST_SCRIPT $POSTUPGRADE_DIR/$SCRIPT_NAME
sed -i "s;PLACEHOLDER;$SMB_CFG;" $POSTUPGRADE_DIR/$SCRIPT_NAME

log_slight_risk "The SMB1 protocol is deprecated and it is replaced by SMB2."
log_medium_risk "Certain samba configuration settings from the source system might be deprecated on the target system service."

echo "The post upgrade script will test the validity of your current configuration options on the CentOS 7 system.
For more detailed information including new default configuration values, run the following command after the upgrade:
# testparm -s -v -d 3 $SMB_CFG" >> "$SOLUTION_FILE"

exit $RESULT_FAIL
