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