pack_binaries.sh 867 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. hash_method=sha384
  3. mkdir -p .packed
  4. file=$1
  5. shift
  6. dir=.packed
  7. packfile=$dir/${file}.tar.gz
  8. hash="$(echo $(for f in $@; do echo $f; done | sort))"
  9. src=$(for f in $@; do
  10. prev_f=
  11. while [ "$f" != "$prev_f" ]; do
  12. for ext in c cpp S; do
  13. [ ! -f ${f}.${ext} ] || echo ${f}.${ext}
  14. done
  15. prev_f=$f
  16. f=${f%.*}
  17. done
  18. done | sort)
  19. git rev-parse --show-toplevel 1>/dev/null 2>/dev/null || not_in_git=1
  20. hashfile=$dir/${file}.${hash_method}
  21. [ "$src" == "" ] || hash="$hash $(cat ${src} | ${hash_method}sum | awk '{ print $1 }')"
  22. if [ -f $hashfile ] && [ "$FORCE_PACK" != "1" ]; then
  23. if [ "$(cat $hashfile)" = "$hash" ]; then
  24. echo "Packed files are up-to-date, no need to repack the file."
  25. exit 0
  26. fi
  27. fi
  28. echo -n $hash > $hashfile
  29. [ "$not_in_git" = "1" ] || git add $hashfile
  30. tar -chzvvf $packfile $@
  31. [ "$not_in_git" = "1" ] || git add $packfile