summaryrefslogtreecommitdiffstats
path: root/ship/lib
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2013-11-06 19:31:15 +0100
committermakefu <github@syntax-fehler.de>2013-11-06 19:31:15 +0100
commit4140374e82f761b8aff74391d0f6c7c98f8abcd6 (patch)
treec176d889a5deedffd5f90ff5139c593548194fd7 /ship/lib
parentec217561231481671be9e33ce8270ca2b7041a9c (diff)
ship/lib/core: add esudo, get_hostname
Diffstat (limited to 'ship/lib')
-rw-r--r--ship/lib/core30
1 files changed, 30 insertions, 0 deletions
diff --git a/ship/lib/core b/ship/lib/core
index fb346f88..3a6b33ff 100644
--- a/ship/lib/core
+++ b/ship/lib/core
@@ -6,6 +6,17 @@ exists(){ type "$1" >/dev/null 2>/dev/null; }
is_root(){
test $(id -u) -eq 0
}
+
+esudo(){
+ # becomes root with sudo powers
+ # unless nosudo env is set
+ if test "${nosudo-false}" != true || is_root; then
+ echo "we're going sudo..." >&2
+ exec sudo -E "$0" "$@"
+ exit 23 # go to hell
+ fi
+}
+
get_hostname(){
# finds the current hostname
# if ENV HOSTN is set echo $HOSTN
@@ -30,3 +41,22 @@ get_hostname(){
line_to_dot(){
while read line; do printf .; done;
}
+
+
+get_os()
+{
+ # TODO: find all the release files
+ #if grep -q 'Linux' /etc/*release 2>/dev/null || grep -qe 'Linux' /etc/issue 2>/dev/null; then
+ if grep -q 'Linux' /etc/lsb-release 2>/dev/null || grep -q 'Linux' /etc/issue 2>/dev/null; then
+ echo 'linux'
+ elif exists getprop ; then
+ echo 'android'
+ elif test -e /etc/openwrt_release; then
+ echo 'openwrt'
+ elif uname -s | grep -qi 'darwin'; then
+ echo 'osx'
+ else
+ warn "Cannot determine your operating system, falling back to Linux"
+ echo 'linux'
+ fi
+}