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