#!/bin/bash

# tidy_lsvpd_dbs - Tidy up lsvpd databases

# This file is part of the Linux lsvpd package.

# (C) Copyright IBM Corp. 2003, 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: tidy_lsvpd_dbs.in,v 1.6 2004/06/21 06:03:13 martins Exp $

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

PATH="/lib/lsvpd:/sbin:${PATH}" ; export PATH

vardir=/var/lib/lsvpd

# Ensure that update-lsvpd-db has been run.
[ -d "$vardir" ] || /sbin/update-lsvpd-db

# This is to workaround the fact that tar doesn't like filenames with
# colons in them, since it thinks that the things that precede colons
# are hostnames.  Later versions of update-lsvpd-db don't create
# directory names with colons in them, so this isn't an ongoing
# problem.
#
# This could be done in a post-install script but is more neatly done
# here, since it needs to be done on all platforms.
for i in "${vardir}/"device-tree-* ; do
    if [ -d "$i" -a ! -h "$i" ] ; then
	case "$i" in
	    *:*)
		mv "$i" $(echo "$i" | sed -e 's/://g')
	esac
    fi
done

# Now for what we really want...
tidy_subdirs "$vardir" "^device-tree-"
tidy_subdirs "$vardir" "^db-"
