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
|
2016-03-31 02:59:15 +03:00
|
|
|
|
|
|
|
get_devtype() {
|
|
|
|
local typ
|
|
|
|
typ=$(udevadm info --query=property --name="$1" | grep "^ID_FS_TYPE=" | sed 's|^ID_FS_TYPE=||')
|
|
|
|
if [ "$typ" = "" ] ; then
|
|
|
|
typ=$(blkid -c /dev/null "$1" -o value -s TYPE)
|
|
|
|
fi
|
|
|
|
echo "$typ"
|
|
|
|
}
|
|
|
|
|
|
|
|
get_pool_devices() {
|
|
|
|
# also present in 99zfssystemd
|
|
|
|
local poolconfigtemp
|
|
|
|
local poolconfigoutput
|
|
|
|
local pooldev
|
2016-04-24 14:35:44 +03:00
|
|
|
local resolved
|
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
|
|
|
poolconfigtemp="$(mktemp)"
|
2021-05-14 12:55:17 +03:00
|
|
|
if ! @sbindir@/zpool list -v -H -P "$1" > "$poolconfigtemp" 2>&1 ; then
|
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
|
|
|
poolconfigoutput="$(cat "$poolconfigtemp")"
|
2016-03-31 02:59:15 +03:00
|
|
|
dinfo "zfsexpandknowledge: pool $1 cannot be listed: $poolconfigoutput"
|
|
|
|
else
|
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
|
|
|
awk -F '\t' '/\t\/dev/ { print $2 }' "$poolconfigtemp" | \
|
|
|
|
while read -r pooldev ; do
|
|
|
|
if [ -e "$pooldev" ] ; then
|
|
|
|
resolved="$(readlink -f "$pooldev")"
|
2016-04-24 14:35:44 +03:00
|
|
|
dinfo "zfsexpandknowledge: pool $1 has device $pooldev (which resolves to $resolved)"
|
|
|
|
echo "$resolved"
|
2016-03-31 02:59:15 +03:00
|
|
|
fi
|
2017-02-01 01:25:49 +03:00
|
|
|
done
|
2016-03-31 02:59:15 +03:00
|
|
|
fi
|
|
|
|
rm -f "$poolconfigtemp"
|
|
|
|
}
|
|
|
|
|
|
|
|
find_zfs_block_devices() {
|
|
|
|
local dev
|
|
|
|
local mp
|
|
|
|
local fstype
|
|
|
|
local pool
|
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
|
|
|
local _
|
|
|
|
numfields="$(awk '{print NF; exit}' /proc/self/mountinfo)"
|
|
|
|
if [ "$numfields" = "10" ] ; then
|
|
|
|
fields="_ _ _ _ mp _ _ fstype dev _"
|
2016-03-31 02:59:15 +03:00
|
|
|
else
|
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
|
|
|
fields="_ _ _ _ mp _ _ _ fstype dev _"
|
2016-03-31 02:59:15 +03:00
|
|
|
fi
|
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=SC2086
|
|
|
|
while read -r ${fields?} ; do
|
|
|
|
[ "$fstype" = "zfs" ] || continue
|
|
|
|
if [ "$mp" = "$1" ]; then
|
2016-03-31 02:59:15 +03:00
|
|
|
pool=$(echo "$dev" | cut -d / -f 1)
|
|
|
|
get_pool_devices "$pool"
|
|
|
|
fi
|
|
|
|
done < /proc/self/mountinfo
|
|
|
|
}
|
|
|
|
|
|
|
|
array_contains () {
|
|
|
|
local e
|
|
|
|
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
check() {
|
|
|
|
local mp
|
|
|
|
local dev
|
|
|
|
local blockdevs
|
|
|
|
local fstype
|
|
|
|
local majmin
|
2020-06-11 03:07:59 +03:00
|
|
|
local _depdev
|
|
|
|
local _depdevname
|
|
|
|
local _depdevtype
|
2016-03-31 02:59:15 +03:00
|
|
|
|
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
|
|
|
|
if [ -n "$hostonly" ]; then
|
2016-03-31 02:59:15 +03:00
|
|
|
|
|
|
|
for mp in \
|
|
|
|
"/" \
|
|
|
|
"/etc" \
|
|
|
|
"/bin" \
|
|
|
|
"/sbin" \
|
|
|
|
"/lib" \
|
|
|
|
"/lib64" \
|
|
|
|
"/usr" \
|
|
|
|
"/usr/bin" \
|
|
|
|
"/usr/sbin" \
|
|
|
|
"/usr/lib" \
|
|
|
|
"/usr/lib64" \
|
|
|
|
"/boot";
|
|
|
|
do
|
|
|
|
mp=$(readlink -f "$mp")
|
|
|
|
mountpoint "$mp" >/dev/null 2>&1 || continue
|
|
|
|
blockdevs=$(find_zfs_block_devices "$mp")
|
|
|
|
if [ -z "$blockdevs" ] ; then continue ; fi
|
2021-04-13 23:31:26 +03:00
|
|
|
dinfo "zfsexpandknowledge: block devices backing ZFS dataset $mp: ${blockdevs//$'\n'/ }"
|
2016-03-31 02:59:15 +03:00
|
|
|
for dev in $blockdevs
|
|
|
|
do
|
|
|
|
array_contains "$dev" "${host_devs[@]}" || host_devs+=("$dev")
|
|
|
|
fstype=$(get_devtype "$dev")
|
|
|
|
host_fs_types["$dev"]="$fstype"
|
|
|
|
majmin=$(get_maj_min "$dev")
|
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
|
|
|
if [ -d "/sys/dev/block/$majmin/slaves" ] ; then
|
|
|
|
for _depdev in "/sys/dev/block/$majmin/slaves"/*; do
|
2020-06-11 03:07:59 +03:00
|
|
|
[[ -f $_depdev/dev ]] || continue
|
|
|
|
_depdev=/dev/$(basename "$_depdev")
|
|
|
|
_depdevname=$(udevadm info --query=property --name="$_depdev" | grep "^DEVNAME=" | sed 's|^DEVNAME=||')
|
|
|
|
_depdevtype=$(get_devtype "$_depdevname")
|
2021-04-13 23:31:26 +03:00
|
|
|
dinfo "zfsexpandknowledge: underlying block device backing ZFS dataset $mp: ${_depdevname//$'\n'/ }"
|
2020-06-11 03:07:59 +03:00
|
|
|
array_contains "$_depdevname" "${host_devs[@]}" || host_devs+=("$_depdevname")
|
|
|
|
host_fs_types["$_depdevname"]="$_depdevtype"
|
2016-03-31 02:59:15 +03:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
for a in "${host_devs[@]}"
|
|
|
|
do
|
|
|
|
dinfo "zfsexpandknowledge: host device $a"
|
|
|
|
done
|
|
|
|
for a in "${!host_fs_types[@]}"
|
|
|
|
do
|
|
|
|
dinfo "zfsexpandknowledge: device $a of type ${host_fs_types[$a]}"
|
|
|
|
done
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|