dcavalca / rpms / systemd

Forked from rpms/systemd 4 months ago
Clone
594167
From 1f9eec4ab2a8a2213fec66194c537086e8242a0d Mon Sep 17 00:00:00 2001
aa0848
From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <nabijaczleweli@nabijaczleweli.xyz>
aa0848
Date: Thu, 16 Dec 2021 15:06:06 +0100
aa0848
Subject: [PATCH] kernel-install: port to /bin/sh
aa0848
aa0848
(cherry picked from commit 76b1274a5cb54acaa4a0f0c2e570d751f9067c06)
aa0848
aa0848
Related: #2065061
aa0848
---
aa0848
 src/kernel-install/kernel-install | 109 ++++++++++++------------------
aa0848
 1 file changed, 43 insertions(+), 66 deletions(-)
aa0848
aa0848
diff --git a/src/kernel-install/kernel-install b/src/kernel-install/kernel-install
aa0848
index f6da0cf7a8..2e8f382d5f 100755
aa0848
--- a/src/kernel-install/kernel-install
aa0848
+++ b/src/kernel-install/kernel-install
aa0848
@@ -1,4 +1,4 @@
aa0848
-#!/usr/bin/env bash
aa0848
+#!/bin/sh
aa0848
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
aa0848
 # ex: ts=8 sw=4 sts=4 et filetype=sh
aa0848
 # SPDX-License-Identifier: LGPL-2.1-or-later
aa0848
@@ -18,7 +18,7 @@
aa0848
 # You should have received a copy of the GNU Lesser General Public License
aa0848
 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
aa0848
 
aa0848
-SKIP_REMAINING=77
aa0848
+skip_remaining=77
aa0848
 
aa0848
 usage()
aa0848
 {
aa0848
@@ -32,24 +32,17 @@ usage()
aa0848
 
aa0848
 dropindirs_sort()
aa0848
 {
aa0848
-    local suffix=$1; shift
aa0848
-    local -a files
aa0848
-    local f d i
aa0848
-
aa0848
-    readarray -t files <<<"$(
aa0848
-        for d in "$@"; do
aa0848
-            for i in "$d/"*"$suffix"; do
aa0848
-                if [[ -e "$i" ]]; then
aa0848
-                    echo "${i##*/}"
aa0848
-                fi
aa0848
-            done
aa0848
-        done | sort -Vu
aa0848
-    )"
aa0848
-
aa0848
-    for f in "${files[@]}"; do
aa0848
-        for d in "$@"; do
aa0848
-            if [[ -e "$d/$f" ]]; then
aa0848
-                echo "$d/$f"
aa0848
+    suffix="$1"
aa0848
+    shift
aa0848
+
aa0848
+    for d; do
aa0848
+        for i in "$d/"*"$suffix"; do
aa0848
+            [ -e "$i" ] && echo "${i##*/}"
aa0848
+        done
aa0848
+    done | sort -Vu | while read -r f; do
aa0848
+        for d; do
aa0848
+            if [ -e "$d/$f" ]; then
aa0848
+                [ -x "$d/$f" ] && echo "$d/$f"
aa0848
                 continue 2
aa0848
             fi
aa0848
         done
aa0848
@@ -65,27 +58,25 @@ for i; do
aa0848
     fi
aa0848
 done
aa0848
 
aa0848
-KERNEL_INSTALL_VERBOSE=0
aa0848
+export KERNEL_INSTALL_VERBOSE=0
aa0848
 if [ "$1" = "--verbose" ] || [ "$1" = "-v" ]; then
aa0848
     shift
aa0848
     KERNEL_INSTALL_VERBOSE=1
aa0848
 fi
aa0848
-export KERNEL_INSTALL_VERBOSE
aa0848
 
aa0848
-if [[ "${0##*/}" == 'installkernel' ]]; then
aa0848
-    COMMAND='add'
aa0848
-    # make install doesn't pass any parameter wrt initrd handling
aa0848
-    INITRD_OPTIONS=()
aa0848
+if [ "${0##*/}" = "installkernel" ]; then
aa0848
+    COMMAND=add
aa0848
+    # make install doesn't pass any initrds
aa0848
 else
aa0848
     COMMAND="$1"
aa0848
-    shift
aa0848
-    INITRD_OPTIONS=( "${@:3}" )
aa0848
+    [ $# -ge 1 ] && shift
aa0848
 fi
aa0848
 
aa0848
 KERNEL_VERSION="$1"
aa0848
 KERNEL_IMAGE="$2"
aa0848
+[ $# -ge 2 ] && shift 2
aa0848
 
aa0848
-if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then
aa0848
+if [ -z "$COMMAND" ] || [ -z "$KERNEL_VERSION" ]; then
aa0848
     echo "Not enough arguments" >&2
aa0848
     exit 1
aa0848
 fi
aa0848
@@ -99,12 +90,11 @@ fi
aa0848
 # Prefer to use an existing machine ID from /etc/machine-info or /etc/machine-id. If we're using the machine
aa0848
 # ID /etc/machine-id, try to persist it in /etc/machine-info. If no machine ID is found, try to generate
aa0848
 # a new machine ID in /etc/machine-info. If that fails, use "Default".
aa0848
-
aa0848
-[ -z "$MACHINE_ID" ] && [ -f /etc/machine-info ] && source /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
aa0848
-[ -z "$MACHINE_ID" ] && [ -f /etc/machine-id ] && read -r MACHINE_ID 
aa0848
-[ -n "$MACHINE_ID" ] && [ -z "$KERNEL_INSTALL_MACHINE_ID" ] && echo "KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID" >>/etc/machine-info
aa0848
+[ -z "$MACHINE_ID" ] && [ -r /etc/machine-info ]              && . /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
aa0848
+[ -z "$MACHINE_ID" ] && [ -r /etc/machine-id ]                && read -r MACHINE_ID 
aa0848
+[ -n "$MACHINE_ID" ] && [ -z "$KERNEL_INSTALL_MACHINE_ID" ]   && echo "KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID" >>/etc/machine-info
aa0848
 [ -z "$MACHINE_ID" ] && NEW_MACHINE_ID="$(systemd-id128 new)" && echo "KERNEL_INSTALL_MACHINE_ID=$NEW_MACHINE_ID" >>/etc/machine-info
aa0848
-[ -z "$MACHINE_ID" ] && [ -f /etc/machine-info ] && source /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
aa0848
+[ -z "$MACHINE_ID" ] && [ -r /etc/machine-info ]              && . /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
aa0848
 [ -z "$MACHINE_ID" ] && MACHINE_ID="Default"
aa0848
 
aa0848
 [ -z "$BOOT_ROOT" ] && for suff in "$MACHINE_ID" "loader/entries"; do
aa0848
@@ -125,11 +115,6 @@ done
aa0848
 [ -z "$BOOT_ROOT" ] && BOOT_ROOT="/boot"
aa0848
 
aa0848
 
aa0848
-ENTRY_DIR_ABS="$BOOT_ROOT/$MACHINE_ID/$KERNEL_VERSION"
aa0848
-
aa0848
-export KERNEL_INSTALL_MACHINE_ID="$MACHINE_ID"
aa0848
-export KERNEL_INSTALL_BOOT_ROOT="$BOOT_ROOT"
aa0848
-
aa0848
 if [ -z "$layout" ]; then
aa0848
     # Administrative decision: if not present, some scripts generate into /boot.
aa0848
     if [ -d "$BOOT_ROOT/$MACHINE_ID" ]; then
aa0848
@@ -152,21 +137,23 @@ MAKE_ENTRY_DIR_ABS=$?
aa0848
 
aa0848
 ret=0
aa0848
 
aa0848
-readarray -t PLUGINS <<<"$(
aa0848
+PLUGINS="$(
aa0848
     dropindirs_sort ".install" \
aa0848
         "/etc/kernel/install.d" \
aa0848
         "/usr/lib/kernel/install.d"
aa0848
 )"
aa0848
+IFS="
aa0848
+"
aa0848
 
aa0848
-case $COMMAND in
aa0848
+case "$COMMAND" in
aa0848
     add)
aa0848
-        if [[ ! "$KERNEL_IMAGE" ]]; then
aa0848
+        if [ -z "$KERNEL_IMAGE" ]; then
aa0848
             echo "Command 'add' requires an argument" >&2
aa0848
             exit 1
aa0848
         fi
aa0848
 
aa0848
-        if [[ ! -f "$KERNEL_IMAGE" ]]; then
aa0848
-            echo "Kernel image argument ${KERNEL_IMAGE} not a file" >&2
aa0848
+        if ! [ -f "$KERNEL_IMAGE" ]; then
aa0848
+            echo "Kernel image argument $KERNEL_IMAGE not a file" >&2
aa0848
             exit 1
aa0848
         fi
aa0848
 
aa0848
@@ -182,32 +169,22 @@ case $COMMAND in
aa0848
             fi
aa0848
         fi
aa0848
 
aa0848
-        for f in "${PLUGINS[@]}"; do
aa0848
-            if [[ -x $f ]]; then
aa0848
-                [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
aa0848
-                    echo "+$f add $KERNEL_VERSION $ENTRY_DIR_ABS $KERNEL_IMAGE ${INITRD_OPTIONS[*]}"
aa0848
-                "$f" add "$KERNEL_VERSION" "$ENTRY_DIR_ABS" "$KERNEL_IMAGE" "${INITRD_OPTIONS[@]}"
aa0848
-                x=$?
aa0848
-                if [ $x -eq "$SKIP_REMAINING" ]; then
aa0848
-                    break
aa0848
-                fi
aa0848
-                ((ret+=x))
aa0848
-            fi
aa0848
+        for f in $PLUGINS; do
aa0848
+            [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "+$f add $KERNEL_VERSION $ENTRY_DIR_ABS $KERNEL_IMAGE $*"
aa0848
+            "$f" add "$KERNEL_VERSION" "$ENTRY_DIR_ABS" "$KERNEL_IMAGE" "$@"
aa0848
+            err=$?
aa0848
+            [ $err -eq $skip_remaining ] && break
aa0848
+            ret=$(( ret + err ))
aa0848
         done
aa0848
         ;;
aa0848
 
aa0848
     remove)
aa0848
-        for f in "${PLUGINS[@]}"; do
aa0848
-            if [[ -x $f ]]; then
aa0848
-                [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
aa0848
-                    echo "+$f remove $KERNEL_VERSION $ENTRY_DIR_ABS"
aa0848
-                "$f" remove "$KERNEL_VERSION" "$ENTRY_DIR_ABS"
aa0848
-                x=$?
aa0848
-                if [ $x -eq "$SKIP_REMAINING" ]; then
aa0848
-                    break
aa0848
-                fi
aa0848
-                ((ret+=x))
aa0848
-            fi
aa0848
+        for f in $PLUGINS; do
aa0848
+            [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "+$f remove $KERNEL_VERSION $ENTRY_DIR_ABS"
aa0848
+            "$f" remove "$KERNEL_VERSION" "$ENTRY_DIR_ABS"
aa0848
+            err=$?
aa0848
+            [ $err -eq $skip_remaining ] && break
aa0848
+            ret=$(( ret + err ))
aa0848
         done
aa0848
 
aa0848
         if [ "$MAKE_ENTRY_DIR_ABS" -eq 0 ]; then