From 72ac75c3322b07e1893246b8928d96a3411aee21 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Sun, 18 Aug 2019 12:07:18 +0200 Subject: update-me: "mount -o remount,rw /boot" if necessarry (and as root) --- update-me.in | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/update-me.in b/update-me.in index 449d7b9..0b4c48d 100644 --- a/update-me.in +++ b/update-me.in @@ -4,6 +4,15 @@ preCmds=('hostname') cmds=() postCmds=('sync') +if mountpoint -q /boot \ +&& mount \ + | grep -wF '/boot' \ + | cut -d' ' -f6 \ + | grep -qwF 'ro'; then + preCmds+=('mount -o remount,rw /boot') + postCmds+=('mount -o remount,ro /boot') +fi + if command -v check-kernel >/dev/null; then postCmds+=('check-kernel -r') fi @@ -12,9 +21,15 @@ fi if "${hasSudo}" && \ command -v sudo >/dev/null; then + for ((i=0; i<${#preCmds[@]}; i++)); do + if [ -z "${preCmds[${i}]%%mount*}" ]; then + preCmds[${i}]='sudo '"${preCmds[${i}]}"; + fi + done for ((i=0; i<${#postCmds[@]}; i++)); do - if [ "${postCmds[${i}]}" = 'check-kernel -r' ]; then - postCmds[${i}]='sudo check-kernel -r'; + if [ "${postCmds[${i}]}" = 'check-kernel -r' ] \ + || [ -z "${postCmds[${i}]%%mount*}" ]; then + postCmds[${i}]='sudo '"${postCmds[${i}]}"; fi done fi -- cgit v1.2.3-54-g00ecf