]> git.proxmox.com Git - mirror_qemu.git/blob - scripts/archive-source.sh
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging
[mirror_qemu.git] / scripts / archive-source.sh
1 #!/bin/bash
2 #
3 # Author: Fam Zheng <famz@redhat.com>
4 #
5 # Archive source tree, including submodules. This is created for test code to
6 # export the source files, in order to be built in a different environment,
7 # such as in a docker instance or VM.
8 #
9 # This code is licensed under the GPL version 2 or later. See
10 # the COPYING file in the top-level directory.
11
12 error() {
13 printf %s\\n "$*" >&2
14 exit 1
15 }
16
17 if test $# -lt 1; then
18 error "Usage: $0 <output tarball>"
19 fi
20
21 tar_file="$1"
22 list_file="$1.list"
23 submodules=$(git submodule foreach --recursive --quiet 'echo $name')
24
25 if test $? -ne 0; then
26 error "git submodule command failed"
27 fi
28
29 trap "status=$?; rm -f \"$list_file\"; exit \$status" 0 1 2 3 15
30
31 if test -n "$submodules"; then
32 {
33 git ls-files || error "git ls-files failed"
34 for sm in $submodules; do
35 (cd $sm; git ls-files) | sed "s:^:$sm/:"
36 if test "${PIPESTATUS[*]}" != "0 0"; then
37 error "git ls-files in submodule $sm failed"
38 fi
39 done
40 } | grep -x -v $(for sm in $submodules; do echo "-e $sm"; done) > "$list_file"
41 else
42 git ls-files > "$list_file"
43 fi
44
45 if test $? -ne 0; then
46 error "failed to generate list file"
47 fi
48
49 tar -cf "$tar_file" -T "$list_file" || error "failed to create tar file"
50
51 exit 0