#!/bin/sh
#-------------------------------------------------------------------------------
# All Rights Reserved, Copyright (C) 2008, NEC Soft, Ltd.
# ++
# Facility :	
# History  :
#     2008/03/10               first written by Ryuu Konn
#     2008/05/26   [Li Jian]   Use parameter to specify which target to convert.
#-------------------------------------------------------------------------------
PATH=$PATH:/home/witchymail/wm_current/sbin
#-------------------------------------------------------------------------------
DIR=`dirname $0`
METAFAILED="/tmp/metafailed.txt"

DO_SYS=0
DO_WM_CURRENT=0
DO_DATA=0

help() {
	cat <<"HELP" | sed -e "s#\$0#$0#g"
Usage: $0 <command>
Commands:
    sys                    Convert system files in sys/.
    wm_current             Convert configuration files in wm_current/.
    data                   Convert user data in data/.
    all                    Convert all above.
Example:
    $0 all                 Convert system files, configuration files and user data.
    $0 data                Convert user data only.
    $0 sys wm_current      Convert system files and configuration files.
HELP
}

if [ $# = 0 ]; then
	help
	exit 1
fi

for i in "$@"; do
	OPTION=`echo "$i" | tr A-Z a-z`
	case "$OPTION" in
	all)
		DO_SYS=1
		DO_WM_CURRENT=1
		DO_DATA=1
		;;
	sys)
		DO_SYS=1
		;;
	wm_current)
		DO_WM_CURRENT=1
		;;
	data)
		DO_DATA=1
		;;
	esac
done

if [ -f "$METAFAILED" ]; then
	rm -f $METAFAILED
fi

if [ $DO_SYS = 1 ]; then
	wms_metadata_enc_sys
fi

if [ $DO_WM_CURRENT = 1 ]; then
	wms_metadata_enc_wm_current
fi

if [ $DO_DATA = 1 ]; then
	wms_metadata_enc_data
fi

# check if anything failed
if [ -s "$METAFAILED" ]; then
	echo Some files could not be converted. See "$METAFAILED" for details.
fi

