summaryrefslogtreecommitdiff
path: root/colm/colm-pack.sh
blob: ce0ea90297a8720f9b69270f41a087bbf82d0247 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
#

# This wrapper around the colm program (and bootstrap programs) allows us to
# stick to one output per run of the program. It packs up the multiple colm
# output files into one file. We can extract them one at a time afterwards.

CMD=$1;
shift 1

ARGS=""
while getopts "p:o:e:x:RcD:I:L:vdlirS:M:vHh?-:sVa:m:b:E:" opt; do
	# For the unpack case.
	if [ "$opt" = 'o' ]; then
		output=$OPTARG
	fi

	# For the colm wrapper case.
	case "$opt" in
		p)
			# Pack file name
			pack_file=$OPTARG
		;;
		[oexm]) 
			ARGS="$ARGS -$opt $OPTARG.pack"
			PACKS="$PACKS $OPTARG.pack"
		;;
		[DILSMambE-])   ARGS="$ARGS -$opt $OPTARG" ;;
		[RcvdlirvHhsV]) ARGS="$ARGS -$opt" ;;
		?)
			exit 1;
		;;
	esac
done

# Shift over the args.
shift $((OPTIND - 1));

if [ $CMD = "unpack" ]; then
	tar -xmf "$@" $output
	EXIT_STATUS=$?
else
	if [ "`basename $0`" != "$0" ] && [ -x "`dirname $0`/$CMD" ]; then
		COLM="`dirname $0`/$CMD"
	else
		COLM=@prefix@/bin/$CMD
	fi

	$COLM $ARGS "$@"
	EXIT_STATUS=$?
	if [ $EXIT_STATUS = 0 ]; then
		tar --transform 's/.pack$//' -cf "$pack_file" $PACKS
	fi
	rm -f $PACKS
fi

exit $EXIT_STATUS