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 ################################################################################
10 export PATH=${PATH:-'/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin'}
14 # {{{ check for root-permissions
16 if [ "$(id -u 2>/dev/null)" != 0 ] ; then
17 echo 1>&2 "Error: please run this script with uid 0 (root)." ; return 1
22 # {{{ check for user permissions
24 if [ "$(id -u 2>/dev/null)" = 0 ] ; then
25 echo 1>&2 "Error: please do not run this script with uid 0 (root)." ; return 1
30 # {{{ check for running zsh
32 if ! [ -z "$ZSH_VERSION" ] ; then
40 # {{{ check for (X)dialog
42 if [ -n "$DISPLAY" ] ; then
43 [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog" && export XDIALOG_HIGH_DIALOG_COMPAT=1
45 [ -x /usr/bin/dialog ] && DIALOG='dialog' || ( echo 1>&2 "dialog not available" ; return 1 )
50 # {{{ check for availability of program(s)
54 which $arg >/dev/null 2>&1 || RC="$arg"
56 if [ -n "$RC" ] ; then
57 echo "$RC not installed"
63 # {{{ simple shell grep
65 case "$(cat $2)" in *$1*) return 0;; esac
70 # {{{ simple shell grep for strings
72 case "$2" in *$1*) return 0;; esac
77 # {{{ reread boot command line; echo last parameter's argument or return false.
79 stringinstring " $1=" /proc/cmdline || return 1
80 result="${/proc/cmdline##*$1=}"
81 result="${result%%[ ]*}"
87 # {{{ check boot commandline for specified option
89 stringinstring " $1" /proc/cmdline
94 # {{{ check whether $1 is yes
96 if [ "$1" = "yes" -o "$1" = "YES" ] ; then
104 # {{{ grml specific checks
106 [ -f /etc/grml_version ] && return 0 || return 1
110 cat /etc/grml_version
114 [ -f /etc/grml_cd ] && return 0 || return 1
118 [ -f /etc/grml_cd ] && return 1 || return 0
122 grep -q small /etc/grml_version 2>/dev/null && return 0 || return 1
126 # {{{ filesystems (proc, pts, sys)
128 check4root || return 1
129 [ -f /proc/version ] || mount -t proc /proc /proc 2>/dev/null
133 check4root || return 1
134 stringinfile "/dev/pts" /proc/mounts || mount -t devpts /dev/pts /dev/pts 2>/dev/null
138 check4root || return 1
139 [ -d /sys/devices ] || mount -t sysfs /sys /sys 2>/dev/null
143 # char *reverse_list(list) {{{
145 # Returns the reversed order of list
150 while [ "$#" -gt 0 ] ; do
151 if [ -z "${ret}" ] ; then
162 # bool is_older_than(reference, files/dirs to check) {{{
164 # return 0 if any of the files/dirs are newer than
167 # EXAMPLE: if is_older_than a.out *.o ; then ...
174 [ "${x}" -nt "${ref}" ] && return 0
176 if [ -d "${x}" ] ; then
177 is_older_than "${ref}" "${x}"/* && return 0
185 ## END OF FILE #################################################################
186 # vim:foldmethod=marker tw=80 ai expandtab shiftwidth=2 tabstop=2