--- branches/unlabeled-1.1.1/magellan-initscripts/etc/rc.d/init.d/functions 2004/12/13 22:52:07 2 +++ trunk/magellan-initscripts/etc/rc.d/init.d/functions 2009/11/05 12:57:14 931 @@ -1,4 +1,6 @@ #!/bin/bash +# $Id$ + # Begin $rc_base/init.d/functions - Run Level Control Functions # Based on functions script from LFS-3.1 and earlier. @@ -48,7 +50,7 @@ # dummy function; needed if splashutils are not installed splash() { - return 0 + return 0 } @@ -106,7 +108,7 @@ then #check if statedir exists [ ! -d ${svcdir}/started ] && mkdir ${svcdir}/started - + #get real name of the initscript, not from the symlink if [ -L "$0" ] then @@ -135,16 +137,17 @@ evaluate_retval() { - error_value=$? + local error_value="$1" + [[ -z ${error_value} ]] && error_value=$? - if [ $error_value = 0 ] + if [[ ${error_value} = 0 ]] then print_status success else print_status failure fi - return $error_value + return ${error_value} } print_status() @@ -346,14 +349,20 @@ fi } +kernel_version() +{ + local KV="$(uname -r | cut -d- -f1)" + echo "${KV}" +} + kernel_major_version() { local KV - KV="$(uname -r|cut -d. -f1-2)" + KV="$(uname -r | cut -d. -f1-2)" echo "${KV}" } -dolisting() +dolisting() { local x= local y= @@ -387,3 +396,63 @@ echo "${mylist}" } + +# searches /proc/mounts for mounted fstypes (like ext3) +is_fstype_mounted() { + local filesys + local i + filesys=$1 + + i="$(cat /proc/mounts | grep ${filesys} | cut -d ' ' -f3)" + [[ ${i} != ${filesys} ]] && return 1 + + return 0 +} + +# searches /proc/mounts for mounted fs names (like udev, proc) +is_fs_mounted() { + local filesys + local i + filesys=$1 + + i="$(cat /proc/mounts | grep ${filesys} | cut -d ' ' -f1)" + [[ ${i} != ${filesys} ]] && return 1 + + return 0 +} + +# checks if kernel supports fs xy +kernel_supports_fs() { + local filesys + local i + filesys=$1 + + i="$(cat /proc/filesystems | grep ${filesys} | cut -d $'\t' -f2)" + [[ ${i} != ${filesys} ]] && return 1 + + return 0 +} + +# bool is_older_than(reference, files/dirs to check) +# +# return 0 if any of the files/dirs are newer than +# the reference file +# +# EXAMPLE: if is_older_than a.out *.o ; then ... +is_older_than() { + local x= + local ref="$1" + shift + + for x in "$@" + do + [[ ${x} -nt ${ref} ]] && return 0 + + if [[ -d ${x} ]] + then + is_older_than "${ref}" "${x}"/* && return 0 + fi + done + + return 1 +}