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