Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / atf / dist / admin / generate-revision.sh
blob540d499e79bffe34d70004e064787f7b6df51739
1 #! /bin/sh
3 # Automated Testing Framework (atf)
5 # Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
6 # All rights reserved.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
18 # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 # IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
28 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 # Generates a header file with information about the revision used to
33 # build ATF.
36 set -e
38 Prog_Name=${0##*/}
40 MTN=
41 ROOT=
44 # err message
46 err() {
47 echo "${Prog_Name}: ${@}" 1>&2
48 exit 1
52 # call_mtn args
54 call_mtn() {
55 ${MTN} --root=${ROOT} "${@}"
59 # get_rev_info_into_vars
61 # Sets the following variables to describe the current revision of the tree:
62 # rev_base_id: The base revision identifier.
63 # rev_modified: true if the tree has been locally modified.
65 get_rev_info_into_vars() {
66 rev_base_id=$(call_mtn automate get_base_revision_id)
68 if call_mtn status | grep "no changes" >/dev/null; then
69 rev_modified=false
70 else
71 rev_modified=true
74 datetime=$(call_mtn automate certs ${rev_base_id} | \
75 grep 'value "[2-9][0-9][0-9][0-9]-[01][0-9]-[0-3][0-9]' | \
76 cut -d '"' -f 2)
77 rev_date=$(echo ${datetime} | cut -d T -f 1)
78 rev_time=$(echo ${datetime} | cut -d T -f 2)
82 # generate_h revfile
84 generate_h() {
85 revfile=${1}
87 get_rev_info_into_vars
89 >${revfile}
91 echo "#define PACKAGE_REVISION_BASE \"${rev_base_id}\"" >>${revfile}
93 if [ ${rev_modified} = true ]; then
94 echo "#define PACKAGE_REVISION_MODIFIED 1" >>${revfile}
97 echo "#define PACKAGE_REVISION_DATE \"${rev_date}\"" >>${revfile}
98 echo "#define PACKAGE_REVISION_TIME \"${rev_time}\"" >>${revfile}
102 # main
104 # Entry point.
106 main() {
107 fmt=
108 outfile=
109 version=
110 while getopts :f:m:r:o:v: arg; do
111 case ${arg} in
113 fmt=${OPTARG}
116 MTN=${OPTARG}
119 outfile=${OPTARG}
122 ROOT=${OPTARG}
125 version=${OPTARG}
128 err "Unknown option ${arg}"
130 esac
131 done
132 [ -n "${ROOT}" ] || \
133 err "Must specify the top-level source directory with -r"
134 [ -n "${fmt}" ] || \
135 err "Must specify an output format with -f"
136 [ -n "${outfile}" ] || \
137 err "Must specify an output file with -o"
138 [ -n "${version}" ] || \
139 err "Must specify a version number with -v"
141 if [ -n "${MTN}" -a -d ${ROOT}/_MTN ]; then
142 case ${fmt} in
144 tmp=$(mktemp -t generate-revision.XXXXXX)
145 generate_${fmt} ${tmp} ${version}
146 cmp -s ${tmp} ${outfile} || cp -p ${tmp} ${outfile}
147 rm -f ${tmp}
150 err "Unknown format ${fmt}"
152 esac
153 else
154 rm -f ${outfile}
158 main "${@}"
160 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4