aboutsummaryrefslogtreecommitdiffstats
path: root/dist.sh
blob: 6e10cae2f6d0a8015fd2f1a845cc6bbcc1d1517f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh

TAR=${2:-"tar"}

if [ $# -lt 1 ] ; then
	echo "Usage: dist.sh <filename> [tar_command]"
	exit 1
fi

FNAME=$1
PREFIX=`basename $FNAME | sed -e 's/\.tar.*$//'`

OUT=""
while true ; do
	_mktemp=`which mktemp`
	if [ F"$_mktemp" != "F" ] ; then
		OUT=`$_mktemp /tmp/files-XXXXXXXX`
		break
	else
		OUT="/tmp/files-`strings -7 /dev/urandom | head -1 | sed -e 's/[^[:alnum:]]//g'`"
	fi
	if [ ! -f "$OUT" ] ; then break ; fi
done

git ls-files > $OUT
SUBMODULES=`git submodule | cut -d ' ' -f 3`

for sub in $SUBMODULES ; do
	(cd $sub && git ls-files | sed -e "s|^|$sub/|" >> $OUT)
done

${TAR} -c --exclude='.[^/]*' --exclude='*.xz' --exclude='*.gz' --no-recursion --transform "s|^|$PREFIX/|" -a -T $OUT -v -f $FNAME
rm -f $OUT