xref: /onnv-gate/usr/src/tools/scripts/hgsetup.sh (revision 8602:c56c22350266)
17078Smjnelson#! /usr/bin/ksh
27078Smjnelson#
37078Smjnelson# CDDL HEADER START
47078Smjnelson#
57078Smjnelson# The contents of this file are subject to the terms of the
67078Smjnelson# Common Development and Distribution License (the "License").
77078Smjnelson# You may not use this file except in compliance with the License.
87078Smjnelson#
97078Smjnelson# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107078Smjnelson# or http://www.opensolaris.org/os/licensing.
117078Smjnelson# See the License for the specific language governing permissions
127078Smjnelson# and limitations under the License.
137078Smjnelson#
147078Smjnelson# When distributing Covered Code, include this CDDL HEADER in each
157078Smjnelson# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167078Smjnelson# If applicable, add the following below this CDDL HEADER, with the
177078Smjnelson# fields enclosed by brackets "[]" replaced with your own identifying
187078Smjnelson# information: Portions Copyright [yyyy] [name of copyright owner]
197078Smjnelson#
207078Smjnelson# CDDL HEADER END
217078Smjnelson#
227078Smjnelson
237078Smjnelson#
24*8602Srichlowe@richlowe.net# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
257078Smjnelson# Use is subject to license terms.
267078Smjnelson#
277078Smjnelson
287078Smjnelson#
297078Smjnelson# Easy setup script for populating a user's ~/.hgrc
307078Smjnelson# This currently does the following:
317078Smjnelson#	* Load the cadmium extension
327078Smjnelson#	* Populate the author/email fields to be correct
337078Smjnelson#	* Alias canonical repositories like onnv-gate
347078Smjnelson#	* Configures mercurial to use appropriate merge tools
357078Smjnelson#
367078Smjnelson# See hgrc(5) for more information
377078Smjnelson#
387078Smjnelson
397078SmjnelsonHGRC=$HOME/.hgrc
407078Smjnelson
417078Smjnelsonusage() {
427078Smjnelson	prog=$(basename "$0")
437078Smjnelson	echo \
447769SMark.J.Nelson@Sun.COM"usage: $prog [-f] [-c cdm_path] [-m merge_path] [-n name] [-e email] [-p proxy] [-s style_path]
457078Smjnelson	-f            : force overwriting $HGRC
467078Smjnelson	-c cdm_path   : override Cadmium path
477078Smjnelson	-m merge_path : override path to merge tool
487078Smjnelson	-n name       : override name (for ui.username)
497078Smjnelson	-e email      : override email (for email.from)
507078Smjnelson	-p proxy      : enable use of web proxy with specified proxy
517769SMark.J.Nelson@Sun.COM	-s style_path : override path to style file
527078Smjnelson
537078Smjnelson	if -e isn't provided, and you are on SWAN, an LDAP query is done
547078Smjnelson	if -n isn't provided, the entry from /etc/passwd is used
557078Smjnelson
567078Smjnelson	proxy should be in the form of hostname:port
577078Smjnelson	if on-SWAN, $prog will lookup your email address.  this can be
587078Smjnelson	overridden by using the -e flag.
597078Smjnelson	"
607078Smjnelson	exit 1
617078Smjnelson}
627078Smjnelson
637769SMark.J.Nelson@Sun.COMwhile getopts c:e:fm:n:p:s: opt; do
647078Smjnelson	case "$opt" in
657078Smjnelson	c) cdm_path=$OPTARG;;
667078Smjnelson	e) email=$OPTARG;;
677078Smjnelson	f) force=1;;
687078Smjnelson	m) merge_path=$OPTARG;;
697078Smjnelson	n) name=$OPTARG;;
707078Smjnelson	p) proxy=$OPTARG;;
717769SMark.J.Nelson@Sun.COM	s) style_path=$OPTARG;;
727078Smjnelson	*) usage;;
737078Smjnelson	esac
747078Smjnelsondone
757078Smjnelson
767078Smjnelsonif [ -f $HGRC -a "$force" -eq 0 ]; then
777078Smjnelson	echo "Error: You have an existing .hgrc in $HGRC"
787078Smjnelson	echo "Please move it aside."
797078Smjnelson	exit 1
807078Smjnelsonfi
817078Smjnelson
827078SmjnelsonAWK="/usr/xpg4/bin/awk"
837078SmjnelsonSED="/usr/bin/sed"
847078SmjnelsonLDAPCLIENT="/usr/bin/ldapsearch"
857078Smjnelson
867078Smjnelsonlogin=$(/usr/bin/id -un)
877078Smjnelson
887078Smjnelson#
897769SMark.J.Nelson@Sun.COM# Try and determine where SUNWonbld is installed.  In order of
907078Smjnelson# preference, look in:
917078Smjnelson#
927078Smjnelson#   1. $(whence $0), on the assumption that you want the version
937769SMark.J.Nelson@Sun.COM#      of SUNWonbld that best matches the hgsetup script you invoked
947078Smjnelson#
957078Smjnelson#   2. /opt/onbld, because local is generally better
967078Smjnelson#
977078Smjnelson#   3. /ws/onnv-tools/onbld, it's nfs and it might be slow, but it
987078Smjnelson#      should resolve from most places on-SWAN
997078Smjnelson#
1007769SMark.J.Nelson@Sun.COMpaths="$(dirname $(dirname $(whence $0))) /opt/onbld /ws/onnv-tools/onbld"
1017078Smjnelsoncdmbin="lib/python/onbld/hgext/cdm.py"
1027769SMark.J.Nelson@Sun.COMstylefile="etc/hgstyle"
1037078Smjnelson
1047078Smjnelsonfor dir in $paths; do
1057078Smjnelson	if [[ -f "$dir/$cdmbin" && -z "$cdm_path" ]]; then
1067078Smjnelson		cdm_path="$dir/$cdmbin"
1077769SMark.J.Nelson@Sun.COM	fi
1087769SMark.J.Nelson@Sun.COM
1097769SMark.J.Nelson@Sun.COM	if [[ -f "$dir/$stylefile" && -z "$style_path" ]]; then
1107769SMark.J.Nelson@Sun.COM		style_path="$dir/$stylefile"
1117769SMark.J.Nelson@Sun.COM	fi
1127769SMark.J.Nelson@Sun.COM
1137769SMark.J.Nelson@Sun.COM	if [[ -n "$cdm_path" && -n "$style_path" ]]; then
1147078Smjnelson		break
1157078Smjnelson	fi
1167078Smjnelsondone
1177078Smjnelson
1187078Smjnelsonif [[ -n $proxy ]]; then
1197078Smjnelson	proxyConfig="[http_proxy]
1207078Smjnelsonhost=$proxy
1217078Smjnelson"
1227078Smjnelsonfi
1237078Smjnelson
1247078Smjnelsonif getent hosts sunweb.central.sun.com >/dev/null; then
1257078Smjnelson	# on SWAN
1267078Smjnelson	echo "Detected SWAN connection"
1277298SMark.J.Nelson@Sun.COM	ON_SWAN=1
1287078Smjnelson	ldapemail='preferredrfc822recipient'
1297078Smjnelson	ldapquery="uid=$login $ldapemail"
1307078Smjnelson	ldapcmd="$LDAPCLIENT -1 -h sun-ds -b dc=sun,dc=com $ldapquery"
1317078Smjnelson	if [[ -z "$email" ]]; then
1327078Smjnelson		echo "Looking up e-mail address in LDAP"
1337078Smjnelson		email=${email:=$($ldapcmd | $AWK /^$ldapemail:/'{print $2}')}
1347078Smjnelson	fi
1357078Smjnelsonfi
1367078Smjnelson
1377078Smjnelsonif [[ -z $email ]]; then
1387078Smjnelson	my_id=$(id -un)
1397078Smjnelson	my_checkhostname=$(check-hostname)
1407078Smjnelson	my_fqhn=${my_checkhostname##* }
1417078Smjnelson	email="$my_id@$my_fqhn"
1427078Smjnelson	echo "No e-mail address provided, defaulting to $email"
1437078Smjnelsonfi
1447078Smjnelson
1457078Smjnelsonif [[ -z "$name" ]]; then
1467078Smjnelson	name=${name:=$(getent passwd $login | awk -F: '{print $5}')}
1477078Smjnelsonfi
1487078Smjnelsonusername="$name <$email>"
1497078Smjnelson
1507078Smjnelsonecho "Configured the following:"
1517078Smjnelsonif [[ -n $proxy ]]; then
1527078Smjnelson	echo "	proxy: $proxy"
1537078Smjnelsonfi
1547078Smjnelsonecho "	email: $email"
1557078Smjnelsonecho "	username: $name"
1567769SMark.J.Nelson@Sun.COMecho "	style: $style_path"
1577078Smjnelsonecho "	cadmium: $cdm_path"
1587078Smjnelson
1597078Smjnelsonif [[ -z "$cdm_path" ]]; then
1607078Smjnelson	echo "Warning: you will need to edit your .hgrc file\n" \
1617078Smjnelson	     "to specify a path for cadmium."
1627078Smjnelsonfi
1637078Smjnelson
1647078Smjnelsonif [[ -n $merge_path ]]; then
1657078Smjnelson	echo "	merge: $merge_path"
1667078Smjnelsonfi
1677078Smjnelson
1687078Smjnelsoncat <<EOF >$HGRC
1697078Smjnelson$proxyConfig[extensions]
1707078Smjnelsonhgext.cdm=$cdm_path
1717078Smjnelson
1727078Smjnelson[email]
1737078Smjnelsonfrom=$email
1747078Smjnelson
1757078Smjnelson[paths]
1767298SMark.J.Nelson@Sun.COMEOF
1777298SMark.J.Nelson@Sun.COM
1787298SMark.J.Nelson@Sun.COMif [[ -n $ON_SWAN ]]; then
1797298SMark.J.Nelson@Sun.COM	cat <<EOF >> $HGRC
1807298SMark.J.Nelson@Sun.COMonnv-gate=ssh://onnv.sfbay.sun.com//export/onnv-gate
1817298SMark.J.Nelson@Sun.COMonnv-clone=ssh://onnv.sfbay.sun.com//export/onnv-clone
1827298SMark.J.Nelson@Sun.COMonnv-closed=ssh://onnv.sfbay.sun.com//export/onnv-gate/usr/closed
1837298SMark.J.Nelson@Sun.COMonnv-closed-clone=ssh://onnv.sfbay.sun.com//export/onnv-clone/usr/closed
1847078Smjnelson
1857298SMark.J.Nelson@Sun.COMEOF
1867298SMark.J.Nelson@Sun.COMelse
1877298SMark.J.Nelson@Sun.COM	cat <<EOF >> $HGRC
1887298SMark.J.Nelson@Sun.COMonnv-gate=ssh://anon@hg.opensolaris.org//hg/onnv/onnv-gate
1897298SMark.J.Nelson@Sun.COM
1907298SMark.J.Nelson@Sun.COMEOF
1917298SMark.J.Nelson@Sun.COMfi
1927298SMark.J.Nelson@Sun.COM
1937298SMark.J.Nelson@Sun.COMcat <<EOF >> $HGRC
1947078Smjnelson[merge-tools]
1957078Smjnelsonfilemerge.gui=True
1967078Smjnelsonfilemerge.args=-a \$base \$local \$other \$output
1977078Smjnelsonfilemerge.priority=1
198*8602Srichlowe@richlowe.netfilemerge.premerge=False
1997078Smjnelson
2007078Smjnelsonmeld.gui=True
2017078Smjnelsonmeld.priority=0
202*8602Srichlowe@richlowe.netmeld.premerge=False
2037078Smjnelson
2047078Smjnelsongpyfm.gui=True
2057078Smjnelsongpyfm.priority=0
206*8602Srichlowe@richlowe.netgpyfm.premerge=False
2077078Smjnelson
2087078Smjnelson[ui]
2097078Smjnelsonusername=$username
2107769SMark.J.Nelson@Sun.COMstyle=$style_path
2117078SmjnelsonEOF
2127078Smjnelson
2137078Smjnelsonif [[ -n $merge_path ]]; then
2147078Smjnelson	echo "merge=$merge_path" >> $HGRC
2157078Smjnelsonfi
2167078Smjnelson
2177078Smjnelsonecho "Please check $HGRC and verify everything looks correct"
218