bash scripts: use /usr/bin/env for bash shebangs
Not all systems / distros have a `/bin/bash`, and these scripts are
more difficult to run at development time.
For example, my system is NixOS which doesn't have a /bin/bash. This
is not a problem for NixOS building ZFS as a package: the build
environment automatically replaces these shebangs with corrected
paths.
The problem is much more annoying at development time: either the
scripts don't run, or I correct them for my local machine and deal with
a perpetually dirty work tree.
Before committing this patch I confirmed there are existing scripts
which use `/usr/bin/env` to locate bash, so I am thinking this is a
safe transformation.
There are a handful of other shebangs in this repository which don't
work on my system. This patch is useful on its own specifically for
`commitcheck.sh`, otherwise I can't validate my commits before
submission.
Here are the remaining shebangs which NixOS systems won't have:
1274 #!/bin/ksh -p
91 #!/bin/ksh
89 #! /bin/ksh -p
2 #!/bin/sed -f
1 #!/usr/bin/perl -w
1 #!/usr/bin/ksh
1 #!/bin/nawk -f
plus this which will create an invalid shebang in
`tests/zfs-tests/tests/functional/mv_files/mv_files_common.kshlib`:
echo "#!/bin/ksh" > $TEST_BASE_DIR/exitsZero.ksh
I chose to leave those alone for now, and gauge the interest in this
much smaller patch first.
The fixes for these are easy enough by simply using `/usr/bin/env ksh`:
91 #!/bin/ksh
1 #!/usr/bin/ksh
The fix for the other set is much trickier. Quoting the GNU coreutils
manual:
Most operating systems (e.g. GNU/Linux, BSDs) treat all text after
the first space as a single argument. When using env in a script it
is thus not possible to specify multiple arguments.
and not all `env`'s support arguments.
Mine (GNU Coreutils 8.31) does, though this feature is new since
April 2018, GNU Coreutils 8.30:
https://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=668306ed86c8c79b0af0db8b9c882654ebb66db2
and worse, requires the -S argument:
-S, --split-string=S process and split S into separate arguments;
used to pass multiple arguments on shebang
lines
Example:
$ seq 1 2 | $(nix-build '<nixpkgs>' -A coreutils)/bin/env "sort -nr"
/nix/[...]-coreutils-8.31/bin/env: ‘sort -nr’: No such file or directory
/nix/[...]-coreutils-8.31/bin/env: use -[v]S to pass options in shebang lines
$ seq 1 2 | $(nix-build '<nixpkgs>' -A coreutils)/bin/env "-S sort -nr"
2
1
GNU Coreutils says FreeBSD's `env` does, though I wonder if FreeBSD's
would be unhappy with the `-S`:
https://www.gnu.org/software/coreutils/manual/html_node/env-invocation.html#env-invocation
BusyBox v1.30.1 does not, and does not have a `-S`-like option:
$ seq 1 2 | $(nix-build '<nixpkgs>' -A busybox)/bin/env "sort -nr"
env: can't execute 'sort -nr': No such file or directory
Toybox 0.8.1 also does not, and also does not have a `-S` option:
$ seq 1 2 | $(nix-build '<nixpkgs>' -A toybox)/bin/env "sort -nr"
env: exec sort -nr: No such file or directory
---
At any rate, if this patch merges and the remaining ~1,500 are updated,
the much larger patch should probably include a checkstyle-like test
asserting all new shebangs use `/usr/bin/env`. I also don't mind
dealing with NixOS weirdness if the project would prefer that.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Graham Christensen <graham@grahamc.com>
Closes #9893
2020-02-11 00:13:46 +03:00
|
|
|
#!/usr/bin/env bash
|
Trim excess shellcheck annotations. Widen to all non-Korn scripts
Before, make shellcheck checked
scripts/{commitcheck,make_gitrev,man-dates,paxcheck,zfs-helpers,zfs,
zfs-tests,zimport,zloop}.sh
cmd/zed/zed.d/{{all-debug,all-syslog,data-notify,generic-notify,
resilver_finish-start-scrub,scrub_finish-notify,
statechange-led,statechange-notify,trim_finish-notify,
zed-functions}.sh,history_event-zfs-list-cacher.sh.in}
cmd/zpool/zpool.d/{dm-deps,iostat,lsblk,media,ses,smart,upath}
now it also checks
contrib/dracut/{02zfsexpandknowledge/module-setup,
90zfs/{export-zfs,parse-zfs,zfs-needshutdown,
zfs-load-key,zfs-lib,module-setup,
mount-zfs,zfs-generator}}.sh.in
cmd/zed/zed.d/{pool_import-led,vdev_attach-led,
resilver_finish-notify,vdev_clear-led}.sh
contrib/initramfs/{zfsunlock,hooks/zfs.in,scripts/local-top/zfs}
tests/zfs-tests/tests/perf/scripts/prefetch_io.sh
scripts/common.sh.in
contrib/bpftrace/zfs-trace.sh
autogen.sh
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12042
2021-05-14 15:02:11 +03:00
|
|
|
# shellcheck disable=SC2154
|
2011-07-04 21:25:31 +04:00
|
|
|
|
|
|
|
check() {
|
2011-07-25 00:46:16 +04:00
|
|
|
# We depend on udev-rules being loaded
|
2022-11-12 15:22:49 +03:00
|
|
|
[[ "${1}" = "-d" ]] && return 0
|
2011-07-04 21:25:31 +04:00
|
|
|
|
2011-07-25 00:46:16 +04:00
|
|
|
# Verify the zfs tool chain
|
2022-02-14 19:58:37 +03:00
|
|
|
for tool in "zgenhostid" "zpool" "zfs" "mount.zfs"; do
|
|
|
|
command -v "${tool}" >/dev/null || return 1
|
2016-04-24 14:35:44 +03:00
|
|
|
done
|
2011-07-04 21:25:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
depends() {
|
2011-07-25 00:46:16 +04:00
|
|
|
echo udev-rules
|
2011-07-04 21:25:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
installkernel() {
|
2022-02-06 07:11:23 +03:00
|
|
|
instmods -c zfs
|
2011-07-04 21:25:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
install() {
|
2022-02-14 15:45:16 +03:00
|
|
|
inst_rules 90-zfs.rules 69-vdev.rules 60-zvol.rules
|
2022-02-14 19:58:37 +03:00
|
|
|
|
2022-02-06 07:11:23 +03:00
|
|
|
inst_multiple \
|
2022-02-14 15:45:16 +03:00
|
|
|
zgenhostid \
|
|
|
|
zfs \
|
|
|
|
zpool \
|
|
|
|
mount.zfs \
|
2022-01-25 06:22:48 +03:00
|
|
|
hostid \
|
|
|
|
grep \
|
|
|
|
awk \
|
|
|
|
tr \
|
|
|
|
cut \
|
2022-02-06 07:11:23 +03:00
|
|
|
head ||
|
|
|
|
{ dfatal "Failed to install essential binaries"; exit 1; }
|
2022-02-14 19:58:37 +03:00
|
|
|
|
|
|
|
# Adapted from https://github.com/zbm-dev/zfsbootmenu
|
2023-06-29 22:54:37 +03:00
|
|
|
if ! ldd "$(command -v zpool)" | grep -qF 'libgcc_s.so' && ldconfig -p 2> /dev/null | grep -qF 'libc.so.6' ; then
|
2022-02-06 07:11:23 +03:00
|
|
|
# On systems with gcc-config (Gentoo, Funtoo, etc.), use it to find libgcc_s
|
2022-02-14 19:58:37 +03:00
|
|
|
if command -v gcc-config >/dev/null; then
|
|
|
|
inst_simple "/usr/lib/gcc/$(s=$(gcc-config -c); echo "${s%-*}/${s##*-}")/libgcc_s.so.1" ||
|
2022-02-06 07:11:23 +03:00
|
|
|
{ dfatal "Unable to install libgcc_s.so"; exit 1; }
|
|
|
|
# Otherwise, use dracut's library installation function to find the right one
|
|
|
|
elif ! inst_libdir_file "libgcc_s.so*"; then
|
|
|
|
# If all else fails, just try looking for some gcc arch directory
|
2022-02-14 19:58:37 +03:00
|
|
|
inst_simple /usr/lib/gcc/*/*/libgcc_s.so* ||
|
2022-02-06 07:11:23 +03:00
|
|
|
{ dfatal "Unable to install libgcc_s.so"; exit 1; }
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-02-15 22:28:42 +03:00
|
|
|
inst_hook cmdline 95 "${moddir}/parse-zfs.sh"
|
2022-11-12 15:22:49 +03:00
|
|
|
if [[ -n "${systemdutildir}" ]]; then
|
2022-02-14 19:58:37 +03:00
|
|
|
inst_script "${moddir}/zfs-generator.sh" "${systemdutildir}/system-generators/dracut-zfs-generator"
|
2016-03-31 02:59:15 +03:00
|
|
|
fi
|
2018-01-18 21:20:34 +03:00
|
|
|
inst_hook pre-mount 90 "${moddir}/zfs-load-key.sh"
|
2016-04-24 14:35:44 +03:00
|
|
|
inst_hook mount 98 "${moddir}/mount-zfs.sh"
|
2016-10-17 21:51:15 +03:00
|
|
|
inst_hook cleanup 99 "${moddir}/zfs-needshutdown.sh"
|
2016-10-16 06:30:53 +03:00
|
|
|
inst_hook shutdown 20 "${moddir}/export-zfs.sh"
|
2011-09-30 21:33:26 +04:00
|
|
|
|
2022-02-14 19:58:37 +03:00
|
|
|
inst_script "${moddir}/zfs-lib.sh" "/lib/dracut-zfs-lib.sh"
|
2013-03-20 22:25:50 +04:00
|
|
|
|
2022-02-14 19:58:37 +03:00
|
|
|
# -H ensures they are marked host-only
|
|
|
|
# -o ensures there is no error upon absence of these files
|
|
|
|
inst_multiple -o -H \
|
|
|
|
"@sysconfdir@/zfs/zpool.cache" \
|
|
|
|
"@sysconfdir@/zfs/vdev_id.conf"
|
2015-02-16 06:08:04 +03:00
|
|
|
|
2011-09-30 21:33:26 +04:00
|
|
|
# Synchronize initramfs and system hostid
|
2022-02-14 19:58:37 +03:00
|
|
|
if ! inst_simple -H @sysconfdir@/hostid; then
|
2022-11-12 15:22:49 +03:00
|
|
|
if HOSTID="$(hostid 2>/dev/null)" && [[ "${HOSTID}" != "00000000" ]]; then
|
2022-02-14 19:58:37 +03:00
|
|
|
zgenhostid -o "${initdir}@sysconfdir@/hostid" "${HOSTID}"
|
|
|
|
mark_hostonly @sysconfdir@/hostid
|
|
|
|
fi
|
2020-11-13 06:00:59 +03:00
|
|
|
fi
|
2016-03-31 02:59:15 +03:00
|
|
|
|
|
|
|
if dracut_module_included "systemd"; then
|
2022-02-14 19:58:37 +03:00
|
|
|
inst_simple "${systemdsystemunitdir}/zfs-import.target"
|
|
|
|
systemctl -q --root "${initdir}" add-wants initrd.target zfs-import.target
|
2021-06-10 19:26:37 +03:00
|
|
|
|
2022-02-14 19:58:37 +03:00
|
|
|
inst_simple "${moddir}/zfs-env-bootfs.service" "${systemdsystemunitdir}/zfs-env-bootfs.service"
|
|
|
|
systemctl -q --root "${initdir}" add-wants zfs-import.target zfs-env-bootfs.service
|
2021-06-10 19:26:37 +03:00
|
|
|
|
contrib: dracut: fix race with root=zfs:dset when necessities required
This had always worked in my testing, but a user on hardware reported
this to happen 100%, and I reproduced it once with cold VM host caches.
dracut-zfs-generator runs as a systemd generator, i.e. at Some
Relatively Early Time; if root= is a fixed dataset, it tries to
"solve [necessities] statically at generation time".
If by that point zfs-import.target hasn't popped (because the import is
taking a non-negligible amount of time for whatever reason), it'll see
no children for the root datase, and as such generate no mounts.
This has never had any right to work. No-one caught this earlier because
it's just that much more convenient to have root=zfs:AUTO, which orders
itself properly.
To fix this, always run zfs-nonroot-necessities.service;
this additionally simplifies the implementation by:
* making BOOTFS from zfs-env-bootfs.service be the real, canonical,
root dataset name, not just "whatever the first bootfs is",
and only set it if we're ZFS-booting
* zfs-{rollback,snapshot}-bootfs.service can use this instead of
re-implementing it
* having zfs-env-bootfs.service also set BOOTFSFLAGS
* this means the sysroot.mount drop-in can be fixed text
* zfs-nonroot-necessities.service can also be constant and always
enabled, because it's conditioned on BOOTFS being set
There is no longer any code generated at run-time
(the sysroot.mount drop-in is an unavoidable gratuitous cp).
The flow of BOOTFS{,FLAGS} from zfs-env-bootfs.service to sysroot.mount
is not noted explicitly in dracut.zfs(7), because (a) at some point it's
just visual noise and (b) it's already ordered via d-p-m.s from z-i.t.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #14690
2023-03-31 19:47:48 +03:00
|
|
|
inst_simple "${moddir}/zfs-nonroot-necessities.service" "${systemdsystemunitdir}/zfs-nonroot-necessities.service"
|
|
|
|
systemctl -q --root "${initdir}" add-requires initrd-root-fs.target zfs-nonroot-necessities.service
|
|
|
|
|
2022-10-23 12:11:18 +03:00
|
|
|
# Add user-provided unit overrides:
|
|
|
|
# - /etc/systemd/system/${_service}
|
|
|
|
# - /etc/systemd/system/${_service}.d/overrides.conf
|
|
|
|
# -H ensures they are marked host-only
|
|
|
|
# -o ensures there is no error upon absence of these files
|
|
|
|
inst_multiple -o -H \
|
|
|
|
"${systemdsystemconfdir}/zfs-import.target" \
|
|
|
|
"${systemdsystemconfdir}/zfs-import.target.d/"*.conf
|
|
|
|
|
2022-02-14 19:58:37 +03:00
|
|
|
for _service in \
|
|
|
|
"zfs-import-scan.service" \
|
2022-06-21 20:37:20 +03:00
|
|
|
"zfs-import-cache.service"; do
|
2022-02-14 19:58:37 +03:00
|
|
|
inst_simple "${systemdsystemunitdir}/${_service}"
|
|
|
|
systemctl -q --root "${initdir}" add-wants zfs-import.target "${_service}"
|
2022-10-23 11:55:46 +03:00
|
|
|
|
2022-10-23 12:11:18 +03:00
|
|
|
# Add user-provided unit overrides:
|
|
|
|
# - /etc/systemd/system/${_service}
|
|
|
|
# - /etc/systemd/system/${_service}.d/overrides.conf
|
2022-10-23 11:55:46 +03:00
|
|
|
# -H ensures they are marked host-only
|
|
|
|
# -o ensures there is no error upon absence of these files
|
|
|
|
inst_multiple -o -H \
|
|
|
|
"${systemdsystemconfdir}/${_service}" \
|
|
|
|
"${systemdsystemconfdir}/${_service}.d/"*.conf
|
|
|
|
|
2022-02-14 19:58:37 +03:00
|
|
|
done
|
2021-06-10 19:26:37 +03:00
|
|
|
|
2022-02-14 19:58:37 +03:00
|
|
|
for _service in \
|
|
|
|
"zfs-snapshot-bootfs.service" \
|
|
|
|
"zfs-rollback-bootfs.service"; do
|
|
|
|
inst_simple "${moddir}/${_service}" "${systemdsystemunitdir}/${_service}"
|
|
|
|
systemctl -q --root "${initdir}" add-wants initrd.target "${_service}"
|
2022-10-23 12:11:58 +03:00
|
|
|
|
|
|
|
# Add user-provided unit overrides:
|
|
|
|
# - /etc/systemd/system/${_service}
|
|
|
|
# - /etc/systemd/system/${_service}.d/overrides.conf
|
|
|
|
# -H ensures they are marked host-only
|
|
|
|
# -o ensures there is no error upon absence of these files
|
|
|
|
inst_multiple -o -H \
|
|
|
|
"${systemdsystemconfdir}/${_service}" \
|
|
|
|
"${systemdsystemconfdir}/${_service}.d/"*.conf
|
2020-05-30 07:16:08 +03:00
|
|
|
done
|
2021-06-10 19:26:37 +03:00
|
|
|
|
2022-02-14 19:58:37 +03:00
|
|
|
inst_simple "${moddir}/import-opts-generator.sh" "${systemdutildir}/system-environment-generators/zfs-import-opts.sh"
|
2016-03-31 02:59:15 +03:00
|
|
|
fi
|
2011-07-04 21:25:31 +04:00
|
|
|
}
|