summaryrefslogtreecommitdiffstats
path: root/ship/lib/core
diff options
context:
space:
mode:
authortv <tv@nomic.retiolum>2013-11-05 12:45:53 +0100
committertv <tv@nomic.retiolum>2013-11-05 12:45:53 +0100
commit3d7e7118aee40a2a7070e503307bdb07fe3bfc49 (patch)
tree942140a91ea23fcb4438f4f206d4bd4a598995a9 /ship/lib/core
parentd5dcf81c04353fad721a0d36d7fc14b50d47583a (diff)
parent3060d3c4ce12fae2e8b754f13d0e227af2134ab5 (diff)
Merge remote-tracking branch 'confmagic/master'
Diffstat (limited to 'ship/lib/core')
-rw-r--r--ship/lib/core34
1 files changed, 34 insertions, 0 deletions
diff --git a/ship/lib/core b/ship/lib/core
new file mode 100644
index 00000000..6d126142
--- /dev/null
+++ b/ship/lib/core
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+# logging
+msg() { printf "$@\n" >&2 ;}
+info() { msg "** $@" ;}
+error() { msg "!! $@" ;}
+exists(){ type "$1" >/dev/null 2>/dev/null; }
+is_root(){
+ test $(id -u) -eq 0
+}
+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;
+}