From d16f89c3016e8ff0da08a85e8d51b79b552a7c5c Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 27 Sep 2013 15:38:14 +0200 Subject: add core libs --- lib/core | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/core diff --git a/lib/core b/lib/core new file mode 100644 index 00000000..f6516b5e --- /dev/null +++ b/lib/core @@ -0,0 +1,32 @@ +#!/bin/sh + +# logging +msg() { printf "$@\n" >&2 ;} +info() { msg "** $@" ;} +error() { msg "!! $@" ;} +exists(){ type "$1" >/dev/null 2>/dev/null; } + +get_hostname(){ + # finds the current hostname + # if ENV HOSTN is set echo $HOSTN + # We try the following: + # $HOSTN + # $HOSTNAME + # hostname + # uci system.hostname + # /etc/hostname + # if everything fails, it returns 1 and prints 'unknown' + + if [ -n "${HOSTN:-}" ] ; then printf "${HOSTN:-}" + elif [ -n "${HOSTNAME:-}" ] ;then printf "$HOSTNAME" + elif exists hostname ; then printf "$(hostname)" + elif exists uci ; then printf "$(uci get system.@system[0].hostname)" + elif [ -e /etc/hostname ] ;then printf "$(cat /etc/hostname)" + else printf "unknown"; return 1 + fi + return 0 +} + +line_to_dot(){ + while read line; do printf .; done; +} -- cgit v1.2.3