Make sure we have a hostname when we grep for it

We attempt to set hostname in /etc/hosts if the hostname does not exist
there. However when the $HOSTNAME variable is empty we grep for
/etc/hosts from stdin which has no data. Check that $HOSTNAME is not
empty before we grep for it.

Change-Id: Ie35fd997f2f569ebea6614f91609281a991f8d6a