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 # 29 # Easy setup script for populating a user's ~/.hgrc 30 # This currently does the following: 31 # * Load the cadmium extension 32 # * Populate the author/email fields to be correct 33 # * Alias canonical repositories like onnv-gate 34 # * Configures mercurial to use appropriate merge tools 35 # 36 # See hgrc(5) for more information 37 # 38 39 HGRC=$HOME/.hgrc 40 41 usage() { 42 prog=$(basename "$0") 43 echo \ 44 "usage: $prog [-f] [-c cdm_path] [-m merge_path] [-n name] [-e email] [-p proxy] [-s style_path] 45 -f : force overwriting $HGRC 46 -c cdm_path : override Cadmium path 47 -m merge_path : override path to merge tool 48 -n name : override name (for ui.username) 49 -e email : override email (for email.from) 50 -p proxy : enable use of web proxy with specified proxy 51 -s style_path : override path to style file 52 53 if -e isn't provided, and you are on SWAN, an LDAP query is done 54 if -n isn't provided, the entry from /etc/passwd is used 55 56 proxy should be in the form of hostname:port 57 if on-SWAN, $prog will lookup your email address. this can be 58 overridden by using the -e flag. 59 " 60 exit 1 61 } 62 63 while getopts c:e:fm:n:p:s: opt; do 64 case "$opt" in 65 c) cdm_path=$OPTARG;; 66 e) email=$OPTARG;; 67 f) force=1;; 68 m) merge_path=$OPTARG;; 69 n) name=$OPTARG;; 70 p) proxy=$OPTARG;; 71 s) style_path=$OPTARG;; 72 *) usage;; 73 esac 74 done 75 76 if [ -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 80 fi 81 82 AWK="/usr/xpg4/bin/awk" 83 SED="/usr/bin/sed" 84 LDAPCLIENT="/usr/bin/ldapsearch" 85 86 login=$(/usr/bin/id -un) 87 88 # 89 # Try and determine where SUNWonbld is installed. In order of 90 # preference, look in: 91 # 92 # 1. $(whence $0), on the assumption that you want the version 93 # of SUNWonbld 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 # 100 paths="$(dirname $(dirname $(whence $0))) /opt/onbld /ws/onnv-tools/onbld" 101 cdmbin="lib/python/onbld/hgext/cdm.py" 102 stylefile="etc/hgstyle" 103 104 for dir in $paths; do 105 if [[ -f "$dir/$cdmbin" && -z "$cdm_path" ]]; then 106 cdm_path="$dir/$cdmbin" 107 fi 108 109 if [[ -f "$dir/$stylefile" && -z "$style_path" ]]; then 110 style_path="$dir/$stylefile" 111 fi 112 113 if [[ -n "$cdm_path" && -n "$style_path" ]]; then 114 break 115 fi 116 done 117 118 if [[ -n $proxy ]]; then 119 proxyConfig="[http_proxy] 120 host=$proxy 121 " 122 fi 123 124 if getent hosts sunweb.central.sun.com >/dev/null; then 125 # on SWAN 126 echo "Detected SWAN connection" 127 ON_SWAN=1 128 ldapemail='preferredrfc822recipient' 129 ldapquery="uid=$login $ldapemail" 130 ldapcmd="$LDAPCLIENT -1 -h sun-ds -b dc=sun,dc=com $ldapquery" 131 if [[ -z "$email" ]]; then 132 echo "Looking up e-mail address in LDAP" 133 email=${email:=$($ldapcmd | $AWK /^$ldapemail:/'{print $2}')} 134 fi 135 fi 136 137 if [[ -z $email ]]; then 138 my_id=$(id -un) 139 my_checkhostname=$(check-hostname) 140 my_fqhn=${my_checkhostname##* } 141 email="$my_id@$my_fqhn" 142 echo "No e-mail address provided, defaulting to $email" 143 fi 144 145 if [[ -z "$name" ]]; then 146 name=${name:=$(getent passwd $login | awk -F: '{print $5}')} 147 fi 148 username="$name <$email>" 149 150 echo "Configured the following:" 151 if [[ -n $proxy ]]; then 152 echo " proxy: $proxy" 153 fi 154 echo " email: $email" 155 echo " username: $name" 156 echo " style: $style_path" 157 echo " cadmium: $cdm_path" 158 159 if [[ -z "$cdm_path" ]]; then 160 echo "Warning: you will need to edit your .hgrc file\n" \ 161 "to specify a path for cadmium." 162 fi 163 164 if [[ -n $merge_path ]]; then 165 echo " merge: $merge_path" 166 fi 167 168 cat <<EOF >$HGRC 169 $proxyConfig[extensions] 170 hgext.cdm=$cdm_path 171 172 [email] 173 from=$email 174 175 [paths] 176 EOF 177 178 if [[ -n $ON_SWAN ]]; then 179 cat <<EOF >> $HGRC 180 onnv-gate=ssh://onnv.sfbay.sun.com//export/onnv-gate 181 onnv-clone=ssh://onnv.sfbay.sun.com//export/onnv-clone 182 onnv-closed=ssh://onnv.sfbay.sun.com//export/onnv-gate/usr/closed 183 onnv-closed-clone=ssh://onnv.sfbay.sun.com//export/onnv-clone/usr/closed 184 185 EOF 186 else 187 cat <<EOF >> $HGRC 188 onnv-gate=ssh://anon@hg.opensolaris.org//hg/onnv/onnv-gate 189 190 EOF 191 fi 192 193 cat <<EOF >> $HGRC 194 [merge-tools] 195 filemerge.gui=True 196 filemerge.args=-a \$base \$local \$other \$output 197 filemerge.priority=1 198 filemerge.premerge=False 199 200 meld.gui=True 201 meld.priority=0 202 meld.premerge=False 203 204 gpyfm.gui=True 205 gpyfm.priority=0 206 gpyfm.premerge=False 207 208 [ui] 209 username=$username 210 style=$style_path 211 EOF 212 213 if [[ -n $merge_path ]]; then 214 echo "merge=$merge_path" >> $HGRC 215 fi 216 217 echo "Please check $HGRC and verify everything looks correct" 218