2
0
Fork 0
genodepkgs/apps/generate-manifest/default.nix

41 lines
1.1 KiB
Nix

# SPDX-License-Identifier: CC0-1.0
{ stdenv, nixpkgs, dhallApps }:
with nixpkgs.buildPackages;
writeScriptBin "generate-manifest" ''
#!${runtimeShell}
root="$1"
if [ -z "$root" ]; then
echo a directory must be passed as an argument >> /dev/stderr
exit 1
fi
if [ ! -d "$root" ]; then
echo \'$root\' is not an existing directory >> /dev/stderr
exit 1
fi
set -eu
find="${findutils}/bin/find"
echo -n '{'
if [ -d "$root/bin" ]; then
echo -n ',bin = {'
find $root/bin/ -type f -printf '%f "%p"\n' \
| awk '{print ", "gensub(/\..*/, "", 1, $1)"={mapKey= \""$1"\",mapValue ="$2"}"}'
echo -n '}'
fi
if [ -d "$root/lib" ]; then
echo -n ',lib = {'
find $root/lib/ -type f -name '*.lib.so' -printf '%f "%p"\n' \
| awk '{print ", "gensub(/\..*/, "", 1, $1)"={mapKey=\""$1"\",mapValue="$2"}"}'
echo -n '}'
fi
if [ -d "$root/tar" ]; then
echo -n ',tar = {'
find $root/tar/ -type f -name '*.tar' -printf '%f "%p"\n' \
| awk '{print ""gensub(/\..*/, "", 1, $1)"={mapKey=\""$1"\",mapValue="$2"}" }'
echo -n '}'
fi
echo '}'
''