2022-08-16 22:00:00 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
internal scripts: use pinned, cached pkgs
Instead of setting up the script PATH via nix-shell, use
`nix shell` with inputs from the nix-bitcoin flake.
Advantages:
- Uses the nixpkgs version from the nix-bitcoin flake instead of
`<nixpkgs>` from the user env (NIX_PATH), so the script runtime
env is reproducible.
- The pkg derivations for the runtime env are cached, which greatly
increases script startup speed.
This commit was generated by running the following script inside the
repo root dir:
def transform(path, src)
if src =~ /#! *nix-shell +-i +bash +-p +(.*)/
pkgs = $1
if src =~ /^.*?(set -e.*?pipefail)\n/
set_statement = $1
src.sub!($&, '')
end
src.sub!(/\A.*?#! *nix-shell.*?\n/m, '')
parents = ([ '..' ] * (path.split('/').count - 1)).join('/')
[
'#!/usr/bin/env bash',
*set_statement,
%(. "${BASH_SOURCE[0]%/*}/#{parents}/helper/run-in-nix-env" "#{pkgs}" "$@"),
nil,
src
].join("\n")
end
end
Dir['**/*.sh'].each do |f|
src = File.read(f)
if new_src = transform(f, src)
puts "Changed file #{f}"
File.write(f, new_src)
end
end
2022-08-22 15:57:39 +03:00
|
|
|
. "${BASH_SOURCE[0]%/*}/../helper/run-in-nix-env" "shellcheck findutils gnugrep" "$@"
|
2022-08-16 22:00:00 +03:00
|
|
|
|
2022-09-05 19:12:09 +03:00
|
|
|
# Shellcheck all bash sources in this repo
|
|
|
|
|
2022-08-16 22:00:00 +03:00
|
|
|
cd "${BASH_SOURCE[0]%/*}/.."
|
|
|
|
{
|
|
|
|
# Skip .git dir in all find commands
|
|
|
|
find . -type f ! -path './.git/*' -name '*.sh'
|
|
|
|
# Find files without extensions that have a shell shebang
|
|
|
|
find . -type f ! -path './.git/*' ! -name "*.*" -exec grep -lP '\A^#! */usr/bin/env (?:nix-shell|bash)' {} \;
|
|
|
|
} | while IFS= read -r path; do
|
|
|
|
echo "$path"
|
|
|
|
file=${path##*/}
|
|
|
|
dir=${path%/*}
|
|
|
|
# Switch working directory so that shellcheck can access external sources
|
|
|
|
# (via arg `--external-sources`)
|
|
|
|
pushd "$dir" > /dev/null
|
|
|
|
shellcheck --external-sources --shell bash "$file"
|
|
|
|
popd > /dev/null
|
|
|
|
done
|