get.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/sh
  2. list_toys() {
  3. toys=$(find toys/ -mindepth 1 -maxdepth 1 -type d | sed 's|toys/||' | sort)
  4. echo "$toys" | while read -r toy
  5. do
  6. status=$(show_item "$toy" 'latest' | head -n1 | cut -d ';' -f1)
  7. printf '%s;%s\n' "$status" "$toy"
  8. done
  9. }
  10. list_items() {
  11. toy=$1
  12. if [ ! -d "toys/$toy" ]
  13. then
  14. printf "n;"
  15. else
  16. printf "0;"
  17. items=$(find "toys/$toy" -mindepth 1 -maxdepth 1 -type d | grep -E '[0-9]+' | sed "s|toys/$toy/||" | sort -nr)
  18. if [ -z "$items" ]
  19. then
  20. return
  21. fi
  22. echo "$items" | while read -r item
  23. do
  24. status=$(show_item "$toy" "$item" | head -n1 | cut -d ';' -f1)
  25. printf '%s,%s ' "$status" "$item"
  26. done
  27. fi
  28. }
  29. show_item() {
  30. toy=$1
  31. item=$2
  32. [ "$item" = 'latest' ] && item=$(find "toys/$toy/" -type d -mindepth 1 -maxdepth 1 | grep -E '[0-9]+' | sed "s|toys/$toy/||" | sort -n | tail -n1 | sed "s|toys/$toy/||")
  33. if [ "$(podman inspect "item_${toy}_${item}" 2>/dev/null | jq -r '.[0].State.Status')" = 'exited' ]
  34. then
  35. podman inspect "item_${toy}_${item}" | jq '.[0].State.ExitCode' > "toys/$toy/$item.exit"
  36. podman rm "item_${toy}_${item}" >/dev/null 2>&1
  37. fi
  38. if [ -z "$item" ] || [ ! -d "toys/$toy/$item" ]
  39. then
  40. printf 'n;'
  41. elif [ ! -f "toys/$toy/$item.exit" ]
  42. then
  43. printf 'r;'
  44. awk -f log_parser.awk "toys/$toy/$item.log"
  45. else
  46. printf '%s;' "$(cat "toys/$toy/$item.exit")"
  47. awk -f log_parser.awk "toys/$toy/$item.log"
  48. fi
  49. }
  50. item_artifacts() {
  51. toy=$1
  52. item=$2
  53. artifacts=""
  54. for artifactName in "toys/$toy/$item/"*
  55. do
  56. artifactName=$(printf '%s' "$artifactName" | sed "s|toys/$toy/$item/||")
  57. artifacts=$(printf '%s %s' "$artifacts" "$artifactName")
  58. done
  59. printf '%s' "$artifacts" | sed 's/^ //' | sed 's/^\*$//'
  60. }
  61. get_artifact() {
  62. toy=$1
  63. item=$2
  64. artifactName=$3
  65. if [ ! -f "toys/$toy/$item/$artifactName" ]
  66. then
  67. printf 'n;'
  68. else
  69. contentType=$(file -b -i "toys/$toy/$item/$artifactName")
  70. printf '0;%s;%s' "$contentType" "toys/$toy/$item/$artifactName"
  71. fi
  72. }