# -*- shell-script -*-

# 41rtas_get_ibm_vpd - Fetch/update dynamic VPD on IBM pSeries when available.

# This file is part of the Linux lsvpd package.

# (C) Copyright IBM Corp. 2004

# Maintained by Martin Schwenke <martins@au.ibm.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 2, 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, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
# $Id: 41rtas_get_ibm_vpd,v 1.4 2004/06/18 07:00:02 martins Exp $

rtas_ibm_get_vpd=$(type -p rtas_ibm_get_vpd)

[ -f "${db_bus_dt_dir}/rtas/ibm,get-vpd" -a -n "$rtas_ibm_get_vpd" ] || \
    return 0

######################################################################

dynamic_vpd_hooks="${dynamic_vpd_hooks} rtas_ibm_get_vpd_hook"

rtas_ibm_get_vpd_hook ()
{
    if dynamic_vpd_ok ; then

	# FIXME: Could make this a symlink-based "method" and push the
	# work out to an external program.  However, this is pretty
	# simple.

	# Planning to remove old VPD.  Be very, very careful...
	local d="$db_bus_dt_dir"
	case "$d" in
	    (/*/${db_bus_dt_subdir}) : ;; # Sanity check.
	    *)
		: "Problem with dynamic VPD node: \"${d}\""
		return
	esac
	
	local t="${d}/${linux_dynamic_vpd}"
	local l="${d}/linux,vpd"
	
	[ -e "$l" -o -e "$t" ] && rm -rf "$l" "$t"
	
	if $rtas_ibm_get_vpd >"$t"  ; then
	    ibm_vpd_render "$t" "$d"
	else
	    rm -f "$t"
	fi
    fi
}
