newvers.sh revision 326359
1203134Sthompsa#!/bin/sh - 2205042Sthompsa# 3205042Sthompsa# Copyright (c) 1984, 1986, 1990, 1993 4205042Sthompsa# The Regents of the University of California. All rights reserved. 5260219Skevlo# 6203134Sthompsa# Redistribution and use in source and binary forms, with or without 7203134Sthompsa# modification, are permitted provided that the following conditions 8203134Sthompsa# are met: 9203134Sthompsa# 1. Redistributions of source code must retain the above copyright 10203134Sthompsa# notice, this list of conditions and the following disclaimer. 11203134Sthompsa# 2. Redistributions in binary form must reproduce the above copyright 12203134Sthompsa# notice, this list of conditions and the following disclaimer in the 13203134Sthompsa# documentation and/or other materials provided with the distribution. 14203134Sthompsa# 4. Neither the name of the University nor the names of its contributors 15203134Sthompsa# may be used to endorse or promote products derived from this software 16203134Sthompsa# without specific prior written permission. 17203134Sthompsa# 18203134Sthompsa# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19203134Sthompsa# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20203134Sthompsa# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21203134Sthompsa# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22203134Sthompsa# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23203134Sthompsa# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24257955Skevlo# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25203134Sthompsa# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26203134Sthompsa# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27203134Sthompsa# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28203134Sthompsa# SUCH DAMAGE. 29203134Sthompsa# 30203134Sthompsa# @(#)newvers.sh 8.1 (Berkeley) 4/20/94 31203134Sthompsa# $FreeBSD: releng/10.3/sys/conf/newvers.sh 326359 2017-11-29 05:59:50Z delphij $ 32203134Sthompsa 33203134SthompsaTYPE="FreeBSD" 34203134SthompsaREVISION="10.3" 35203134SthompsaBRANCH="RELEASE-p25" 36203134Sthompsaif [ "X${BRANCH_OVERRIDE}" != "X" ]; then 37203134Sthompsa BRANCH=${BRANCH_OVERRIDE} 38203134Sthompsafi 39203134SthompsaRELEASE="${REVISION}-${BRANCH}" 40203134SthompsaVERSION="${TYPE} ${RELEASE}" 41203134Sthompsa 42203134Sthompsaif [ "X${SYSDIR}" = "X" ]; then 43203134Sthompsa SYSDIR=$(dirname $0)/.. 44203134Sthompsafi 45203134Sthompsa 46203134Sthompsaif [ "X${PARAMFILE}" != "X" ]; then 47203134Sthompsa RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \ 48203134Sthompsa ${PARAMFILE}) 49203134Sthompsaelse 50203134Sthompsa RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \ 51257176Sglebius ${SYSDIR}/sys/param.h) 52203134Sthompsafi 53203134Sthompsa 54203134Sthompsab=share/examples/etc/bsd-style-copyright 55203134Sthompsayear=$(sed -Ee '/^Copyright .* The FreeBSD Project/!d;s/^.*1992-([0-9]*) .*$/\1/g' ${SYSDIR}/../COPYRIGHT) 56203134Sthompsa# look for copyright template 57203134Sthompsafor bsd_copyright in ../$b ../../$b ../../../$b /usr/src/$b /usr/$b 58203134Sthompsado 59203134Sthompsa if [ -r "$bsd_copyright" ]; then 60203134Sthompsa COPYRIGHT=`sed \ 61203134Sthompsa -e "s/\[year\]/1992-$year/" \ 62203134Sthompsa -e 's/\[your name here\]\.* /The FreeBSD Project./' \ 63203134Sthompsa -e 's/\[your name\]\.*/The FreeBSD Project./' \ 64203134Sthompsa -e '/\[id for your version control system, if any\]/d' \ 65203134Sthompsa $bsd_copyright` 66203134Sthompsa break 67206358Srpaulo fi 68203134Sthompsadone 69203134Sthompsa 70203134Sthompsa# no copyright found, use a dummy 71203134Sthompsaif [ X"$COPYRIGHT" = X ]; then 72203134Sthompsa COPYRIGHT="/*- 73259546Skevlo * Copyright (c) 1992-$year The FreeBSD Project. 74203134Sthompsa * All rights reserved. 75259812Skevlo * 76203134Sthompsa */" 77220235Skevlofi 78220235Skevlo 79203134Sthompsa# add newline 80207077SthompsaCOPYRIGHT="$COPYRIGHT 81259546Skevlo" 82203134Sthompsa 83203134SthompsaLC_ALL=C; export LC_ALL 84203134Sthompsaif [ ! -r version ] 85203134Sthompsathen 86227309Sed echo 0 > version 87276701Shselaskyfi 88203134Sthompsa 89203134Sthompsatouch version 90203134Sthompsav=`cat version` u=${USER:-root} d=`pwd` h=${HOSTNAME:-`hostname`} 91287552Skevloif [ -n "$SOURCE_DATE_EPOCH" ]; then 92203134Sthompsa if ! t=`date -r $SOURCE_DATE_EPOCH 2>/dev/null`; then 93208019Sthompsa echo "Invalid SOURCE_DATE_EPOCH" >&2 94208019Sthompsa exit 1 95208019Sthompsa fi 96208019Sthompsaelse 97259546Skevlo t=`date` 98208019Sthompsafi 99223486Shselaskyi=`${MAKE:-make} -V KERN_IDENT` 100259546Skevlocompiler_v=$($(${MAKE:-make} -V CC) -v 2>&1 | grep 'version') 101259812Skevlo 102262465Skevlofor dir in /usr/bin /usr/local/bin; do 103262465Skevlo if [ ! -z "${svnversion}" ] ; then 104209918Sthompsa break 105209918Sthompsa fi 106209918Sthompsa if [ -x "${dir}/svnversion" ] && [ -z ${svnversion} ] ; then 107209918Sthompsa # Run svnversion from ${dir} on this script; if return code 108209918Sthompsa # is not zero, the checkout might not be compatible with the 109209918Sthompsa # svnversion being used. 110209918Sthompsa ${dir}/svnversion $(realpath ${0}) >/dev/null 2>&1 111209918Sthompsa if [ $? -eq 0 ]; then 112209918Sthompsa svnversion=${dir}/svnversion 113209918Sthompsa break 114209918Sthompsa fi 115209918Sthompsa fi 116209918Sthompsadone 117209918Sthompsa 118209918Sthompsaif [ -z "${svnversion}" ] && [ -x /usr/bin/svnliteversion ] ; then 119209918Sthompsa /usr/bin/svnliteversion $(realpath ${0}) >/dev/null 2>&1 120209918Sthompsa if [ $? -eq 0 ]; then 121209918Sthompsa svnversion=/usr/bin/svnliteversion 122209918Sthompsa else 123209918Sthompsa svnversion= 124209918Sthompsa fi 125209918Sthompsafi 126209918Sthompsa 127209918Sthompsafor dir in /usr/bin /usr/local/bin; do 128209918Sthompsa if [ -x "${dir}/p4" ] && [ -z ${p4_cmd} ] ; then 129209918Sthompsa p4_cmd=${dir}/p4 130209918Sthompsa fi 131209918Sthompsadone 132209918Sthompsaif [ -d "${SYSDIR}/../.git" ] ; then 133209918Sthompsa for dir in /usr/bin /usr/local/bin; do 134209918Sthompsa if [ -x "${dir}/git" ] ; then 135209918Sthompsa git_cmd="${dir}/git --git-dir=${SYSDIR}/../.git" 136209918Sthompsa break 137209918Sthompsa fi 138209918Sthompsa done 139209918Sthompsafi 140209918Sthompsa 141209918Sthompsaif [ -d "${SYSDIR}/../.hg" ] ; then 142260219Skevlo for dir in /usr/bin /usr/local/bin; do 143239358Shselasky if [ -x "${dir}/hg" ] ; then 144209918Sthompsa hg_cmd="${dir}/hg -R ${SYSDIR}/.." 145209918Sthompsa break 146209918Sthompsa fi 147209918Sthompsa done 148209918Sthompsafi 149209918Sthompsa 150260219Skevloif [ -n "$svnversion" ] ; then 151209918Sthompsa svn=`cd ${SYSDIR} && $svnversion 2>/dev/null` 152209918Sthompsa case "$svn" in 153226534Shselasky [0-9]*) svn=" r${svn}" ;; 154209918Sthompsa *) unset svn ;; 155256500Shselasky esac 156209918Sthompsafi 157209918Sthompsa 158226534Shselaskyif [ -n "$git_cmd" ] ; then 159209918Sthompsa git=`$git_cmd rev-parse --verify --short HEAD 2>/dev/null` 160209918Sthompsa svn=`$git_cmd svn find-rev $git 2>/dev/null` 161209918Sthompsa if [ -n "$svn" ] ; then 162209918Sthompsa svn=" r${svn}" 163209918Sthompsa git="=${git}" 164209918Sthompsa else 165209918Sthompsa svn=`$git_cmd log | fgrep 'git-svn-id:' | head -1 | \ 166209918Sthompsa sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p'` 167209918Sthompsa if [ -z "$svn" ] ; then 168209918Sthompsa svn=`$git_cmd log --format='format:%N' | \ 169209918Sthompsa grep '^svn ' | head -1 | \ 170209918Sthompsa sed -n 's/^.*revision=\([0-9][0-9]*\).*$/\1/p'` 171209918Sthompsa fi 172209918Sthompsa if [ -n "$svn" ] ; then 173209918Sthompsa svn=" r${svn}" 174209918Sthompsa git="+${git}" 175209918Sthompsa else 176209918Sthompsa git=" ${git}" 177209918Sthompsa fi 178209918Sthompsa fi 179209918Sthompsa git_b=`$git_cmd rev-parse --abbrev-ref HEAD` 180255238Sbr if [ -n "$git_b" ] ; then 181257955Skevlo git="${git}(${git_b})" 182259032Skevlo fi 183267089Skevlo if $git_cmd --work-tree=${SYSDIR}/.. diff-index \ 184260219Skevlo --name-only HEAD | read dummy; then 185209918Sthompsa git="${git}-dirty" 186209918Sthompsa fi 187209918Sthompsafi 188209918Sthompsa 189209918Sthompsaif [ -n "$p4_cmd" ] ; then 190209918Sthompsa p4version=`cd ${SYSDIR} && $p4_cmd changes -m1 "./...#have" 2>&1 | \ 191209918Sthompsa awk '{ print $2 }'` 192209918Sthompsa case "$p4version" in 193209918Sthompsa [0-9]*) 194209918Sthompsa p4version=" ${p4version}" 195209918Sthompsa p4opened=`cd ${SYSDIR} && $p4_cmd opened ./... 2>&1` 196209918Sthompsa case "$p4opened" in 197260219Skevlo File*) ;; 198209918Sthompsa //*) p4version="${p4version}+edit" ;; 199209918Sthompsa esac 200209918Sthompsa ;; 201209918Sthompsa *) unset p4version ;; 202209918Sthompsa esac 203209918Sthompsafi 204209918Sthompsa 205209918Sthompsaif [ -n "$hg_cmd" ] ; then 206209918Sthompsa hg=`$hg_cmd id 2>/dev/null` 207209918Sthompsa svn=`$hg_cmd svn info 2>/dev/null | \ 208209918Sthompsa awk -F': ' '/Revision/ { print $2 }'` 209209918Sthompsa if [ -n "$svn" ] ; then 210209918Sthompsa svn=" r${svn}" 211209918Sthompsa fi 212209918Sthompsa if [ -n "$hg" ] ; then 213209918Sthompsa hg=" ${hg}" 214209918Sthompsa fi 215209918Sthompsafi 216209918Sthompsa 217209918Sthompsacat << EOF > vers.c 218209918Sthompsa$COPYRIGHT 219209918Sthompsa#define SCCSSTR "@(#)${VERSION} #${v}${svn}${git}${hg}${p4version}: ${t}" 220209918Sthompsa#define VERSTR "${VERSION} #${v}${svn}${git}${hg}${p4version}: ${t}\\n ${u}@${h}:${d}\\n" 221209918Sthompsa#define RELSTR "${RELEASE}" 222209918Sthompsa 223209918Sthompsachar sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR; 224230333Shselaskychar version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR; 225238274Shrschar compiler_version[] = "${compiler_v}"; 226248458Shselaskychar ostype[] = "${TYPE}"; 227281745Skevlochar osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR; 228209918Sthompsaint osreldate = ${RELDATE}; 229209918Sthompsachar kern_ident[] = "${i}"; 230209918SthompsaEOF 231219257Sdaichi 232209918Sthompsaecho $((v + 1)) > version 233227781Shselasky