bumpversion revision 1.8
1#!/bin/sh
2# $NetBSD: bumpversion,v 1.8 2000/06/14 06:48:58 cgd Exp $
3#
4# Copyright (c) 1993 Christopher G. Demetriou
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15# 3. All advertising materials mentioning features or use of this software
16#    must display the following acknowledgement:
17#      This product includes software developed by Christopher G. Demetriou.
18# 4. The name of the author may not be used to endorse or promote products
19#    derived from this software without specific prior written permission
20#
21# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32while :
33	do case "$1" in
34		# -c says to create new shlib_version files
35		-c)
36			create=TRUE
37			shift ;;
38
39		# -n sets 'do nothing mode'
40		-n)
41			donothing=TRUE
42			shift ;;
43
44		# -m says to bump major number, rather than minor number
45		-m)
46			bumpmajor=TRUE
47			shift ;;
48
49		*)
50			break ;;
51	esac
52done
53
54if [ $# = 0 ] ; then
55	echo "usage: $0 [-c] [-m] [-n] dir ..."
56	exit 2
57fi
58
59TMP=/tmp/bump$$
60error=0
61
62trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
63
64for dir in $@ ; do
65	versf=$dir/shlib_version
66
67	if [ "X$create" != "X" ] ; then
68		if [ ! -d $dir ] ; then
69		        echo $0: $dir is not a directory 1>&2
70		        error=1
71			continue
72		fi
73		if [ -e $versf ] ; then
74		        echo $0: $versf exists\; not replacing 1>&2
75		        error=1
76			continue
77		fi
78	else
79		if [ ! -e $versf ] ; then
80		        echo $0: $versf does not exist 1>&2
81		        error=1
82			continue
83		fi
84		if [ ! -f $versf ] ; then
85		        echo $0: $versf is not a regular file 1>&2
86		        error=1
87			continue
88		fi
89		if [ ! -r $versf ] ; then
90		        echo $0: $versf is not readable 1>&2
91		        error=1
92			continue
93		fi
94		if [ ! -w $versf ] ; then
95		        echo $0: $versf is not a writable 1>&2
96		        error=1
97			continue
98		fi
99
100		. $versf
101	fi
102
103	if [ "X$create" != "X" ] ; then
104		nmajor=0
105		nminor=0
106	elif [ "X$bumpmajor" != "X" ] ; then
107		nmajor=`expr $major + 1`
108		nminor=0
109	else
110		nmajor=$major
111		nminor=`expr $minor + 1`
112	fi
113
114	if [ "X$donothing" = "X" ] ; then
115		echo major=$nmajor > $TMP
116		echo minor=$nminor >> $TMP
117		mv $TMP $versf
118	else
119		echo "$0: $versf -> $nmajor.$nminor"
120	fi
121done
122
123exit $error
124