#! /usr/bin/ksh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # Copyright 2010, Richard Lowe # # Easy setup script for populating a user's ~/.hgrc # This currently does the following: # * Load the cadmium extension # * Populate the author/email fields to be correct # * Alias canonical repositories like onnv-gate # * Configures mercurial to use appropriate merge tools # # See hgrc(5) for more information # setvar HGRC = "$HOME/.hgrc" proc usage { setvar prog = $(basename "$0") echo \ "usage: $prog [-f] [-c cdm_path] [-m merge_path] [-n name] [-e email] [-p proxy] [-s style_path] -f : force overwriting $HGRC -c cdm_path : override Cadmium path -m merge_path : override path to merge tool -n name : override name (for ui.username) -e email : override email (for email.from) -p proxy : enable use of web proxy with specified proxy -s style_path : override path to style file if -n isn't provided, the entry from /etc/passwd is used proxy should be in the form of hostname:port " exit 1 } while getopts c:e:fm:n:p:s: opt { match $opt { with c setvar cdm_path = "$OPTARG" with e setvar email = "$OPTARG" with f setvar force = '1' with m setvar merge_path = "$OPTARG" with n setvar name = "$OPTARG" with p setvar proxy = "$OPTARG" with s setvar style_path = "$OPTARG" with * usage } } if test -f $HGRC -a $force -eq 0 { echo "Error: You have an existing .hgrc in $HGRC" echo "Please move it aside." exit 1 } setvar AWK = ""/usr/xpg4/bin/awk"" setvar SED = ""/usr/bin/sed"" setvar LDAPCLIENT = ""/usr/bin/ldapsearch"" setvar login = $(/usr/bin/id -un) # # Try and determine where SUNWonbld is installed. In order of # preference, look in: # # 1. $(whence $0), on the assumption that you want the version # of SUNWonbld that best matches the hgsetup script you invoked # # 2. /opt/onbld, because local is generally better # # 3. /ws/onnv-tools/onbld, it's nfs and it might be slow, but it # should resolve from most places on-SWAN # setvar paths = ""$(dirname $(dirname $(whence $0))) /opt/onbld /ws/onnv-tools/onbld"" setvar cdmbin = ""lib/python/onbld/hgext/cdm.py"" setvar stylefile = ""etc/hgstyle"" for dir in [$paths] { if [[ -f "$dir/$cdmbin" && -z "$cdm_path" ]] { setvar cdm_path = ""$dir/$cdmbin"" } if [[ -f "$dir/$stylefile" && -z "$style_path" ]] { setvar style_path = ""$dir/$stylefile"" } if [[ -n "$cdm_path" && -n "$style_path" ]] { break } } if [[ -n $proxy ]] { setvar proxyConfig = ""[http_proxy] host=$proxy "" } if [[ -z $email ]] { setvar my_id = $(id -un) setvar my_hostname = $(hostname) setvar possible_fqhns = $(getent hosts $my_hostname | cut -f 2-) setvar my_fqhn = $(for i in [$possible_fqhns] { match $i { with *.* echo $i; break }; }) setvar email = ""$my_id@$my_fqhn"" echo "No e-mail address provided, defaulting to $email" } if [[ -z "$name" ]] { setvar name = ${name:=$(getent passwd $login | awk -F: '{print $5}')} } setvar username = ""$name <$email>"" echo "Configured the following:" if [[ -n $proxy ]] { echo " proxy: $proxy" } echo " email: $email" echo " username: $name" echo " style: $style_path" echo " cadmium: $cdm_path" if [[ -z "$cdm_path" ]] { echo "Warning: you will need to edit your .hgrc file\n" \ "to specify a path for cadmium." } if [[ -n $merge_path ]] { echo " merge: $merge_path" } cat <<< """ >$HGRC $proxyConfig[extensions] hgext.cdm=$cdm_path [email] from=$email [paths] onnv-gate=ssh://anon@hg.opensolaris.org//hg/onnv/onnv-gate illumos-gate=ssh://anonhg@hg.illumos.org/illumos-gate [merge-tools] filemerge.gui=True filemerge.args=-a '$'base '$'local '$'other '$'output filemerge.priority=1 filemerge.premerge=False meld.gui=True meld.priority=0 meld.premerge=False gpyfm.gui=True gpyfm.priority=0 gpyfm.premerge=False [ui] username=$username style=$style_path """ >$HGRC $proxyConfig[extensions] hgext.cdm=$cdm_path [email] from=$email [paths] onnv-gate=ssh://anon@hg.opensolaris.org//hg/onnv/onnv-gate illumos-gate=ssh://anonhg@hg.illumos.org/illumos-gate [merge-tools] filemerge.gui=True filemerge.args=-a \$base \$local \$other \$output filemerge.priority=1 filemerge.premerge=False meld.gui=True meld.priority=0 meld.premerge=False gpyfm.gui=True gpyfm.priority=0 gpyfm.premerge=False [ui] username=$username style=$style_path EOF if [[ -n $merge_path ]] { echo "merge=$merge_path" >> $HGRC } echo "Please check $HGRC and verify everything looks correct"