--- trunk/installer-simple/functions/hwdetection.sh 2014/01/07 13:24:37 2407 +++ trunk/installer-simple/functions/hwdetection.sh 2014/01/07 13:25:22 2408 @@ -315,17 +315,38 @@ ${chroot} mkinitrd -f ${initrd} ${kernel} } +is_mounted() +{ + local item + local mount + local method + method="$1" + item="$2" + + [ -e /proc/mounts ] || return 1 + + case ${method} in + --location) mount="$(grep "[[:space:]]${item}[[:space:]]" /proc/mounts | cut -d ' ' -f2)" ;; + --device) mount="$(grep "^${item}[[:space:]]" /proc/mounts | cut -d ' ' -f1)" ;; + --filesystem) mount="$(grep "[[:space:]]${item}[[:space:]]" /proc/mounts | cut -d ' ' -f3)" ;; + *) echo "unknown method '${method}'"; return 1 ;; + esac + [[ ${mount} != ${item} ]] && return 1 + + return 0 +} + chrooted() { local cmd="$@" - mount -t sysfs sysfs ${INSTALL_ROOT}/sys - mount -t proc proc ${INSTALL_ROOT}/proc - mount -o bind /dev ${INSTALL_ROOT}/dev - - chroot ${INSTALL_ROOT} ${cmd} - - umount ${INSTALL_ROOT}/dev - umount ${INSTALL_ROOT}/proc - umount ${INSTALL_ROOT}/sys + is_mounted --location ${INSTALLROOT}/sys || mount -t sysfs sysfs ${INSTALLROOT}/sys + is_mounted --location ${INSTALLROOT}/proc || mount -t proc proc ${INSTALLROOT}/proc + is_mounted --location ${INSTALLROOT}/dev || mount -o bind /dev ${INSTALLROOT}/dev + + chroot ${INSTALLROOT} ${cmd} + + is_mounted --location ${INSTALLROOT}/dev && umount ${INSTALLROOT}/dev + is_mounted --location ${INSTALLROOT}/proc && umount ${INSTALLROOT}/proc + is_mounted --location ${INSTALLROOT}/sys && umount ${INSTALLROOT}/sys }