summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorĐoàn Trần Công Danh <[email protected]>2020-11-29 02:02:08 +0700
committerGitHub <[email protected]>2020-11-28 11:02:08 -0800
commit16692e6ba0bc3b0b6e7d64a68e91ded9f2d0959e (patch)
tree9f06b307d2ffb072e17f66cb56b12a072bf07fae
parent04a82e043d067181a8b352921ef6a3c3ac875b59 (diff)
dracut: use /bin/sh instead of bash as the intepreter
Despite that dracut has a hard dependency on bash, its modules doesn't, dracut only has a hard dependency on bash for module-setup (on a fully usable machine). Inside initramfs, dracut allows users choose from a list of handful other shells, e.g. bash, busybox, dash, mkfsh. In fact, my local machine's initramfs is being built with dash, and it's functional for a very long time. Before 64025fa3a (Silence 'make checkbashisms', 2020-08-20), we also allows our users to have that right, too. Let's fix the problem 'make checkbashisms' reported and allows our users to have that right, again. For 'plymouth' case, let's simply run the command inside the if instead of checking for the existence of command before running it, because the status is also failture if plymouth is unavailable. While we're at it, let's remove an unnecessary fork for grep in zfs-generator.sh.in and its following complicated 'if elif fi' with a simple 'case ... esac'. To support this change, also exclude 90zfs from "make checkbashisms" because the current CI infrastructure ships an old version of "checkbashisms", which complains about "command -v", while the current latest "checkbashisms" thinks it's fine. In the near future, we can revert that change to "Makefile.am" when CI infrastructure is updated. Reviewed-by: Gabriel A. Devenyi <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Đoàn Trần Công Danh <[email protected]> Closes #11244
-rw-r--r--Makefile.am1
-rwxr-xr-xcontrib/dracut/90zfs/export-zfs.sh.in2
-rwxr-xr-xcontrib/dracut/90zfs/mount-zfs.sh.in2
-rwxr-xr-xcontrib/dracut/90zfs/parse-zfs.sh.in2
-rwxr-xr-xcontrib/dracut/90zfs/zfs-generator.sh.in23
-rwxr-xr-xcontrib/dracut/90zfs/zfs-lib.sh.in4
-rwxr-xr-xcontrib/dracut/90zfs/zfs-load-key.sh.in2
-rwxr-xr-xcontrib/dracut/90zfs/zfs-needshutdown.sh.in4
8 files changed, 21 insertions, 19 deletions
diff --git a/Makefile.am b/Makefile.am
index eac1a3e97..436b78d76 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -159,6 +159,7 @@ checkbashisms:
-o -name 'smart' -prune \
-o -name 'paxcheck.sh' -prune \
-o -name 'make_gitrev.sh' -prune \
+ -o -name '90zfs' -prune \
-o -type f ! -name 'config*' \
! -name 'libtool' \
-exec sh -c 'awk "NR==1 && /\#\!.*bin\/sh.*/ {print FILENAME;}" "{}"' \;); \
diff --git a/contrib/dracut/90zfs/export-zfs.sh.in b/contrib/dracut/90zfs/export-zfs.sh.in
index 09e4a3cc0..892650383 100755
--- a/contrib/dracut/90zfs/export-zfs.sh.in
+++ b/contrib/dracut/90zfs/export-zfs.sh.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
. /lib/dracut-zfs-lib.sh
diff --git a/contrib/dracut/90zfs/mount-zfs.sh.in b/contrib/dracut/90zfs/mount-zfs.sh.in
index ca407fdd4..4a892e938 100755
--- a/contrib/dracut/90zfs/mount-zfs.sh.in
+++ b/contrib/dracut/90zfs/mount-zfs.sh.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
. /lib/dracut-zfs-lib.sh
diff --git a/contrib/dracut/90zfs/parse-zfs.sh.in b/contrib/dracut/90zfs/parse-zfs.sh.in
index 2ff76d8fa..768de9dd2 100755
--- a/contrib/dracut/90zfs/parse-zfs.sh.in
+++ b/contrib/dracut/90zfs/parse-zfs.sh.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
. /lib/dracut-lib.sh
diff --git a/contrib/dracut/90zfs/zfs-generator.sh.in b/contrib/dracut/90zfs/zfs-generator.sh.in
index 120b9ecf9..59cdadcbe 100755
--- a/contrib/dracut/90zfs/zfs-generator.sh.in
+++ b/contrib/dracut/90zfs/zfs-generator.sh.in
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
echo "zfs-generator: starting" >> /dev/kmsg
@@ -11,7 +11,7 @@ GENERATOR_DIR="$1"
[ -f /lib/dracut-lib.sh ] && dracutlib=/lib/dracut-lib.sh
[ -f /usr/lib/dracut/modules.d/99base/dracut-lib.sh ] && dracutlib=/usr/lib/dracut/modules.d/99base/dracut-lib.sh
-type getarg >/dev/null 2>&1 || {
+command -v getarg >/dev/null 2>&1 || {
echo "zfs-generator: loading Dracut library from $dracutlib" >> /dev/kmsg
. "$dracutlib"
}
@@ -22,16 +22,17 @@ type getarg >/dev/null 2>&1 || {
# If root is not ZFS= or zfs: or rootfstype is not zfs
# then we are not supposed to handle it.
-[ "${root##zfs:}" = "${root}" -a "${root##ZFS=}" = "${root}" -a "$rootfstype" != "zfs" ] && exit 0
+[ "${root##zfs:}" = "${root}" ] &&
+ [ "${root##ZFS=}" = "${root}" ] &&
+ [ "$rootfstype" != "zfs" ] &&
+ exit 0
rootfstype=zfs
-if echo "${rootflags}" | grep -Eq '^zfsutil$|^zfsutil,|,zfsutil$|,zfsutil,' ; then
- true
-elif test -n "${rootflags}" ; then
- rootflags="zfsutil,${rootflags}"
-else
- rootflags=zfsutil
-fi
+case ",${rootflags}," in
+ *,zfsutil,*) ;;
+ ,,) rootflags=zfsutil ;;
+ *) rootflags="zfsutil,${rootflags}" ;;
+esac
echo "zfs-generator: writing extension for sysroot.mount to $GENERATOR_DIR"/sysroot.mount.d/zfs-enhancement.conf >> /dev/kmsg
@@ -58,4 +59,4 @@ echo "zfs-generator: writing extension for sysroot.mount to $GENERATOR_DIR"/sysr
[ -d "$GENERATOR_DIR"/initrd-root-fs.target.requires ] || mkdir -p "$GENERATOR_DIR"/initrd-root-fs.target.requires
ln -s ../sysroot.mount "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount
-echo "zfs-generator: finished" >> /dev/kmsg \ No newline at end of file
+echo "zfs-generator: finished" >> /dev/kmsg
diff --git a/contrib/dracut/90zfs/zfs-lib.sh.in b/contrib/dracut/90zfs/zfs-lib.sh.in
index f470bfcc5..c39cc5cff 100755
--- a/contrib/dracut/90zfs/zfs-lib.sh.in
+++ b/contrib/dracut/90zfs/zfs-lib.sh.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
command -v getarg >/dev/null || . /lib/dracut-lib.sh
command -v getargbool >/dev/null || {
@@ -144,7 +144,7 @@ ask_for_password() {
{ flock -s 9;
# Prompt for password with plymouth, if installed and running.
- if type plymouth >/dev/null 2>&1 && plymouth --ping 2>/dev/null; then
+ if plymouth --ping 2>/dev/null; then
plymouth ask-for-password \
--prompt "$ply_prompt" --number-of-tries="$ply_tries" \
--command="$ply_cmd"
diff --git a/contrib/dracut/90zfs/zfs-load-key.sh.in b/contrib/dracut/90zfs/zfs-load-key.sh.in
index 49d56e546..e29501418 100755
--- a/contrib/dracut/90zfs/zfs-load-key.sh.in
+++ b/contrib/dracut/90zfs/zfs-load-key.sh.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
# only run this on systemd systems, we handle the decrypt in mount-zfs.sh in the mount hook otherwise
[ -e /bin/systemctl ] || return 0
diff --git a/contrib/dracut/90zfs/zfs-needshutdown.sh.in b/contrib/dracut/90zfs/zfs-needshutdown.sh.in
index ddd3edae0..dd6de30c2 100755
--- a/contrib/dracut/90zfs/zfs-needshutdown.sh.in
+++ b/contrib/dracut/90zfs/zfs-needshutdown.sh.in
@@ -1,6 +1,6 @@
-#!/bin/bash
+#!/bin/sh
-type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
+command -v getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
if zpool list 2>&1 | grep -q 'no pools available' ; then
info "ZFS: No active pools, no need to export anything."