#!/bin/sh


for VERSION_PATH in $(find -L . -maxdepth 1 -type d -not -path '.'); do
  echo "Processing $VERSION_PATH"
  jq -s '{ release: .[0].version_number, profiles: [.[] | .target as $target | .profiles | keys[] as $k | { id: ($k), titles: (.[$k] | .titles), target: $target }] }' $(find -L "$VERSION_PATH" -iname 'profiles.json') > $VERSION_PATH/.overview.json

# debugging print: uncomment and comment line above. Run script by piping stdout to /dev/null
#  for file in  $(find -L "$VERSION_PATH" -iname 'profiles.json'); do
#    jq -s '{ release: .[0].version_number, profiles: [.[] | .target as $target | .profiles | keys[] as $k | { id: ($k), titles: (.[$k] | .titles), target: $target }] }' "$file"
#  done

done
