get_source.sh revision 1132:d9edec389373
1145184Sglebius#!/bin/sh
2145184Sglebius
3145184Sglebius#
4145184Sglebius# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
5145184Sglebius# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6145184Sglebius#
7145184Sglebius# This code is free software; you can redistribute it and/or modify it
8145184Sglebius# under the terms of the GNU General Public License version 2 only, as
9145184Sglebius# published by the Free Software Foundation.  Oracle designates this
10145184Sglebius# particular file as subject to the "Classpath" exception as provided
11145184Sglebius# by Oracle in the LICENSE file that accompanied this code.
12145184Sglebius#
13145184Sglebius# This code is distributed in the hope that it will be useful, but WITHOUT
14145184Sglebius# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15145184Sglebius# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16145184Sglebius# version 2 for more details (a copy is included in the LICENSE file that
17145184Sglebius# accompanied this code).
18145184Sglebius#
19145184Sglebius# You should have received a copy of the GNU General Public License version
20145184Sglebius# 2 along with this work; if not, write to the Free Software Foundation,
21145184Sglebius# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22145184Sglebius#
23145184Sglebius# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24145184Sglebius# or visit www.oracle.com if you need additional information or have any
25145184Sglebius# questions.
26145184Sglebius#
27145184Sglebius
28145184Sglebiusto_stderr() {
29145184Sglebius    echo "$@" >&2
30145184Sglebius}
31145184Sglebius
32145184Sglebiuserror() {
33145184Sglebius    to_stderr "ERROR: $1"
34145184Sglebius    exit ${2:-126}
35145184Sglebius}
36145184Sglebius
37145184Sglebiuswarning() {
38145184Sglebius    to_stderr "WARNING: $1"
39145184Sglebius}
40145184Sglebius
41145184Sglebiusversion_field() {
42145184Sglebius  # rev is typically omitted for minor and major releases
43145184Sglebius  field=`echo ${1}.0 | cut -f ${2} -d .`
44145184Sglebius  if expr 1 + $field >/dev/null 2> /dev/null; then
45145184Sglebius    echo $field
46145184Sglebius  else
47145184Sglebius    echo -1
48145184Sglebius  fi
49145184Sglebius}
50145184Sglebius
51145184Sglebius# Version check
52145184Sglebius
53145184Sglebius# required
54145184Sglebiusreqdmajor=1
55145184Sglebiusreqdminor=4
56145184Sglebiusreqdrev=0
57145184Sglebius
58145184Sglebius# requested
59145184Sglebiusrqstmajor=2
60145184Sglebiusrqstminor=6
61145184Sglebiusrqstrev=3
62145184Sglebius
63145184Sglebius
64145184Sglebius# installed
65145184Sglebiushgwhere="`command -v hg`"
66145184Sglebiusif [ "x$hgwhere" = "x" ]; then
67145184Sglebius  error "Could not locate Mercurial command"
68fi
69
70hgversion="`LANGUAGE=en hg --version 2> /dev/null | sed -n -e 's@^Mercurial Distributed SCM (version \([^+]*\).*)\$@\1@p'`"
71if [ "x${hgversion}" = "x" ] ; then
72  error "Could not determine Mercurial version of $hgwhere"
73fi
74
75hgmajor="`version_field $hgversion 1`"
76hgminor="`version_field $hgversion 2`"
77hgrev="`version_field $hgversion 3`"
78
79if [ $hgmajor -eq -1 -o $hgminor -eq -1 -o $hgrev -eq -1 ] ; then
80  error "Could not determine Mercurial version of $hgwhere from \"$hgversion\""
81fi
82
83
84# Require
85if [ $hgmajor -lt $reqdmajor -o \( $hgmajor -eq $reqdmajor -a $hgminor -lt $reqdminor \) -o \( $hgmajor -eq $reqdmajor -a $hgminor -eq $reqdminor -a $hgrev -lt $reqdrev \) ] ; then
86  error "Mercurial version $reqdmajor.$reqdminor.$reqdrev or later is required. $hgwhere is version $hgversion"
87fi
88
89
90# Request
91if [ $hgmajor -lt $rqstmajor -o \( $hgmajor -eq $rqstmajor -a $hgminor -lt $rqstminor \) -o \( $hgmajor -eq $rqstmajor -a $hgminor -eq $rqstminor -a $hgrev -lt $rqstrev \) ] ; then
92  warning "Mercurial version $rqstmajor.$rqstminor.$rqstrev or later is recommended. $hgwhere is version $hgversion"
93fi
94
95
96# Get clones of all absent nested repositories (harmless if already exist)
97sh ./common/bin/hgforest.sh clone "$@" || exit $?
98
99# Update all existing repositories to the latest sources
100sh ./common/bin/hgforest.sh pull -u
101