Browse Source

Allow to pass multiple arguments to pkg.sh script

 + For instance, ./pkg.sh HEAD master dev creates archives for current
 HEAD, master and dev. Interesting to use like this:

git tag --contains=initial | xargs ./pkg.sh

and create a tarball for each tagged commit.
Leo 2 years ago
parent
commit
1fc43c517a
1 changed files with 32 additions and 25 deletions
  1. 32 25
      pkg.sh

+ 32 - 25
pkg.sh

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