#!/bin/sh

# 
# Little helper to split NfSen-1.1 old style directory layout to 
# NfSen > 1.2.x new layout

#
# **** Note *****
# this script does not support sub Directory hierarchy levels
# which means, the converted new layout will be flat
# therfore set SUBDIRHIERARCHY = 0 in nfsen.conf
#
# set this to the old profile dir, which was $BASEDIR/profiles
OLDPROFILES='/data/nfsen/profiles'

# set these to the new values
PROFILESTATDIR='/data/nfsen/p1/profiles'
PROFILEDATADIR='/data/nfsen/p2/profiles'

# run the script
#
# nothing to change beyong this line
####################################

for entry in `/bin/ls $OLDPROFILES`; do
	if [ ! -d "$OLDPROFILES/$entry" ]; then
		continue
	fi

	if [ ! -f "$OLDPROFILES/$entry/profile.dat" ]; then
		continue
	fi

	echo "# Split profile $entry"
	echo "test -d $PROFILESTATDIR/$entry || mkdir -p $PROFILESTATDIR/$entry"
	echo mv -p "$OLDPROFILES/$entry/profile.dat" "$PROFILESTATDIR/$entry"
	echo mv -p "$OLDPROFILES/$entry/*rrd" "$PROFILESTATDIR/$entry"
	echo mv -p "$OLDPROFILES/$entry/*gif" "$PROFILESTATDIR/$entry"

	filterfile=''
	if [ -f "$OLDPROFILES/$entry/filter.txt" ]; then
		filterfile="$OLDPROFILES/$entry/filter.txt"
	fi

	if [ -f "$OLDPROFILES/$entry/history_filter.txt" ]; then
		filterfile="$OLDPROFILES/$entry/history_filter.txt"
	fi

	echo "test -d $PROFILEDATADIR/$entry || mkdir -p $PROFILEDATADIR/$entry"
	if [ "X$filterfile" != "X" ]; then
		echo mv -p "$filterfile" "$PROFILEDATADIR/$entry"
	fi

	for dir in `/bin/ls $OLDPROFILES/$entry`; do
		if [ -d "$OLDPROFILES/$entry/$dir" ]; then
			echo mv -p "$OLDPROFILES/$entry/$dir" "$PROFILEDATADIR/$entry"
		fi
	done
	echo

done
