pkg.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. # A little script to create tarball, especially for Oasis2Opam
  3. # You may pass source commit as first argument, HEAD is used if omitted.
  4. create_archive() {
  5. # Target commit (TC) i.e. commit from which tarball is created.
  6. TC=$1
  7. TCID=`git rev-parse ${TC}`
  8. echo "Creating tarball from commit ${TCID} ($TC)."
  9. # If no tag, use commit SHA1
  10. id=`git describe --abbrev=10 --candidates=50 ${TCID}`
  11. name=oclaunch_${id}_source # _source emphasis the difference with binary tarballs
  12. echo "Writing in" $name".*"
  13. git archive ${TCID} --prefix=${name}/ --format=zip -o dist/${name}.zip -9
  14. # Creating .xz .gz and .bz2 from tar archive
  15. tar_name=${name}.tar
  16. git archive ${TCID} --prefix=${name}/ --format=tar \
  17. | tee dist/${tar_name} \
  18. | gzip -c9 > dist/${tar_name}.gz
  19. bzip2 -c9 < dist/${tar_name} > dist/${tar_name}.bz2
  20. xz -c9 < dist/${tar_name} > dist/${tar_name}.xz
  21. # Verification
  22. gzip -t < dist/${tar_name}.gz
  23. bzip2 -t < dist/${tar_name}.bz2
  24. xz -t < dist/${tar_name}.xz
  25. }
  26. echo "Start"
  27. # If directory doesn't exist, create it
  28. if ! [ -e dist ]; then
  29. mkdir dist
  30. fi
  31. if [[ $1 = "" ]]; then
  32. echo "No argument, using HEAD to create tarball."
  33. create_archive HEAD
  34. else
  35. # If several commits are given, create an archive for each
  36. for commit in "$@"; do
  37. create_archive $commit
  38. done
  39. fi