#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix-update git jq

# Get the current version of the protobuf Java library
# from nixpkgs to avoid ProtobufRuntimeVersionException

set -euo pipefail

nixpkgs="$(git rev-parse --show-toplevel)"
protobufSrc="$(nix-build --no-out-link "$nixpkgs" -A protobuf_35.src)"
protobufJavaVer=$(cat "$protobufSrc/version.json" | jq -r 'map(to_entries) | last | from_entries | ."languages"."java"')

echo "\"$protobufJavaVer\" # Generated by update.sh, do not edit" > "$nixpkgs/pkgs/by-name/tr/traccar/protobuf-java-version.nix"

pushd "$nixpkgs"
nix-update traccar
popd
