#!/bin/bash

set -e

count=$(find .git/lfs/objects -type f | wc -l)
echo "-- total objects count is $count"

index=0
concurrency=5

find .git/lfs/objects -type f | awk -F '/' '{print $NF}' | while read -r obj; do
  echo "-- $(date) -- uploading ($index/$count) $obj"
  git lfs push lfs2 --object-id "$obj" &
  index=$((index+1))
  if [[ $index%$concurrency -eq 0 ]]; then
    echo -e "\r\n-- $(date) -- waiting --------------------------\r\n"
    wait
  fi
done
