some new scripts, functions,....
[grml-live.git] / scripts / functions.sh
1 # Filename:      functions.sh
2 # Purpose:       helper functions for use within grml-live
3 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
4 # Bug-Reports:   see http://grml.org/bugs/
5 # License:       This file is licensed under the GPL v2.
6 # Latest change: Thu Feb 08 22:35:46 CET 2007
7 ################################################################################
8
9 bailout(){
10   [ -n "$1" ] && EXIT="$1" || EXIT="1"
11   [ -n "$2" ] && echo "$2">&2
12   exit "$EXIT"
13 }
14
15 usage() {
16   print "
17   $0 ....
18 "
19 }
20
21 debug() {
22   if [[ -n "$DEBUG" ]] ; then
23      einfo "grml-live: $*"
24      [[ -n "$DEBUG_SYSLOG" ]] && [ -x /usr/bin/logger ] && logger -t grml-live-info "$*"
25   else
26      return 0 # do nothing
27   fi
28 }
29
30 debug_warn() {
31   if [[ -n "$DEBUG" ]] ; then
32      ewarn "grml-live: $*"
33      [[ -n "$DEBUG_SYSLOG" ]] && [ -x /usr/bin/logger ] && logger -t grml-live-warn "$*"
34   else
35      return 0 # do nothing
36   fi
37 }
38
39 debug_error() {
40   if [[ -n "$DEBUG" ]] ; then
41      eerror "grml-live: $*"
42      [[ -n "$DEBUG_SYSLOG" ]] && [ -x /usr/bin/logger ] && logger -t grml-live-error "$*"
43   else
44      return 0 # do nothing
45   fi
46 }
47
48 chroot_exec()
49 {
50   [ -n "$TARGET" ] || bailout 1 "\$TARGET unset, can not chroot_exec"
51   [ -n "$1" ] || bailout 1 "Error executing chroot_exec. Usage: chroot_exec <command>"
52   chroot "$TARGET" "$1"
53 }
54
55 ## END OF FILE #################################################################