Merge pull request #330634 from r-ryantm/auto-update/circumflex
[NixPkgs.git] / pkgs / shells / bash / update-patch-set.sh
blobee785cc831235eb30e03f5213795b5c93d9e0589
1 #!/usr/bin/env nix-shell
2 #!nix-shell --pure -i bash -p wget -p gnupg -p cacert -p nix
4 # Update patch set for GNU Bash or Readline.
6 if [ $# -ne 2 ]
7 then
8 echo "Usage: $(basename "$0") PROJECT VERSION"
9 echo ""
10 echo "Update the patch set for PROJECT (one of \`bash' or \`readline') for"
11 echo "the given version (e.g., \`4.0'). Produce \`PROJECT-patches.nix'."
12 exit 1
15 PROJECT="$1"
16 VERSION="$2"
17 DIR=$(dirname "$0")
18 VERSION_CONDENSED="$(echo "$VERSION" | sed -es/\\.//g)"
19 PATCH_LIST="$DIR/$PROJECT-$VERSION-patches.nix"
21 set -e
23 rm -vf "$PATCH_LIST"
25 wget "https://tiswww.case.edu/php/chet/gpgkey.asc"
26 echo "4ef5051ce7200241e65d29c11eb57df8 gpgkey.asc" > gpgkey.asc.md5
27 md5sum -c gpgkey.asc.md5
28 gpg --import ./gpgkey.asc
29 rm gpgkey.asc{,.md5}
31 ( echo "# Automatically generated by \`$(basename "$0")'; do not edit." ; \
32 echo "" ; \
33 echo "patch: [" ) \
34 >> "$PATCH_LIST"
36 for i in {001..100}
38 wget -P "$DIR" "ftp.gnu.org/gnu/$PROJECT/$PROJECT-$VERSION-patches/$PROJECT$VERSION_CONDENSED-$i" || break
39 wget -P "$DIR" "ftp.gnu.org/gnu/$PROJECT/$PROJECT-$VERSION-patches/$PROJECT$VERSION_CONDENSED-$i.sig"
40 gpg --verify "$DIR/$PROJECT$VERSION_CONDENSED-$i.sig"
41 hash=$(nix-hash --flat --type sha256 --base32 "$DIR/$PROJECT$VERSION_CONDENSED-$i")
42 echo "(patch \"$i\" \"$hash\")" \
43 >> "$PATCH_LIST"
45 rm -f "$DIR/$PROJECT$VERSION_CONDENSED-$i"{,.sig}
46 done
48 echo "]" >> "$PATCH_LIST"
50 # bash interprets numbers starting with 0 as octals
51 echo "Got $((10#$i - 1)) patches."
52 echo "Patch list has been written to \`$PATCH_LIST'."