1 # Filename: /etc/grml/script-functions
2 # Purpose: some often used functions for use in shellscripts
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: Fre Apr 06 22:42:04 CEST 2007 [mika]
7 ################################################################################
11 export PATH=${PATH:-'/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin'}
15 # {{{ check for root-permissions
17 if [ "$(id -u 2>/dev/null)" != 0 ] ; then
18 echo 1>&2 "Error: please run this script with uid 0 (root)." ; return 1
23 # {{{ check for user permissions
25 if [ "$(id -u 2>/dev/null)" = 0 ] ; then
26 echo 1>&2 "Error: please do not run this script with uid 0 (root)." ; return 1
31 # {{{ check for running zsh
33 if ! [ -z "$ZSH_VERSION" ] ; then
41 # {{{ check for (X)dialog
43 if [ -n "$DISPLAY" ] ; then
44 [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog" && export XDIALOG_HIGH_DIALOG_COMPAT=1
46 [ -x /usr/bin/dialog ] && DIALOG='dialog' || ( echo 1>&2 "dialog not available" ; return 1 )
51 # {{{ check for availability of program(s)
55 type -p $arg >/dev/null 2>&1 || RC="$arg"
57 if [ -n "$RC" ] ; then
58 echo "$RC not installed"
64 # {{{ simple shell grep
66 case "$(cat $2)" in *$1*) return 0;; esac
71 # {{{ simple shell grep for strings
73 case "$2" in *$1*) return 0;; esac
78 # {{{ reread boot command line; echo last parameter's argument or return false.
80 stringinstring " $1=" /proc/cmdline || return 1
81 result="${/proc/cmdline##*$1=}"
82 result="${result%%[ ]*}"
88 # {{{ check boot commandline for specified option
90 stringinstring " $1" /proc/cmdline
95 # {{{ check whether $1 is yes
97 if [ "$1" = "yes" -o "$1" = "YES" ] ; then
105 # {{{ grml specific checks
107 [ -f /etc/grml_version ] && return 0 || return 1
111 cat /etc/grml_version
115 [ -f /etc/grml_cd ] && return 0 || return 1
119 [ -f /etc/grml_cd ] && return 1 || return 0
123 grep -q small /etc/grml_version 2>/dev/null && return 0 || return 1
127 # {{{ filesystems (proc, pts, sys)
129 check4root || return 1
130 [ -f /proc/version ] || mount -t proc /proc /proc 2>/dev/null
134 check4root || return 1
135 stringinfile "/dev/pts" /proc/mounts || mount -t devpts /dev/pts /dev/pts 2>/dev/null
139 check4root || return 1
140 [ -d /sys/devices ] || mount -t sysfs /sys /sys 2>/dev/null
144 ## END OF FILE #################################################################
145 # vim:foldmethod=marker tw=80 ai expandtab shiftwidth=2 tabstop=2