#! /bin/sh

# This script is responsible for providing processing
# that follows an upgrade on the HMC
# This scripts runs right after the upgrade data has been restored during
# boot

# Convert old-style UserLicence if enabled and it exists.
if [ -f /opt/hsc/data/user_license/.prompt_for_agreement ];then
   # Clean up old dot file.
   /bin/rm -f /opt/hsc/data/user_license/.prompt_for_agreement
   if [ -f /opt/hsc/data/user_license/UserLicense.html ];then
        /bin/cp /opt/hsc/data/user_license/UserLicense.html /opt/hsc/data/user_license/WelcomeFile.txt >/dev/null 2>&1
        /opt/hsc/bin/chusrtca -o a -f /opt/hsc/data/user_license/WelcomeFile.txt >/dev/null 2>&1
        /bin/rm -f /opt/hsc/data/user_license/UserLicense.html
        # Do not remove /opt/hsc/data/user_license/WelcomeFile.txt
        # Administrator may need to perform further work on the file.
   else
        for locale in `echo /opt/hsc/data/user_license/*`
        do
                if [ -f ${locale}/UserLicense.html ];then
                        /bin/cp ${locale}/UserLicense.html /opt/hsc/data/user_license/WelcomeFile.txt >/dev/null 2>&1
                        /opt/hsc/bin/chusrtca -o a -f /opt/hsc/data/user_license/WelcomeFile.txt >/dev/null 2>&1
                        /bin/rm -f ${locale}/UserLicense.html
                        /bin/rmdir ${locale} >/dev/null 2>&1
                        # Do not remove /opt/hsc/data/user_license/WelcomeFile.txt
                        # Administrator may need to perform further work on the file.
                        break;
                fi
        done
   fi
fi

# Remove all WebSM related files

for user in `echo /home/*`
do
 rm -f $user/WebSM.pref
 rm -f $user/websm.script
done
rm -f /var/websm/config*
rm -f /usr/websm/codebase/SMpubkr.zip
rm -rf /var/websm/security
grep -v "^SocketProvider" /opt/hsc/data/cim.properties > /tmp/_cim.properties_new
echo "SocketProvider=org.snia.wbemcmd.xml.PlainSocketProvider" >> /tmp/_cim.properties_new
mv /tmp/_cim.properties_new /opt/hsc/data/cim.properties

# Remove file used by websm client download
rm -f /usr/local/etc/httpd/*

# Now make sure permission are set correctly

chown -R ccfw.ccfw /var/hsc/profiles
chmod 400 /etc/shadow
/usr/sbin/usermod -G ccfw,root,hmc ccfw >/dev/null 2>&1

# Now upgrade access control
if [ -f /opt/hsc/sbin/upgrole ]; then
   /opt/hsc/sbin/upgrole 2>/dev/null
   if [ $? -ne 0 ]; then
      echo "Upgrade of access control from previous version has failed."
      echo "You will need to manually configure your access control."
   fi
fi


exit 0
