#!/bin/bash

# sourcing our current rc.conf requires this to be a bash script
. /usr/lib/rc/functions

config(){
    unset HOSTNAME

    if [[ -s /etc/hostname ]]; then
        HOSTNAME=$(< /etc/hostname)
    fi

    if [[ $HOSTNAME ]]; then
        echo "$HOSTNAME" >| /proc/sys/kernel/hostname
    fi
}

case "$1" in
    start)
        stat_busy "Setting hostname to $HOSTNAME"
        config
        add_daemon hostname
        stat_done
        ;;
    *)
        echo "usage: $0 {start}"
        exit 1
        ;;
esac
