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 2008 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27# ident "%Z%%M% %I% %E% SMI" 28# 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] 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 54 if -e isn't provided, and you are on SWAN, an LDAP query is done 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 if on-SWAN, $prog will lookup your email address. this can be 59 overridden by using the -e flag. 60 " 61 exit 1 62} 63 64while getopts c:e:fm:n:p: opt; do 65 case "$opt" in 66 c) cdm_path=$OPTARG;; 67 e) email=$OPTARG;; 68 f) force=1;; 69 m) merge_path=$OPTARG;; 70 n) name=$OPTARG;; 71 p) proxy=$OPTARG;; 72 *) usage;; 73 esac 74done 75 76if [ -f $HGRC -a "$force" -eq 0 ]; then 77 echo "Error: You have an existing .hgrc in $HGRC" 78 echo "Please move it aside." 79 exit 1 80fi 81 82AWK="/usr/xpg4/bin/awk" 83SED="/usr/bin/sed" 84LDAPCLIENT="/usr/bin/ldapsearch" 85 86login=$(/usr/bin/id -un) 87 88# 89# Try and determine where Cadmium is installed. In order of 90# preference, look in: 91# 92# 1. $(whence $0), on the assumption that you want the version 93# of cadmium that best matches the hgsetup script you invoked 94# 95# 2. /opt/onbld, because local is generally better 96# 97# 3. /ws/onnv-tools/onbld, it's nfs and it might be slow, but it 98# should resolve from most places on-SWAN 99# 100paths="$(dirname $(whence $0)) /opt/onbld /ws/onnv-tools/onbld" 101cdmbin="lib/python/onbld/hgext/cdm.py" 102 103for dir in $paths; do 104 if [[ -f "$dir/$cdmbin" && -z "$cdm_path" ]]; then 105 cdm_path="$dir/$cdmbin" 106 break 107 fi 108done 109 110if [[ -n $proxy ]]; then 111 proxyConfig="[http_proxy] 112host=$proxy 113" 114fi 115 116if getent hosts sunweb.central.sun.com >/dev/null; then 117 # on SWAN 118 echo "Detected SWAN connection" 119 ldapemail='preferredrfc822recipient' 120 ldapquery="uid=$login $ldapemail" 121 ldapcmd="$LDAPCLIENT -1 -h sun-ds -b dc=sun,dc=com $ldapquery" 122 if [[ -z "$email" ]]; then 123 echo "Looking up e-mail address in LDAP" 124 email=${email:=$($ldapcmd | $AWK /^$ldapemail:/'{print $2}')} 125 fi 126fi 127 128if [[ -z $email ]]; then 129 my_id=$(id -un) 130 my_checkhostname=$(check-hostname) 131 my_fqhn=${my_checkhostname##* } 132 email="$my_id@$my_fqhn" 133 echo "No e-mail address provided, defaulting to $email" 134fi 135 136if [[ -z "$name" ]]; then 137 name=${name:=$(getent passwd $login | awk -F: '{print $5}')} 138fi 139username="$name <$email>" 140 141echo "Configured the following:" 142if [[ -n $proxy ]]; then 143 echo " proxy: $proxy" 144fi 145echo " email: $email" 146echo " username: $name" 147echo " cadmium: $cdm_path" 148 149if [[ -z "$cdm_path" ]]; then 150 echo "Warning: you will need to edit your .hgrc file\n" \ 151 "to specify a path for cadmium." 152fi 153 154if [[ -n $merge_path ]]; then 155 echo " merge: $merge_path" 156fi 157 158cat <<EOF >$HGRC 159$proxyConfig[extensions] 160hgext.cdm=$cdm_path 161 162[email] 163from=$email 164 165[paths] 166onnv-gate=ssh://anon@hg.opensolaris.org/hg/onnv/onnv-gate 167 168[merge-tools] 169filemerge.gui=True 170filemerge.args=-a \$base \$local \$other \$output 171filemerge.priority=1 172 173meld.gui=True 174meld.priority=0 175 176gpyfm.gui=True 177gpyfm.priority=0 178 179[ui] 180username=$username 181EOF 182 183if [[ -n $merge_path ]]; then 184 echo "merge=$merge_path" >> $HGRC 185fi 186 187echo "Please check $HGRC and verify everything looks correct" 188