From c0cddfc63083f8b34eb9cc282332b6430a41e5a8 Mon Sep 17 00:00:00 2001 From: "Gerd v. Egidy" Date: Mon, 1 Aug 2022 22:40:48 +0200 Subject: [PATCH] add --readonly option to mountall --- airootfs/usr/share/sysrescue/bin/mountall | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/airootfs/usr/share/sysrescue/bin/mountall b/airootfs/usr/share/sysrescue/bin/mountall index 93012e8..79b3b93 100755 --- a/airootfs/usr/share/sysrescue/bin/mountall +++ b/airootfs/usr/share/sysrescue/bin/mountall @@ -15,10 +15,11 @@ print_help() echo "mountall - mount all suitable block devices" echo "" echo "Usage:" - echo "mountall [-n|--no-bind] [-v|--verbose]" + echo "mountall [-n|--no-bind] [-o|--ro|--readonly] [-v|--verbose]" echo "" echo "--no-bind Don't try to bind-mount /dev /proc and /sys when" echo " the partition has these dirs" + echo "--readonly Mount read-only" echo "--verbose Verbose output." echo "" echo "See https://www.system-rescue.org/scripts/mountall/ for details." @@ -51,11 +52,12 @@ parse_args() exit 1 fi - local OPTIONS="nvh" - local LONGOPTS="no-bind,verbose,help" + local OPTIONS="novh" + local LONGOPTS="no-bind,readonly,ro,verbose,help" # option variables as globals, set to default values declare -g BIND=1 + declare -g READONLY=0 declare -g VERBOSE=0 # -regarding ! and PIPESTATUS see above @@ -79,6 +81,10 @@ parse_args() BIND=0 shift ;; + -o|--readonly|--ro) + READONLY=1 + shift + ;; -v|--verbose) VERBOSE=1 shift @@ -263,8 +269,14 @@ try_mount() create_mountpoint "$DEV" || return - if ! mount "$DEV" "$MOUNTPOINT"; then - echo "error mounting $DEV" + local OPTIONS="" + if [[ $READONLY -eq 1 ]]; then + [[ $VERBOSE -eq 1 ]] && echo "mounting read-only" + OPTIONS="--read-only" + fi + + if ! mount $OPTIONS "$DEV" "$MOUNTPOINT"; then + echo "error mounting $DEV to $MOUNTPOINT (options $OPTIONS)" return fi