nixpkgs-suyu/pkgs/build-support/autonix/manifest.sh

45 lines
1.1 KiB
Bash
Raw Normal View History

2015-01-19 18:13:18 +01:00
#!@bash@/bin/bash
@coreutils@/bin/mkdir tmp; cd tmp
@wget@/bin/wget -nH -r -c --no-parent $*
2015-06-15 17:50:39 +02:00
cat >../manifest.json <<EOF
2015-01-19 18:13:18 +01:00
[
EOF
workdir=$(pwd)
2015-06-15 17:50:39 +02:00
sep=""
2015-01-19 18:13:18 +01:00
@findutils@/bin/find . | while read path; do
if [[ -f "${path}" ]]; then
2015-06-15 17:50:39 +02:00
[[ -n "${sep}" ]] && echo "$sep" >>../manifest.json
2015-01-19 18:13:18 +01:00
url="${path:2}"
# Sanitize file name
2015-06-15 17:50:39 +02:00
filename=$(@coreutils@/bin/basename "${path}" | tr '@' '_')
nameversion="${filename%.tar.*}"
name="${nameversion%-*}"
2015-01-19 18:13:18 +01:00
dirname=$(@coreutils@/bin/dirname "${path}")
2015-06-15 17:50:39 +02:00
mv "${workdir}/${path}" "${workdir}/${dirname}/${filename}"
2015-01-19 18:13:18 +01:00
# Prefetch and hash source file
2015-06-15 17:50:39 +02:00
sha256=$(@nix@/bin/nix-prefetch-url "file://${workdir}/${dirname}/${filename}")
store=$(@nix@/bin/nix-store --print-fixed-path sha256 "$sha256" "$filename")
cat >>../manifest.json <<EOF
2015-01-19 18:13:18 +01:00
{
2015-06-15 17:50:39 +02:00
"name": "${nameversion}",
"store": "${store}",
"src": {
"url": "${url}",
"sha256": "${sha256}",
"name": "${filename}"
}
2015-01-19 18:13:18 +01:00
}
EOF
2015-06-15 17:50:39 +02:00
sep=","
2015-01-19 18:13:18 +01:00
fi
done
2015-06-15 17:50:39 +02:00
echo "]" >>../manifest.json
2015-01-19 18:13:18 +01:00
cd ..