#!/bin/sh

#Copyright (C) 1999-2001 by  Sbastien Chaumat <schaumat@ens-lyon.fr>
#                        and Loc Prylli <lprylli@lhpca.univ-lyon1.fr>

#    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 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.

#    A copy of the GNU General Public License is available as
#    `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
#    or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html.  You
#    can also obtain it by writing to the Free Software Foundation, Inc.,
#    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

set -e

postinst=repli-postinst.diskless
scriptsdir=/export/install/scripts
model=pilot
targetbase=/export/diskless

host=`dialog --title "Host" --inputbox "Diskless Host Name" 10 60  2>&1 1> /dev/tty`
test -n "$host" || exit 1
MYHOSTNAME=$host
export MYHOSTNAME

kbd=`dialog --title "Configuration" --radiolist "Keyboard choice" 10 60 5 us clavier-us on fr-pc clavier-fr off uk clavier-uk off 2>&1 1> /dev/tty`

target=$targetbase/$host

dialog --title "confirm" --yesno "\n\nFaire la replication automatiquement?\n      (efface tout le disque)" 10 50

case $? in 
  0) 
    dialog --title "Danger" --yesno "\n\n    $target will be erased!!!! \n     Do you want to continue??" 10 50
    test $? = 0 || exit 1
    repli-install --master $model --diskless $host --nfsroot $target --real all || exit 1
    mkdir -p $target/etc/console-tools
    mkdir -p $target/etc/kbd
    cp  /usr/share/keymaps/i386/*/$kbd.*map.gz $target/etc/console-tools/default.kmap.gz
    cp  /usr/share/keymaps/i386/*/$kbd.*map.gz $target/etc/kbd/default.map.gz
    cp $scriptsdir/uname.so $target/root
    cp $scriptsdir/$postinst $target/root/repli-postinst
    cp $postinst $target/root/repli-postinst
    mount -t proc proc $target/proc
    cd $target/root && chroot $target /bin/bash /root/repli-postinst
    umount $target/proc
   ;;
esac

