Don't depend on grml-etc-core
[grml-debootstrap.git] / grml-debootstrap
index b030ff0..5964d55 100755 (executable)
@@ -28,11 +28,6 @@ export LC_ALL=C
 INTERACTIVE=''
 # }}}
 
-# source core functions {{{
-. /etc/grml/lsb-functions
-. /etc/grml/script-functions
-# }}}
-
 # help text {{{
 usage() {
   echo "$PN - wrapper around debootstrap for installing Debian
@@ -103,6 +98,60 @@ if [ "$1" = '-h' ] || [ "$1" = '-help' ] || [ "$1" = "--help" ] ; then
 fi
 # }}}
 
+# {{{
+GOOD='\e[32;01m'
+WARN='\e[33;01m'
+BAD='\e[31;01m'
+NORMAL='\e[0m'
+HILITE='\e[36;01m'
+BRACKET='\e[34;01m'
+
+einfo() {
+  einfon "$1\n"
+  return 0
+}
+
+einfon() {
+  [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
+  printf " ${GOOD}*${NORMAL} $*"
+  LAST_E_CMD=einfon
+  return 0
+}
+
+eerror() {
+  [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
+  printf " ${BAD}*${NORMAL} $*\n"
+  LAST_E_CMD=eerror
+  return 0
+}
+
+eend() {
+  local retval="${1:-0}"
+  shift
+  if [ $retval -gt 0 ]; then
+    printf " ${BAD}-> Failed (rc=${retval})${NORMAL}\n"
+  fi
+}
+
+check4root(){
+  if [ "$(id -u 2>/dev/null)" != 0 ] ; then
+    echo 1>&2 "Error: please run this script with uid 0 (root)." ; return 1
+  fi
+}
+
+check4progs(){
+  local RC=''
+  for arg in $* ; do
+    which $arg >/dev/null 2>&1 || RC="$arg"
+  done
+  if [ -n "$RC" ] ; then
+     echo "$RC not installed"
+     return 1
+  fi
+}
+
+# }}}
+
 # make sure we have what we need {{{
 check4progs debootstrap dialog || exit 1
 # }}}
@@ -120,7 +169,8 @@ if [ -r ./cmdlineopts.clp ] ; then
 elif [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
    . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
 else
-   echo "Error: cmdline function file not found, exiting.">&2
+   eerror "Error: cmdline function file not found, exiting."
+   eend 1
    exit 1
 fi
 
@@ -206,15 +256,17 @@ fi
 
 # backwards compability checks {{{
 if [ -n "$GROOT" ] ; then
-   echo "Error: you seem to have \$GROOT configured." >&2
-   echo "This variable is no longer supported, please visit the" >&2
-   echo "grml-debootstrap documentation for details." >&2
+   eerror "Error: you seem to have \$GROOT configured."
+   eerror "This variable is no longer supported, please visit the"
+   eerror "grml-debootstrap documentation for details."
+   eend 1
    exit 1
 fi
 
 if echo "$GRUB" | grep -q '^hd' ; then
-   echo "Error: this syntax for the grub configuration variable is no longer supported." >&2
-   echo "Please do not use hd... any longer but /dev/sdX instead." >&2
+   eerror "Error: this syntax for the grub configuration variable is no longer supported."
+   eerror "Please do not use hd... any longer but /dev/sdX instead."
+   eend 1
    exit 1
 fi
 # }}}
@@ -739,9 +791,7 @@ stage() {
      return 0
   elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
      ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
-     eindent
-       ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
-     eoutdent
+     ewarn "  To reexecute it clean up the according directory inside $STAGES" ; eend 0
      return 1
   fi
 }
@@ -839,7 +889,7 @@ prepare_vm() {
 
   DEVINFO=$(kpartx -av $TARGET) # 'add map loop1p1 (253:0): 0 6289408 linear /dev/loop1 2048'
   if [ -z "${DEVINFO}" ] ; then
-    echo  Error setting up loopback device >&2
+    eerror "Error setting up loopback device." ; eend 1
     exit 1
   fi
 
@@ -852,7 +902,7 @@ prepare_vm() {
   blockdev --rereadpt "${LOOP}"
 
   if [ -z "$TARGET" ] ; then
-     echo "Error: target could not be set to according /dev/mapper/* device." >&2
+     eerror "Error: target could not be set to according /dev/mapper/* device." ; eend 1
      exit 1
   fi
 }