xref: /titanic_50/usr/src/tools/scripts/hgsetup.sh (revision 287247a826fa2ab8d01f6c8f276d405eb08420f8)
1cdf0c1d5Smjnelson#! /usr/bin/ksh
2cdf0c1d5Smjnelson#
3cdf0c1d5Smjnelson# CDDL HEADER START
4cdf0c1d5Smjnelson#
5cdf0c1d5Smjnelson# The contents of this file are subject to the terms of the
6cdf0c1d5Smjnelson# Common Development and Distribution License (the "License").
7cdf0c1d5Smjnelson# You may not use this file except in compliance with the License.
8cdf0c1d5Smjnelson#
9cdf0c1d5Smjnelson# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10cdf0c1d5Smjnelson# or http://www.opensolaris.org/os/licensing.
11cdf0c1d5Smjnelson# See the License for the specific language governing permissions
12cdf0c1d5Smjnelson# and limitations under the License.
13cdf0c1d5Smjnelson#
14cdf0c1d5Smjnelson# When distributing Covered Code, include this CDDL HEADER in each
15cdf0c1d5Smjnelson# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16cdf0c1d5Smjnelson# If applicable, add the following below this CDDL HEADER, with the
17cdf0c1d5Smjnelson# fields enclosed by brackets "[]" replaced with your own identifying
18cdf0c1d5Smjnelson# information: Portions Copyright [yyyy] [name of copyright owner]
19cdf0c1d5Smjnelson#
20cdf0c1d5Smjnelson# CDDL HEADER END
21cdf0c1d5Smjnelson#
22cdf0c1d5Smjnelson
23cdf0c1d5Smjnelson#
2412203c71SRichard Lowe# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25cdf0c1d5Smjnelson# Use is subject to license terms.
26cdf0c1d5Smjnelson#
27cdf0c1d5Smjnelson
282f54b716SRichard Lowe# Copyright 2010, Richard Lowe
292f54b716SRichard Lowe
30cdf0c1d5Smjnelson#
31cdf0c1d5Smjnelson# Easy setup script for populating a user's ~/.hgrc
32cdf0c1d5Smjnelson# This currently does the following:
33cdf0c1d5Smjnelson#	* Load the cadmium extension
34cdf0c1d5Smjnelson#	* Populate the author/email fields to be correct
35cdf0c1d5Smjnelson#	* Alias canonical repositories like onnv-gate
36cdf0c1d5Smjnelson#	* Configures mercurial to use appropriate merge tools
37cdf0c1d5Smjnelson#
38cdf0c1d5Smjnelson# See hgrc(5) for more information
39cdf0c1d5Smjnelson#
40cdf0c1d5Smjnelson
41cdf0c1d5SmjnelsonHGRC=$HOME/.hgrc
42cdf0c1d5Smjnelson
43cdf0c1d5Smjnelsonusage() {
44cdf0c1d5Smjnelson	prog=$(basename "$0")
45cdf0c1d5Smjnelson	echo \
4693af10a4SMark J. Nelson"usage: $prog [-f] [-c cdm_path] [-m merge_path] [-n name] [-e email] [-p proxy] [-s style_path]
47cdf0c1d5Smjnelson	-f            : force overwriting $HGRC
48cdf0c1d5Smjnelson	-c cdm_path   : override Cadmium path
49cdf0c1d5Smjnelson	-m merge_path : override path to merge tool
50cdf0c1d5Smjnelson	-n name       : override name (for ui.username)
51cdf0c1d5Smjnelson	-e email      : override email (for email.from)
52cdf0c1d5Smjnelson	-p proxy      : enable use of web proxy with specified proxy
5393af10a4SMark J. Nelson	-s style_path : override path to style file
54cdf0c1d5Smjnelson
55cdf0c1d5Smjnelson	if -n isn't provided, the entry from /etc/passwd is used
56cdf0c1d5Smjnelson
57cdf0c1d5Smjnelson	proxy should be in the form of hostname:port
58cdf0c1d5Smjnelson	"
59cdf0c1d5Smjnelson	exit 1
60cdf0c1d5Smjnelson}
61cdf0c1d5Smjnelson
6293af10a4SMark J. Nelsonwhile getopts c:e:fm:n:p:s: opt; do
63cdf0c1d5Smjnelson	case "$opt" in
64cdf0c1d5Smjnelson	c) cdm_path=$OPTARG;;
65cdf0c1d5Smjnelson	e) email=$OPTARG;;
66cdf0c1d5Smjnelson	f) force=1;;
67cdf0c1d5Smjnelson	m) merge_path=$OPTARG;;
68cdf0c1d5Smjnelson	n) name=$OPTARG;;
69cdf0c1d5Smjnelson	p) proxy=$OPTARG;;
7093af10a4SMark J. Nelson	s) style_path=$OPTARG;;
71cdf0c1d5Smjnelson	*) usage;;
72cdf0c1d5Smjnelson	esac
73cdf0c1d5Smjnelsondone
74cdf0c1d5Smjnelson
75cdf0c1d5Smjnelsonif [ -f $HGRC -a "$force" -eq 0 ]; then
76cdf0c1d5Smjnelson	echo "Error: You have an existing .hgrc in $HGRC"
77cdf0c1d5Smjnelson	echo "Please move it aside."
78cdf0c1d5Smjnelson	exit 1
79cdf0c1d5Smjnelsonfi
80cdf0c1d5Smjnelson
81cdf0c1d5SmjnelsonAWK="/usr/xpg4/bin/awk"
82cdf0c1d5SmjnelsonSED="/usr/bin/sed"
83cdf0c1d5SmjnelsonLDAPCLIENT="/usr/bin/ldapsearch"
84cdf0c1d5Smjnelson
85cdf0c1d5Smjnelsonlogin=$(/usr/bin/id -un)
86cdf0c1d5Smjnelson
87cdf0c1d5Smjnelson#
8893af10a4SMark J. Nelson# Try and determine where SUNWonbld is installed.  In order of
89cdf0c1d5Smjnelson# preference, look in:
90cdf0c1d5Smjnelson#
91cdf0c1d5Smjnelson#   1. $(whence $0), on the assumption that you want the version
9293af10a4SMark J. Nelson#      of SUNWonbld that best matches the hgsetup script you invoked
93cdf0c1d5Smjnelson#
94cdf0c1d5Smjnelson#   2. /opt/onbld, because local is generally better
95cdf0c1d5Smjnelson#
96cdf0c1d5Smjnelson#   3. /ws/onnv-tools/onbld, it's nfs and it might be slow, but it
97cdf0c1d5Smjnelson#      should resolve from most places on-SWAN
98cdf0c1d5Smjnelson#
9993af10a4SMark J. Nelsonpaths="$(dirname $(dirname $(whence $0))) /opt/onbld /ws/onnv-tools/onbld"
100cdf0c1d5Smjnelsoncdmbin="lib/python/onbld/hgext/cdm.py"
10193af10a4SMark J. Nelsonstylefile="etc/hgstyle"
102cdf0c1d5Smjnelson
103cdf0c1d5Smjnelsonfor dir in $paths; do
104cdf0c1d5Smjnelson	if [[ -f "$dir/$cdmbin" && -z "$cdm_path" ]]; then
105cdf0c1d5Smjnelson		cdm_path="$dir/$cdmbin"
10693af10a4SMark J. Nelson	fi
10793af10a4SMark J. Nelson
10893af10a4SMark J. Nelson	if [[ -f "$dir/$stylefile" && -z "$style_path" ]]; then
10993af10a4SMark J. Nelson		style_path="$dir/$stylefile"
11093af10a4SMark J. Nelson	fi
11193af10a4SMark J. Nelson
11293af10a4SMark J. Nelson	if [[ -n "$cdm_path" && -n "$style_path" ]]; then
113cdf0c1d5Smjnelson		break
114cdf0c1d5Smjnelson	fi
115cdf0c1d5Smjnelsondone
116cdf0c1d5Smjnelson
117cdf0c1d5Smjnelsonif [[ -n $proxy ]]; then
118cdf0c1d5Smjnelson	proxyConfig="[http_proxy]
119cdf0c1d5Smjnelsonhost=$proxy
120cdf0c1d5Smjnelson"
121cdf0c1d5Smjnelsonfi
122cdf0c1d5Smjnelson
123cdf0c1d5Smjnelsonif [[ -z $email ]]; then
124cdf0c1d5Smjnelson	my_id=$(id -un)
125*287247a8SAlexander Pyhalov	my_hostname=$(hostname)
126*287247a8SAlexander Pyhalov	possible_fqhns=$(getent hosts $my_hostname | cut -f 2-)
127*287247a8SAlexander Pyhalov	my_fqhn=`for i in $possible_fqhns; do case $i in *.*) echo $i; break;; esac; done`
128cdf0c1d5Smjnelson	email="$my_id@$my_fqhn"
129cdf0c1d5Smjnelson	echo "No e-mail address provided, defaulting to $email"
130cdf0c1d5Smjnelsonfi
131cdf0c1d5Smjnelson
132cdf0c1d5Smjnelsonif [[ -z "$name" ]]; then
133cdf0c1d5Smjnelson	name=${name:=$(getent passwd $login | awk -F: '{print $5}')}
134cdf0c1d5Smjnelsonfi
135cdf0c1d5Smjnelsonusername="$name <$email>"
136cdf0c1d5Smjnelson
137cdf0c1d5Smjnelsonecho "Configured the following:"
138cdf0c1d5Smjnelsonif [[ -n $proxy ]]; then
139cdf0c1d5Smjnelson	echo "	proxy: $proxy"
140cdf0c1d5Smjnelsonfi
141cdf0c1d5Smjnelsonecho "	email: $email"
142cdf0c1d5Smjnelsonecho "	username: $name"
14393af10a4SMark J. Nelsonecho "	style: $style_path"
144cdf0c1d5Smjnelsonecho "	cadmium: $cdm_path"
145cdf0c1d5Smjnelson
146cdf0c1d5Smjnelsonif [[ -z "$cdm_path" ]]; then
147cdf0c1d5Smjnelson	echo "Warning: you will need to edit your .hgrc file\n" \
148cdf0c1d5Smjnelson	     "to specify a path for cadmium."
149cdf0c1d5Smjnelsonfi
150cdf0c1d5Smjnelson
151cdf0c1d5Smjnelsonif [[ -n $merge_path ]]; then
152cdf0c1d5Smjnelson	echo "	merge: $merge_path"
153cdf0c1d5Smjnelsonfi
154cdf0c1d5Smjnelson
155cdf0c1d5Smjnelsoncat <<EOF >$HGRC
156cdf0c1d5Smjnelson$proxyConfig[extensions]
157cdf0c1d5Smjnelsonhgext.cdm=$cdm_path
158cdf0c1d5Smjnelson
159cdf0c1d5Smjnelson[email]
160cdf0c1d5Smjnelsonfrom=$email
161cdf0c1d5Smjnelson
162cdf0c1d5Smjnelson[paths]
1639a70fc3bSMark J. Nelsononnv-gate=ssh://anon@hg.opensolaris.org//hg/onnv/onnv-gate
1645aad09c6SJoshua M. Clulowillumos-gate=ssh://anonhg@hg.illumos.org/illumos-gate
1659a70fc3bSMark J. Nelson
166cdf0c1d5Smjnelson[merge-tools]
167cdf0c1d5Smjnelsonfilemerge.gui=True
168cdf0c1d5Smjnelsonfilemerge.args=-a \$base \$local \$other \$output
169cdf0c1d5Smjnelsonfilemerge.priority=1
17012203c71SRichard Lowefilemerge.premerge=False
171cdf0c1d5Smjnelson
172cdf0c1d5Smjnelsonmeld.gui=True
173cdf0c1d5Smjnelsonmeld.priority=0
17412203c71SRichard Lowemeld.premerge=False
175cdf0c1d5Smjnelson
176cdf0c1d5Smjnelsongpyfm.gui=True
177cdf0c1d5Smjnelsongpyfm.priority=0
17812203c71SRichard Lowegpyfm.premerge=False
179cdf0c1d5Smjnelson
180cdf0c1d5Smjnelson[ui]
181cdf0c1d5Smjnelsonusername=$username
18293af10a4SMark J. Nelsonstyle=$style_path
183cdf0c1d5SmjnelsonEOF
184cdf0c1d5Smjnelson
185cdf0c1d5Smjnelsonif [[ -n $merge_path ]]; then
186cdf0c1d5Smjnelson	echo "merge=$merge_path" >> $HGRC
187cdf0c1d5Smjnelsonfi
188cdf0c1d5Smjnelson
189cdf0c1d5Smjnelsonecho "Please check $HGRC and verify everything looks correct"
190