1- #! /usr/ bin/env bash
1+ #! /bin/sh
22# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
33# ex: ts=8 sw=4 sts=4 et filetype=sh
44# SPDX-License-Identifier: LGPL-2.1-or-later
1818# You should have received a copy of the GNU Lesser General Public License
1919# along with systemd; If not, see <http://www.gnu.org/licenses/>.
2020
21- SKIP_REMAINING =77
21+ skip_remaining =77
2222
2323usage ()
2424{
@@ -32,24 +32,17 @@ usage()
3232
3333dropindirs_sort ()
3434{
35- local suffix=$1 ; shift
36- local -a files
37- local f d i
38-
39- readarray -t files <<< " $(
40- for d in " $@ " ; do
41- for i in " $d /" *" $suffix " ; do
42- if [[ -e " $i " ]]; then
43- echo " ${i##*/ } "
44- fi
45- done
46- done | sort -Vu
47- )"
48-
49- for f in " ${files[@]} " ; do
50- for d in " $@ " ; do
51- if [[ -e " $d /$f " ]]; then
52- echo " $d /$f "
35+ suffix=" $1 "
36+ shift
37+
38+ for d; do
39+ for i in " $d /" * " $suffix " ; do
40+ [ -e " $i " ] && echo " ${i##*/ } "
41+ done
42+ done | sort -Vu | while read -r f; do
43+ for d; do
44+ if [ -e " $d /$f " ]; then
45+ [ -x " $d /$f " ] && echo " $d /$f "
5346 continue 2
5447 fi
5548 done
@@ -65,27 +58,25 @@ for i; do
6558 fi
6659done
6760
68- KERNEL_INSTALL_VERBOSE=0
61+ export KERNEL_INSTALL_VERBOSE=0
6962if [ " $1 " = " --verbose" ] || [ " $1 " = " -v" ]; then
7063 shift
7164 KERNEL_INSTALL_VERBOSE=1
7265fi
73- export KERNEL_INSTALL_VERBOSE
7466
75- if [[ " ${0##*/ } " == ' installkernel' ]]; then
76- COMMAND=' add'
77- # make install doesn't pass any parameter wrt initrd handling
78- INITRD_OPTIONS=()
67+ if [ " ${0##*/ } " = " installkernel" ]; then
68+ COMMAND=add
69+ # make install doesn't pass any initrds
7970else
8071 COMMAND=" $1 "
81- shift
82- INITRD_OPTIONS=( " ${@: 3} " )
72+ [ $# -ge 1 ] && shift
8373fi
8474
8575KERNEL_VERSION=" $1 "
8676KERNEL_IMAGE=" $2 "
77+ [ $# -ge 2 ] && shift 2
8778
88- if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ] ]; then
79+ if [ -z " $COMMAND " ] || [ -z " $KERNEL_VERSION " ]; then
8980 echo " Not enough arguments" >&2
9081 exit 1
9182fi
9990# Prefer to use an existing machine ID from /etc/machine-info or /etc/machine-id. If we're using the machine
10091# ID /etc/machine-id, try to persist it in /etc/machine-info. If no machine ID is found, try to generate
10192# a new machine ID in /etc/machine-info. If that fails, use "Default".
102-
103- [ -z " $MACHINE_ID " ] && [ -f /etc/machine-info ] && source /etc/machine-info && MACHINE_ID=" $KERNEL_INSTALL_MACHINE_ID "
104- [ -z " $MACHINE_ID " ] && [ -f /etc/machine-id ] && read -r MACHINE_ID < /etc/machine-id
105- [ -n " $MACHINE_ID " ] && [ -z " $KERNEL_INSTALL_MACHINE_ID " ] && echo " KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID " >> /etc/machine-info
93+ [ -z " $MACHINE_ID " ] && [ -r /etc/machine-info ] && . /etc/machine-info && MACHINE_ID=" $KERNEL_INSTALL_MACHINE_ID "
94+ [ -z " $MACHINE_ID " ] && [ -r /etc/machine-id ] && read -r MACHINE_ID < /etc/machine-id
95+ [ -n " $MACHINE_ID " ] && [ -z " $KERNEL_INSTALL_MACHINE_ID " ] && echo " KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID " >> /etc/machine-info
10696[ -z " $MACHINE_ID " ] && NEW_MACHINE_ID=" $( systemd-id128 new) " && echo " KERNEL_INSTALL_MACHINE_ID=$NEW_MACHINE_ID " >> /etc/machine-info
107- [ -z " $MACHINE_ID " ] && [ -f /etc/machine-info ] && source /etc/machine-info && MACHINE_ID=" $KERNEL_INSTALL_MACHINE_ID "
97+ [ -z " $MACHINE_ID " ] && [ -r /etc/machine-info ] && . /etc/machine-info && MACHINE_ID=" $KERNEL_INSTALL_MACHINE_ID "
10898[ -z " $MACHINE_ID " ] && MACHINE_ID=" Default"
10999
110100[ -z " $BOOT_ROOT " ] && for suff in " $MACHINE_ID " " loader/entries" ; do
@@ -125,11 +115,6 @@ done
125115[ -z " $BOOT_ROOT " ] && BOOT_ROOT=" /boot"
126116
127117
128- ENTRY_DIR_ABS=" $BOOT_ROOT /$MACHINE_ID /$KERNEL_VERSION "
129-
130- export KERNEL_INSTALL_MACHINE_ID=" $MACHINE_ID "
131- export KERNEL_INSTALL_BOOT_ROOT=" $BOOT_ROOT "
132-
133118if [ -z " $layout " ]; then
134119 # Administrative decision: if not present, some scripts generate into /boot.
135120 if [ -d " $BOOT_ROOT /$MACHINE_ID " ]; then
@@ -152,21 +137,23 @@ MAKE_ENTRY_DIR_ABS=$?
152137
153138ret=0
154139
155- readarray -t PLUGINS <<< " $(
140+ PLUGINS= " $(
156141 dropindirs_sort " .install" \
157142 " /etc/kernel/install.d" \
158143 " /usr/lib/kernel/install.d"
159144) "
145+ IFS="
146+ "
160147
161- case $COMMAND in
148+ case " $COMMAND " in
162149 add)
163- if [[ ! " $KERNEL_IMAGE " ] ]; then
150+ if [ -z " $KERNEL_IMAGE " ]; then
164151 echo " Command 'add' requires an argument" >&2
165152 exit 1
166153 fi
167154
168- if [[ ! -f " $KERNEL_IMAGE " ] ]; then
169- echo " Kernel image argument ${ KERNEL_IMAGE} not a file" >&2
155+ if ! [ -f " $KERNEL_IMAGE " ]; then
156+ echo " Kernel image argument $KERNEL_IMAGE not a file" >&2
170157 exit 1
171158 fi
172159
@@ -182,32 +169,22 @@ case $COMMAND in
182169 fi
183170 fi
184171
185- for f in " ${PLUGINS[@]} " ; do
186- if [[ -x $f ]]; then
187- [ " $KERNEL_INSTALL_VERBOSE " -gt 0 ] && \
188- echo " +$f add $KERNEL_VERSION $ENTRY_DIR_ABS $KERNEL_IMAGE ${INITRD_OPTIONS[*]} "
189- " $f " add " $KERNEL_VERSION " " $ENTRY_DIR_ABS " " $KERNEL_IMAGE " " ${INITRD_OPTIONS[@]} "
190- x=$?
191- if [ $x -eq " $SKIP_REMAINING " ]; then
192- break
193- fi
194- (( ret+= x))
195- fi
172+ for f in $PLUGINS ; do
173+ [ " $KERNEL_INSTALL_VERBOSE " -gt 0 ] && echo " +$f add $KERNEL_VERSION $ENTRY_DIR_ABS $KERNEL_IMAGE $* "
174+ " $f " add " $KERNEL_VERSION " " $ENTRY_DIR_ABS " " $KERNEL_IMAGE " " $@ "
175+ err=$?
176+ [ $err -eq $skip_remaining ] && break
177+ ret=$(( ret + err ))
196178 done
197179 ;;
198180
199181 remove)
200- for f in " ${PLUGINS[@]} " ; do
201- if [[ -x $f ]]; then
202- [ " $KERNEL_INSTALL_VERBOSE " -gt 0 ] && \
203- echo " +$f remove $KERNEL_VERSION $ENTRY_DIR_ABS "
204- " $f " remove " $KERNEL_VERSION " " $ENTRY_DIR_ABS "
205- x=$?
206- if [ $x -eq " $SKIP_REMAINING " ]; then
207- break
208- fi
209- (( ret+= x))
210- fi
182+ for f in $PLUGINS ; do
183+ [ " $KERNEL_INSTALL_VERBOSE " -gt 0 ] && echo " +$f remove $KERNEL_VERSION $ENTRY_DIR_ABS "
184+ " $f " remove " $KERNEL_VERSION " " $ENTRY_DIR_ABS "
185+ err=$?
186+ [ $err -eq $skip_remaining ] && break
187+ ret=$(( ret + err ))
211188 done
212189
213190 if [ " $MAKE_ENTRY_DIR_ABS " -eq 0 ]; then
0 commit comments