#!/bin/sh

if [ -z "$1" ]; then
  cat<<-EOF >&2
	Usage: $0 CSVfile
	       $0 -a CSVfile		# for al
	Csv file should be the form of:
	   GroupName,UserName(email)
	EOF
  exit 1
fi
cd `dirname $0`/..
if ! . ./s4-funcs.sh; then
  echo "Cannot find s4-funcs.sh, which should be located in $mydir/.."
  exit 1
fi

target=$(cd `dirname "$1"`; pwd)/`basename $1`

query<<-EOF
	.mode csv
	CREATE TEMPORARY TABLE _gusers(gname, user, admin);
	.import $target _gusers
	REPLACE INTO grp SELECT * FROM _gusers;
	REPLACE INTO grp_adm SELECT * FROM _gusers WHERE admin LIKE 'admin';
EOF
