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-10 21:13:46 +00:00
|
|
|
#!/usr/bin/env bash
|
2011-07-04 17:25:31 +00:00
|
|
|
|
|
|
|
check() {
|
2011-07-24 20:46:16 +00:00
|
|
|
# We depend on udev-rules being loaded
|
2015-02-15 19:28:42 +00:00
|
|
|
[ "${1}" = "-d" ] && return 0
|
2011-07-04 17:25:31 +00:00
|
|
|
|
2011-07-24 20:46:16 +00:00
|
|
|
# Verify the zfs tool chain
|
2020-09-16 19:25:12 +00:00
|
|
|
for tool in "@bindir@/zgenhostid" "@sbindir@/zpool" "@sbindir@/zfs" "@mounthelperdir@/mount.zfs" ; do
|
2016-04-24 11:35:44 +00:00
|
|
|
test -x "$tool" || return 1
|
|
|
|
done
|
|
|
|
# Verify grep exists
|
|
|
|
which grep >/dev/null 2>&1 || return 1
|
2011-07-04 17:25:31 +00:00
|
|
|
|
2011-07-24 20:46:16 +00:00
|
|
|
return 0
|
2011-07-04 17:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
depends() {
|
2011-07-24 20:46:16 +00:00
|
|
|
echo udev-rules
|
|
|
|
return 0
|
2011-07-04 17:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
installkernel() {
|
2011-07-24 20:46:16 +00:00
|
|
|
instmods zfs
|
|
|
|
instmods zcommon
|
|
|
|
instmods znvpair
|
|
|
|
instmods zavl
|
|
|
|
instmods zunicode
|
2018-02-08 16:16:23 +00:00
|
|
|
instmods zlua
|
2017-09-12 20:15:11 +00:00
|
|
|
instmods icp
|
2011-07-24 20:46:16 +00:00
|
|
|
instmods spl
|
|
|
|
instmods zlib_deflate
|
|
|
|
instmods zlib_inflate
|
2011-07-04 17:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
install() {
|
2011-08-09 21:39:47 +00:00
|
|
|
inst_rules @udevruledir@/90-zfs.rules
|
2013-03-20 18:25:50 +00:00
|
|
|
inst_rules @udevruledir@/69-vdev.rules
|
2011-08-09 21:39:47 +00:00
|
|
|
inst_rules @udevruledir@/60-zvol.rules
|
2016-04-24 11:35:44 +00:00
|
|
|
dracut_install hostid
|
|
|
|
dracut_install grep
|
2020-09-16 19:25:12 +00:00
|
|
|
dracut_install @bindir@/zgenhostid
|
2011-08-09 21:39:47 +00:00
|
|
|
dracut_install @sbindir@/zfs
|
|
|
|
dracut_install @sbindir@/zpool
|
2016-09-21 20:35:16 +00:00
|
|
|
# Workaround for zfsonlinux/zfs#4749 by ensuring libgcc_s.so(.1) is included
|
|
|
|
if [[ -n "$(ldd @sbindir@/zpool | grep -F 'libgcc_s.so')" ]]; then
|
|
|
|
# Dracut will have already tracked and included it
|
|
|
|
:;
|
|
|
|
elif command -v gcc-config 2>&1 1>/dev/null; then
|
|
|
|
# On systems with gcc-config (Gentoo, Funtoo, etc.):
|
|
|
|
# Use the current profile to resolve the appropriate path
|
2016-09-01 16:15:10 +00:00
|
|
|
dracut_install "/usr/lib/gcc/$(s=$(gcc-config -c); echo ${s%-*}/${s##*-})/libgcc_s.so.1"
|
2017-10-09 21:34:26 +00:00
|
|
|
elif [[ -n "$(ls /usr/lib/libgcc_s.so* 2>/dev/null)" ]]; then
|
|
|
|
# Try a simple path first
|
|
|
|
dracut_install /usr/lib/libgcc_s.so*
|
2016-09-01 16:15:10 +00:00
|
|
|
else
|
2016-09-21 20:35:16 +00:00
|
|
|
# Fallback: Guess the path and include all matches
|
|
|
|
dracut_install /usr/lib/gcc/*/*/libgcc_s.so*
|
2016-09-01 16:15:10 +00:00
|
|
|
fi
|
2017-12-17 22:14:07 +00:00
|
|
|
dracut_install @mounthelperdir@/mount.zfs
|
2013-01-29 18:53:19 +00:00
|
|
|
dracut_install @udevdir@/vdev_id
|
2017-08-04 18:14:48 +00:00
|
|
|
dracut_install awk
|
2018-05-30 00:32:05 +00:00
|
|
|
dracut_install basename
|
2018-12-13 23:48:46 +00:00
|
|
|
dracut_install cut
|
2017-08-04 18:14:48 +00:00
|
|
|
dracut_install head
|
2011-08-09 21:39:47 +00:00
|
|
|
dracut_install @udevdir@/zvol_id
|
2015-02-15 19:28:42 +00:00
|
|
|
inst_hook cmdline 95 "${moddir}/parse-zfs.sh"
|
2016-03-30 23:59:15 +00:00
|
|
|
if [ -n "$systemdutildir" ] ; then
|
|
|
|
inst_script "${moddir}/zfs-generator.sh" "$systemdutildir"/system-generators/dracut-zfs-generator
|
|
|
|
fi
|
2018-01-18 18:20:34 +00:00
|
|
|
inst_hook pre-mount 90 "${moddir}/zfs-load-key.sh"
|
2016-04-24 11:35:44 +00:00
|
|
|
inst_hook mount 98 "${moddir}/mount-zfs.sh"
|
2016-10-17 18:51:15 +00:00
|
|
|
inst_hook cleanup 99 "${moddir}/zfs-needshutdown.sh"
|
2016-10-16 03:30:53 +00:00
|
|
|
inst_hook shutdown 20 "${moddir}/export-zfs.sh"
|
2011-09-30 17:33:26 +00:00
|
|
|
|
2015-02-15 19:28:42 +00:00
|
|
|
inst_simple "${moddir}/zfs-lib.sh" "/lib/dracut-zfs-lib.sh"
|
2013-03-20 18:25:50 +00:00
|
|
|
if [ -e @sysconfdir@/zfs/zpool.cache ]; then
|
|
|
|
inst @sysconfdir@/zfs/zpool.cache
|
2016-03-30 23:59:15 +00:00
|
|
|
type mark_hostonly >/dev/null 2>&1 && mark_hostonly @sysconfdir@/zfs/zpool.cache
|
2013-03-20 18:25:50 +00:00
|
|
|
fi
|
|
|
|
|
2015-02-16 03:08:04 +00:00
|
|
|
if [ -e @sysconfdir@/zfs/vdev_id.conf ]; then
|
|
|
|
inst @sysconfdir@/zfs/vdev_id.conf
|
2016-03-30 23:59:15 +00:00
|
|
|
type mark_hostonly >/dev/null 2>&1 && mark_hostonly @sysconfdir@/zfs/vdev_id.conf
|
2015-02-16 03:08:04 +00:00
|
|
|
fi
|
|
|
|
|
2011-09-30 17:33:26 +00:00
|
|
|
# Synchronize initramfs and system hostid
|
2020-09-16 19:25:12 +00:00
|
|
|
zgenhostid -o "${initdir}/etc/hostid" "$(hostid)"
|
2016-03-30 23:59:15 +00:00
|
|
|
|
|
|
|
if dracut_module_included "systemd"; then
|
2018-07-31 17:15:41 +00:00
|
|
|
mkdir -p "${initdir}/$systemdsystemunitdir/zfs-import.target.wants"
|
2016-03-30 23:59:15 +00:00
|
|
|
for _item in scan cache ; do
|
|
|
|
dracut_install @systemdunitdir@/zfs-import-$_item.service
|
2018-07-31 17:15:41 +00:00
|
|
|
if ! [ -L "${initdir}/$systemdsystemunitdir/zfs-import.target.wants"/zfs-import-$_item.service ]; then
|
|
|
|
ln -s ../zfs-import-$_item.service "${initdir}/$systemdsystemunitdir/zfs-import.target.wants"/zfs-import-$_item.service
|
2016-03-30 23:59:15 +00:00
|
|
|
type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-import-$_item.service
|
|
|
|
fi
|
|
|
|
done
|
2019-04-03 00:14:39 +00:00
|
|
|
inst "${moddir}"/zfs-env-bootfs.service "${systemdsystemunitdir}"/zfs-env-bootfs.service
|
|
|
|
ln -s ../zfs-env-bootfs.service "${initdir}/${systemdsystemunitdir}/zfs-import.target.wants"/zfs-env-bootfs.service
|
|
|
|
type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-env-bootfs.service
|
2018-07-16 22:11:36 +00:00
|
|
|
dracut_install systemd-ask-password
|
|
|
|
dracut_install systemd-tty-ask-password-agent
|
2018-07-31 17:15:41 +00:00
|
|
|
mkdir -p "${initdir}/$systemdsystemunitdir/initrd.target.wants"
|
|
|
|
dracut_install @systemdunitdir@/zfs-import.target
|
|
|
|
if ! [ -L "${initdir}/$systemdsystemunitdir/initrd.target.wants"/zfs-import.target ]; then
|
|
|
|
ln -s ../zfs-import.target "${initdir}/$systemdsystemunitdir/initrd.target.wants"/zfs-import.target
|
|
|
|
type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-import.target
|
|
|
|
fi
|
2020-05-30 04:16:08 +00:00
|
|
|
for _service in zfs-snapshot-bootfs.service zfs-rollback-bootfs.service ; do
|
|
|
|
inst "${moddir}"/$_service "${systemdsystemunitdir}"/$_service
|
|
|
|
if ! [ -L "${initdir}/$systemdsystemunitdir/initrd.target.wants"/$_service ]; then
|
|
|
|
ln -s ../$_service "${initdir}/$systemdsystemunitdir/initrd.target.wants"/$_service
|
|
|
|
fi
|
|
|
|
done
|
2016-03-30 23:59:15 +00:00
|
|
|
fi
|
2011-07-04 17:25:31 +00:00
|
|
|
}
|