component
C1812C124J1GACTU - KEMET
Public Made by Adomby adom
MLCC 0.12 uF +/-5 %, 100 V, C0G/NP0, 1812 (4532 metric)
main
#!/usr/bin/env bash
# usage: push.sh <slug> (pushes /home/adom/project/uta-dynos/work/pages/<slug> to adom/<slug>)
set -u
slug="$1"; dir="/home/adom/project/uta-dynos/work/pages/$slug"
cd "$dir" || exit 1
mapfile -t files < <(find . -type f ! -name page.json -printf '%s %P\n' | sort -k2)
batch=(); size=0; n=0
push() {
local tries=0
while :; do
out=$(adom-wiki repo push "adom/$slug" --files "$@" -m "$MSG" 2>&1); rc=$?
if echo "$out" | grep -q -E '429|RATE_LIMITED'; then
w=$(echo "$out" | grep -oE '"retry_after":[0-9]+' | grep -oE '[0-9]+' | head -1); w=${w:-20}
echo "rate limited, waiting $w s"; sleep "$w"; tries=$((tries+1)); [ $tries -gt 5 ] && return 1; continue
fi
echo "$out" | tail -4; return $rc
done
}
flush() {
[ ${#batch[@]} -eq 0 ] && return 0
n=$((n+1)); MSG="Component record for $slug: files batch $n"
echo "== batch $n: ${#batch[@]} files, $size bytes"
push "${batch[@]}" || { echo "PUSH FAILED"; exit 1; }
batch=(); size=0; sleep 3
}
for line in "${files[@]}"; do
s=${line%% *}; f=${line#* }
if [ $((size + s)) -gt 3300000 ]; then flush; fi
batch+=("$f"); size=$((size + s))
done
flush
MSG="Component record for $slug: page.json (last, keeps hero and title)"
echo "== page.json"
push page.json || { echo "PUSH FAILED"; exit 1; }