# get the lts.conf via tftp

# $filename comes from net-eth0.conf and is usually "/<path>/pxelinux.0".
# If it contains a path, we want to construct "/<path>/lts.conf".
# If it doesn't, we want just "lts.conf" without inserting a slash, as some tftp
# servers have problems with it. Finally, if $filename isn't set, we want to
# default to "/ltsp/i386/lts.conf".
if [ -n "$SERVER" ]; then
    # Prefer the kernel path from /proc/cmdline over $filename from DHCP
    boot_image=$(sed -n 's/.*BOOT_IMAGE=\([^[:space:]]*\).*/\1/p' /proc/cmdline)
    boot_image=${boot_image:-$filename}
    fileonly=${boot_image##*/}
    pathonly=${boot_image%$fileonly}
    lts_conf_temp=$(mktemp)
    tftp -m binary "$SERVER" -c get ${pathonly:-/ltsp/$(detect_arch)/}${LTSCONF:-"lts.conf"} $lts_conf_temp >/dev/null
    # only overwrite lts.conf if it has non-zero size.
    if [ -s "$lts_conf_temp" ]; then
        mv "$lts_conf_temp" /etc/lts.conf
    else
        rm "$lts_conf_temp"
    fi
fi

# Get the lts.conf vars into the environment
. /usr/share/ltsp/ltsp_config
