#!/usr/bin/python
# -*- coding: utf-8 -*-

from preupg.script_api import *

"""Preupgrade Assistant performs system upgradability assessment
and gathers information required for successful operating system upgrade.
Copyright (C) 2013 Red Hat Inc.
Renaud Métrich <rmetrich@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/>."""
check_applies_to (check_applies="java-1.8.0-ibm")
#END GENERATED SECTION

import os
from shutil import copy2

# This script will be used during pre-upgrade section of redhat-upgrade-tool
# when 'java-1.8.0-ibm' is found.
PRE_UPGRADE_SCRIPT = "remove-java-1.8.0-ibm-pre-upgrade.sh"
PRE_UPGRADE_DIR    = os.path.join(VALUE_TMP_PREUPGRADE, "preupgrade-scripts")

##############################################################################
##### MAIN #####
##############################################################################

log_high_risk("The java-1.8.0-ibm package is installed."
              " Remove it before the in-place upgrade.")
solution_file("The java-1.8.0-ibm package is installed and conflicts with"
              " the upgrade. Remove the package before the upgrade.\n")

# add pre-upgrade check script, which check, that package was really
# removed before upgrade - otherwise user can't continue in upgrade.
copy2(PRE_UPGRADE_SCRIPT, PRE_UPGRADE_DIR)
os.chmod(os.path.join(PRE_UPGRADE_DIR, PRE_UPGRADE_SCRIPT), 0o775)

exit_fail()
