#! /bin/sh

# (c) 2001-2002, Thomas Lange
#
# set link for tftpboot in /srv/tftp/fai to an image for a host
# or for all hosts with prefix and a number

# examples:
# tlink installimage bigfoot
# tlink installimage ant06
# tlink installimage all ant
# tlink nodeimage all ant
#
# tlink             shows all file in /srv/tftp/fai
# tlink ant01       shows syslink for ant01

version="Version 1.1 10-jan-2002"

# define the range for client numbers using prefix
startnum=1
endnum=25

image=$1
host=$2
prefix=$3

tftpdir=/srv/tftp/fai
# - - - - - - - - - - - - - - - - - - - -
usage() {

cat <<EOF
tlink:  make symbolic link for booting network card via TFTP and BOOTP. $version

  Copyright (C) 2001-2002 by Thomas Lange

Usage: tlink [bootimage] [all] [hostname|prefix]

The list of all hosts is specified in the script itself.

Examples:
    tlink                             shows all files in /srv/tftp/fai
    tlink atom02                      shows symlink of host atom02
    tlink atom_install atom02         host atom02 will boot image atom_install
    tlink atom_local atom02           host atom02 will boot image atom_local
    tlink atom_install all atom       all hosts with prefix atom will use atom_install

EOF
exit 0
}
# - - - - - - - - - - - - - - - - - - - -
link() {

    	rm -f $ $tftpdir/$1
	ln -s $image $tftpdir/$1 && echo $1 now booting $image
}
# - - - - - - - - - - - - - - - - - - - -
showlink() {

    # show current link for host

    ls -l $tftpdir/$1
    exit 0
}
# - - - - - - - - - - - - - - - - - - - -

[ X"$1" = X ] && usage

# create list of host numbers
hostnums=`seq -w $starnum 1 $endnum`

# show one or all files
[ X"$host" = X ] && showlink $1

if [ $host = "all" ];then
    for i in $hostnums
    do
	link $prefix$i
    done
    exit
else
    link $host
fi
