126497Sache#! /bin/bash -
226497Sache#
326497Sache# mkdist - make a distribution directory from a master manifest file
426497Sache#
526497Sache# usage: mkdist [-m manifest] [-s srcdir] [-r rootname] [-v] version
626497Sache#
726497Sache# SRCDIR defaults to src
826497Sache# MANIFEST defaults to $SRCDIR/MANIFEST
926497Sache#
10119610Sache# Chet Ramey
11119610Sache# chet@po.cwru.edu
1226497Sache
13119610Sache# Copyright (C) 1996-2002 Free Software Foundation, Inc.
14119610Sache#
15119610Sache# This program is free software; you can redistribute it and/or modify
16119610Sache# it under the terms of the GNU General Public License as published by
17119610Sache# the Free Software Foundation; either version 2, or (at your option)
18119610Sache# any later version.
19119610Sache#
20119610Sache# This program is distributed in the hope that it will be useful,
21119610Sache# but WITHOUT ANY WARRANTY; without even the implied warranty of
22119610Sache# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23119610Sache# GNU General Public License for more details.
24119610Sache#
25119610Sache# You should have received a copy of the GNU General Public License
26119610Sache# along with this program; if not, write to the Free Software
27119610Sache# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
28119610Sache
2926497SacheSRCDIR=src
3026497SacheROOTNAME=bash
3126497Sache
3226497Sacheusage()
3326497Sache{
3426497Sache	echo usage: mkdist [-m manifest] [-s srcdir] [-r rootname] [-v] version 1>&2
3526497Sache	exit 2
3626497Sache}
3726497Sache
3826497Sachevmsg()
3926497Sache{
4026497Sache	if [ -n "$verbose" ]; then
4126497Sache		echo mkdist: "$@"
4226497Sache	fi
4326497Sache}
4426497Sache
4526497Sachewhile getopts m:s:r:v name
4626497Sachedo
4726497Sache	case $name in
4826497Sache	m)	MANIFEST=$OPTARG ;;
4926497Sache	s)	SRCDIR=$OPTARG ;;
5026497Sache	r)	ROOTNAME=$OPTARG ;;
5126497Sache	v)	verbose=yes ;;
5226497Sache	?)	usage ;;
5326497Sache	esac
5426497Sachedone
5526497Sache
5626497Sache: ${MANIFEST:=$SRCDIR/MANIFEST}
5726497Sache
5826497Sachevmsg using $MANIFEST
5926497Sache
6026497Sacheshift $(( $OPTIND - 1 ))
6126497Sache
6226497Sacheif [ $# -lt 1 ]; then
6326497Sache	usage
6426497Sachefi
6526497Sache
6626497Sacheversion=$1
6726497Sachenewdir=${ROOTNAME}-$version
6826497Sache
6947558Sachevmsg creating distribution for $ROOTNAME version $version in $newdir
7026497Sache
7126497Sacheif [ ! -d $newdir ]; then
7226497Sache	mkdir $newdir || { echo $0: cannot make directory $newdir 1>&2 ; exit 1; }
7326497Sachefi
7426497Sache
7526497Sachedirmode=755
7626497Sachefilmode=644
7726497Sache
7826497Sachewhile read fname type mode
7926497Sachedo
8026497Sache	[ -z "$fname" ] && continue
8126497Sache
8226497Sache	case "$fname" in
8326497Sache	\#*)	continue ;;
8426497Sache	esac
8526497Sache
8626497Sache	case "$type" in
8726497Sache	d)	mkdir $newdir/$fname ;;
8826497Sache	f)	cp -p $SRCDIR/$fname $newdir/$fname ;;
89119610Sache	s)	ln -s $mode $newdir/$fname ; mode= ;;		# symlink
90119610Sache	l)	ln $mode $newdir/$fname ; mode= ;;		# hard link
9126497Sache	*)	echo "unknown file type $type" 1>&2 ;;
9226497Sache	esac
9326497Sache
9426497Sache	if [ -n "$mode" ]; then
9526497Sache		chmod $mode $newdir/$fname
9626497Sache	fi
9726497Sache
9826497Sachedone < $MANIFEST
9926497Sache
10026497Sache# cut off the `-alpha' in something like `2.0-alpha', leaving just the
10126497Sache# numeric version
10226497Sache#version=${version%%-*}
10326497Sache
10426497Sache#case "$version" in
10526497Sache#*.*.*)	vers=${version%.*} ;;
10626497Sache#*.*)	vers=${version} ;;
10726497Sache#esac
10826497Sache
10926497Sache#echo $vers > $newdir/.distribution
11026497Sache
11126497Sache#case "$version" in
11226497Sache#*.*.*)	plevel=${version##*.} ;;
11326497Sache#*)	plevel=0 ;;
11426497Sache#esac
11526497Sache#[ -z "$plevel" ] && plevel=0
11626497Sache#echo ${plevel} > $newdir/.patchlevel
11726497Sache
11826497Sachevmsg $newdir created
11926497Sache
12026497Sacheexit 0
121