Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # Used to convert a single universe repo file with multiple
  3. # packages in to multiple build definition files
  4.  
  5. # Exit on errors
  6. set -e
  7.  
  8. # Takes one argument - valid path to a stub universe json file
  9. STUB_UNIVERSE_JSON=$1
  10.  
  11. if [[ ! -f $STUB_UNIVERSE_JSON ]]; then
  12. echo "$STUB_UNIVERSE_JSON is not a valid file" && exit 1
  13. fi
  14.  
  15. # Ensure jq is installed
  16. which jq || $(echo "jq is not installed" && exit 1)
  17.  
  18. if [ $(cat "$STUB_UNIVERSE_JSON" | jq -r type) = "object" ]; then
  19. # Parse each package
  20. packages=$(cat $STUB_UNIVERSE_JSON | jq .packages)
  21. for row in $(echo "$packages" | jq -r '.[] | @base64'); do
  22. data=$(echo "$row" | base64 --decode)
  23. name=$(echo "$data" | jq -r '.name')
  24. version=$(echo "$data" | jq -r '.version')
  25. filename="$name-$version.json"
  26.  
  27. packagingVersion=$(echo "$data" | jq -r '.packagingVersion')
  28. if (( ${packagingVersion%.*} >= 3)); then
  29. echo "$packagingVersion is supported. Creating $filename"
  30. else
  31. echo "$packagingVersion is not supported. Ignoring $filename"
  32. continue
  33. fi
  34.  
  35. echo "$data" | jq 'del(.releaseVersion,.selected)' > "$filename"
  36. echo "Created $filename"
  37. done
  38. else
  39. echo "Given file is not a valid json object"
  40. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement