#!/bin/sh
#  Copyright 2007, One Laptop per Child
#  Author: John Watlington
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public License
# as published by the Free Software Foundation; either version 2
# of the License, 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 Library General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

# list_registration [<database>]
# This script lists the entries in the registration database
# If a database file is indicated, it is used, otherwise the default
# system database is used.
#
if [ $# -gt 0 ]; then
    DATABASE=$1
else
    DATABASE=/home/idmgr/identity.db
fi

if ! [ -r "$DATABASE" ]; then
	echo "ERROR: Can't read $DATABASE" >&2
	echo "Maybe you need to run as root?" >&2
	exit 1
fi

echo "Listing students from " $DATABASE
sqlite3 $DATABASE "select nickname, serial, full_name from laptops" | sed "y/|/\t/"

