extract_and_commit.sh 1011 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/sh
  2. set -eu
  3. if ! [ -d tarball_archive ]; then
  4. echo "$0: Directory tarball_archive does not exist in the current directory" >&2
  5. exit 1
  6. fi
  7. if [ -d .git ]; then
  8. if git status --porcelain | grep -q .; then
  9. git status >&2
  10. echo "$0: Git working tree unclean, won't continue" >&2
  11. exit 1
  12. fi
  13. else
  14. echo "$0: .git does not exist in the current directory" >&2
  15. exit 1
  16. fi
  17. tmpfile="$(mktemp /tmp/extract_and_commit.XXXXXX)"
  18. for archive in ./tarball_archive/{mon-2.{0,1,2,3,4},symon-2.{5,51,52,53,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88}}.tar.gz; do
  19. if git log --format=oneline | grep -q "$archive"; then
  20. echo "$0: $archive already in git, continuing" >&2
  21. continue
  22. fi
  23. zcat $archive | pax -0 > "$tmpfile"
  24. zcat $archive | pax -r
  25. xargs -0 git add < "$tmpfile"
  26. git commit -m "Add $archive"
  27. tr '\0' '\n' < "$tmpfile" | egrep -o "^[^/.]+/" | sort -u | xargs rm -R
  28. xargs -0 git add < "$tmpfile"
  29. done
  30. rm "$tmpfile"
  31. git reset --hard HEAD