#!/bin/bash 
#
#      -*- OpenSAF  -*-
#
# (C) Copyright 2008 The OpenSAF Foundation
#
# 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. This file and program are licensed
# under the GNU Lesser General Public License Version 2.1, February 1999.
# The complete license can be accessed from the following location:
# http://opensource.org/licenses/lgpl-license.php
# See the Copying file included with the OpenSAF distribution for full
# licensing terms.
#
# Author(s): Ericsson AB
#
# Default implementation of SMF repository check

# FROM THE SMF SPECIFICATION;
# 4.1.1 Upgrade Prerequisites
#
#   Before an upgrade campaign starts, the following prerequisites
#   must be checked at a minimum.
#
#    1. The Software Management Framework is operational.
#    2. The software repository is accessible.
#    3. There is no other upgrade campaign in progress.
#    4. The currently running version of the software is available in
#       the software repository.
#    5. The specifics of the upgrade campaign have been provided, and
#       the campaign is still applicable.
#    6. The desired version of the software is available in the
#       software repository, and all the dependencies of the required
#       packages have been checked and are satisfied.
#    7. All affected nodes must provide the resources (for instance,
#       sufficient disk space and proper access rights) needed to
#       perform the upgrade campaign.
#    8. The target system is in a state such that the expected service
#       outage does not exceed the acceptable service outage defined
#       for the campaign.
#    9. Upgrade-aware entities are ready for an upgrade campaign.
#   10. Any necessary backup is created.
#
#   If any of these checks fails, the upgrade campaign must not
#   start. If the upgrade campaign has been initiated, it must
#   terminate immediately. Note that after the correction of the
#   failed prerequisite, the campaign may be re-attempted.

# This script should check the repository according to item 2 above.

# About the "repository";
# The repository is assumed to be a locally accessible directory.
# Since nothing is specified about the location we require that the
# repository is defined by the $REPOSITORY environment variable for now.

prg=`basename $0`

die() {
    echo "ERROR: $@" >&2
    logger -t $prg -p user.err "ERROR ($cmd): $@"
    exit 1
}
log() {
    echo "$@"
    logger -t $prg -p user.debug "$@"
}

smfrc=${SMFRC:-/hostfs/smf.rc}
test -r $smfrc && . $smfrc

test -n "$REPOSITORY" || die 'Variable $REPOSITORY not set'
test -d $REPOSITORY || die "Not a directory [$REPOSITORY]"
exit 0

