#!/bin/sh - # # Copyright (C) 2005-2009 Oliver Fromme, Munich. All rights reserved. # Standard 2-clause BSD license and disclaimer apply, please refer to # the file /usr/share/examples/etc/bsd-style-copyright on FreeBSD # or ask the author for a copy: olli@fromme.com or olli@secnetix.de # # The purpose of this script is to modify the version string of the # FreeBSD kernel by appending a date accoding to the age of your # source tree, making it easier to tell exactly what sources your # kernel was built from, which is especially useful when tracking # changes or hunting bugs. For example: 7.0-STABLE-20080822 or # 8.0-CURRENT-20081128. # # This script is intended to be used instead of "make kernel" in the # /usr/src directory, as part of a FreeBSD update. Please refer to # the /usr/src/UPDATING file for the full procedure. # # Use the -h option to get usage information. # ME="${0##*/}" Usage() { cat <<-tac >&2 Usage: $ME [-t | -y] [-n] [foo=bar ...] Options: -t Use datestamp of today. -y Use datestamp of yesterday. -n Only print the datestamp, then exit. By default (neither -t nor -y is given), the datestamp is deduced from the mtimes of the source files. Because that might give the wrong result, confirmation is requested from the user if stdin and stderr are terminals. tac exit 1 } NV="sys/conf/newvers.sh" if [ -f $NV ]; then echo "Using ./$NV" >&2 else if [ -f /usr/src/$NV ]; then NV="/usr/src/$NV" echo "Using $NV" >&2 else echo "${ME}: Can't find $NV in '.' nor in '/usr/src'!" >&2 exit 1 fi fi EXTRA="" DATE_STAMP="" PRINT_ONLY=false while [ $# -gt 0 ]; do case "$1" in [!-]*=?*) EXTRA="$EXTRA $1"; shift; continue ;; esac case "$1" in -*[!tyn]*|[!-]*) Usage ;; esac case "$1" in -*t*) DATE_STAMP=$(date +%Y%m%d) ;; esac case "$1" in -*y*) DATE_STAMP=$(date -v -1d +%Y%m%d) ;; esac case "$1" in -*n*) PRINT_ONLY=true ;; esac shift done if [ -z "$DATE_STAMP" ]; then DATE_STAMP=$(date -r $(stat -f%m */* | sort -n | tail -1) +%Y%m%d) if [ -z "$DATE_STAMP" ]; then echo "${ME}: Unexpected error generating date stamp!" >&2 exit 1 fi echo "Using date stamp: $DATE_STAMP" >&2 fi eval $(awk '/^[ ]*BRANCH=/ {print; exit}' $NV) if [ -z "$BRANCH" ]; then echo "${ME}: Cannot locate BRANCH in $NV" >&2 exit 1 fi case "$BRANCH" in CURRENT|STABLE|RELEASE|PRERELEASE) ;; ALPHA|ALPHA[1-9]|BETA|BETA[1-9]|GAMMA|GAMMA[1-9]|RC|RC[1-9]) ;; *) echo "${ME}: Unknown BRANCH name \"$BRANCH\"" >&2 if ! $PRINT_ONLY; then while :; do echo -n 'Continue [y/n]? ' >&2 read answer < /dev/tty case "$answer" in [Yy]|[Yy][Ee][Ss]) break ;; [Nn]|[Nn][Oo]) echo "${ME}: Cancelled" >&2 exit 1 ;; esac echo "Please enter 'y' or 'n'!" >&2 done fi ;; esac export BRANCH_OVERRIDE="${BRANCH}-${DATE_STAMP}" echo "BRANCH_OVERRIDE=\"$BRANCH_OVERRIDE\"" >&2 case $(pwd) in /usr/src) set BRANCH_OVERRIDE="$BRANCH_OVERRIDE" $EXTRA kernel ;; */compile/*) set BRANCH_OVERRIDE="$BRANCH_OVERRIDE" $EXTRA ;; *) set BRANCH_OVERRIDE="$BRANCH_OVERRIDE" $EXTRA kernel esac echo "Executing the following command:" echo " make $*" if $PRINT_ONLY; then exit 0 fi if [ -t 0 -a -t 2 ]; then echo -n 'Please enter "y" to confirm: ' >&2 read ANSWER case "$ANSWER" in [Yy]|[Yy][Ee][Ss]) # OK. ;; *) echo "Cancelled." >&2 exit 1 ;; esac fi exec make "$@" #--