X-Git-Url: https://git.grml.org/?a=blobdiff_plain;ds=sidebyside;f=scripts%2Fforensic-mark-readonly;h=cd7afc8babd4b78c7bd9adf7b23b2685f0787255;hb=cf81315ab6c4038db9198c4a27e77ad1e4a776d7;hp=909a512bb6e61ff3a0c62ccc943fd50bcedb46cd;hpb=d74a8a677ede7a1b867ea97d0596e5f954d67e19;p=grml-udev-config.git diff --git a/scripts/forensic-mark-readonly b/scripts/forensic-mark-readonly index 909a512..cd7afc8 100755 --- a/scripts/forensic-mark-readonly +++ b/scripts/forensic-mark-readonly @@ -1,58 +1,61 @@ #!/bin/sh # Filename: forensic-mark-readonly -# Purpose: force device to readonly mode when booting with bootoption forensic/readonly +# Purpose: force block devices to read-only mode when booting with boot option read-only # Authors: grml-team (grml.org), (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2 or any later version. ################################################################################ -function get_blockdev_dir() { +get_blockdev_dir() { for dir in /sys/subsystem/block/ /sys/class/block/ /sys/block/ ; do - [ -d $dir ] && echo $dir && return + [ -d "$dir" ] && echo "$dir" && return done } -function base() { +base() { echo ${1##*/} } -function dir() { + +dir() { echo ${1%/*} } -function is_ro() { +is_ro() { [ "$(blockdev --getro $1)" = "1" ] && return 0 || return 1 - - } -# check for forensic/readonly bootoption -if : ; then + +# check for read-only bootoption +if grep -q read-only /proc/cmdline ; then # we get $DEVNAME via udev's environment if [ -n "$DEVNAME" ] ; then NAME=$(base $DEVNAME) SYS_DIR=$(get_blockdev_dir) - if [ -n $SYS_DIR ] && [ -n $NAME ] ; then + if [ -n "$SYS_DIR" ] && [ -n "$NAME" ] ; then DEVICE=$SYS_DIR/*/$NAME if [ -d $DEVICE ] ; then PARENT=$(dir $DEVICE) PARENT=$(base $PARENT) - PARENT=/dev/$PARENT + PARENT="/dev/$PARENT" fi fi if is_ro "$DEVNAME" ; then - logger "forensic mode: device $DEVNAME already set to readonly mode, nothing to do" + logger "forensic mode: device $DEVNAME already set to read-only mode, nothing to do" elif [ -n "$PARENT" ] && ! is_ro "$PARENT" ; then - logger "forensic mode: parent device $PARENT is set readwrite, not modifying" + logger "forensic mode: parent device $PARENT is set read-write, not modifying" logger "forensic mode: use blockdev --setro $DEVNAME to set it manually" else - logger "forensic mode: setting $DEVNAME [$ID_SERIAL] to readonly" + logger "forensic mode: setting $DEVNAME [$ID_SERIAL] to read-only" + if blockdev --setro "$DEVNAME" ; then logger "|-> done; execute 'blockdev --setrw $DEVNAME' to unlock" else logger "|-> error while executing blockdev: $(blockdev --setro $DEVNAME 2>&1)" fi + fi + fi fi