1
0

update.sh 869 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env bash
  2. # shellcheck disable=SC2016
  3. set -euo pipefail
  4. plugins=$(< sources.json)
  5. q() {
  6. jq -r "$@" <<<"$plugins"
  7. }
  8. u() {
  9. plugins=$(jq "$@" <<<"$plugins")
  10. }
  11. update_plugin() {
  12. name=$1
  13. branch=$(q --arg name "$name" '.[$name].branch // "HEAD"')
  14. echo "Updating $name" >&2
  15. revision=$(git ls-remote "https://github.com/$name" "$branch" | cut -b -40)
  16. sha256=$(nix-prefetch-url --unpack "https://github.com/$name/archive/$revision.tar.gz")
  17. u --arg name "$name" --arg rev "$revision" --arg sha256 "$sha256" '
  18. .[$name] = (.[$name] // {}) * {
  19. rev: $rev,
  20. sha256: $sha256,
  21. }
  22. '
  23. }
  24. update_all() {
  25. for plugin in $(q 'to_entries | .[] | .key'); do
  26. update_plugin "$plugin"
  27. done
  28. }
  29. if [ "$#" -eq 0 ]; then
  30. update_all
  31. else
  32. while [ "$#" -gt 0 ]; do
  33. update_plugin "$1"
  34. shift
  35. done
  36. fi
  37. echo "$plugins" > sources.json