11.1Slukem#!/bin/sh
21.1Slukem#
31.122Schristos#	$NetBSD: osrelease.sh,v 1.122 2012/02/16 23:56:57 christos Exp $
41.1Slukem#
51.1Slukem# Copyright (c) 1997 The NetBSD Foundation, Inc.
61.1Slukem# All rights reserved.
71.1Slukem#
81.1Slukem# This code is derived from software contributed to The NetBSD Foundation
91.1Slukem# by Luke Mewburn.
101.1Slukem#
111.1Slukem# Redistribution and use in source and binary forms, with or without
121.1Slukem# modification, are permitted provided that the following conditions
131.1Slukem# are met:
141.1Slukem# 1. Redistributions of source code must retain the above copyright
151.1Slukem#    notice, this list of conditions and the following disclaimer.
161.1Slukem# 2. Redistributions in binary form must reproduce the above copyright
171.1Slukem#    notice, this list of conditions and the following disclaimer in the
181.1Slukem#    documentation and/or other materials provided with the distribution.
191.1Slukem#
201.1Slukem# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
211.1Slukem# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
221.1Slukem# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
231.4Sjtc# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
241.4Sjtc# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
251.1Slukem# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
261.1Slukem# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
271.1Slukem# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
281.1Slukem# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
291.1Slukem# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
301.1Slukem# POSSIBILITY OF SUCH DAMAGE.
311.1Slukem#
321.1Slukem
331.107Sjdolecek# We use the number specified in <sys/param.h>
341.111Sriz
351.120Sdslpath="$0"
361.120Sdsl[ "${path#/*}" = "$path" ] && path="./$path"
371.118Sdslexec < ${path%/*}/../sys/param.h
381.111Sriz
391.119Sdsl# Search for line
401.119Sdsl# #define __NetBSD_Version__ <ver_num> /* NetBSD <ver_text> */
411.119Sdsl#
421.119Sdsl# <ver_num> and <ver_text> should match!
431.119Sdsl
441.118Sdslwhile
451.119Sdsl	read define ver_tag rel_num comment_start NetBSD rel_text rest || exit 1
461.118Sdsldo
471.118Sdsl	[ "$define" = "#define" ] || continue;
481.118Sdsl	[ "$ver_tag" = "__NetBSD_Version__" ] || continue
491.118Sdsl	break
501.118Sdsldone
511.118Sdsl
521.118Sdsl# default: return MM.mm.pp
531.118Sdsl# -m: return MM, representing only the major number; however, for -current,
541.117Sapb#     return the next major number (e.g. for 5.99.nn, return 6)
551.118Sdsl# -n: return MM.mm
561.118Sdsl# -s: return MMmmpp (no dots)
571.122Schristos# -k: return MM.mm on release branch, MM.mm.pp on current.
581.118Sdsl
591.119Sdsloption="$1"
601.118Sdsl
611.119Sdsl# ${rel_num} is [M]Mmm00pp00
621.119Sdslrel_num=${rel_num%??}
631.119Sdslrel_MMmm=${rel_num%????}
641.118Sdslrel_MM=${rel_MMmm%??}
651.118Sdslrel_mm=${rel_MMmm#${rel_MM}}
661.119Sdsl# rel_pp=${rel_num#${rel_MMmm}00}
671.119Sdsl
681.119Sdsl# Get patch from text version
691.119SdslIFS=.
701.119Sdslset -- - $rel_text
711.121Schristosbeta=${3#[0-9]}
721.121Schristosbeta=${beta#[0-9]}
731.119Sdslshift 3
741.119SdslIFS=' '
751.121Schristosset -- $rel_MM ${rel_mm#0}$beta $*
761.113Sperry
771.119Sdslcase "$option" in
781.122Schristos-k)
791.122Schristos	if [ ${rel_mm#0} = 99 ]
801.122Schristos	then
811.122Schristos		IFS=.
821.122Schristos		echo "$*"
831.122Schristos	else
841.122Schristos		echo "${rel_MM}.${rel_mm#0}"
851.122Schristos	fi
861.122Schristos	;;
871.122Schristos	     
881.113Sperry-m)
891.118Sdsl	echo "$(((${rel_MMmm}+1)/100))"
901.113Sperry	;;
911.116Sjoerg-n)
921.119Sdsl	echo "${rel_MM}.${rel_mm#0}"
931.116Sjoerg	;;
941.111Sriz-s)
951.119Sdsl	IFS=
961.119Sdsl	echo "$*"
971.111Sriz	;;
981.111Sriz*)
991.119Sdsl	IFS=.
1001.119Sdsl	echo "$*"
1011.111Sriz	;;
1021.111Srizesac
103