#!/usr/bin/env ksh # $Id: mpull,v 1.10 2012/03/12 16:59:35 ksb Exp $ # Pull master source directories to this host and build. (ksb) # mpull msrc-path [mmsrc-opts] utility PROGNAME=`basename $0 .ksh` # Fill in missing environment from auto.cf, or the command line, or guess. typeset Pkg Mpull_CNF Mpull_ZNF Mpull_XNF typeset Mpull_MODULE Mpull_HOST Mpull_PORT Mpull_Trace=false typeset Mpull_RSYNC Mpull_RSOPTS Mpull_Version Mpull_Temp # Look through the options to mmsrc, see if we can figure out where # to find the local configuration, read -DHOST=target and -C options # at least. Mpull_Temp=mpullXXXXXX Mpull_CNF= Mpull_XNF= Mpull_ZNF= Mpull_HOST=localhost Mpull_RSOPTS=$MPULL_RSOPTS Mpull_RSYNC=${MPULL_RSYNC:-rsync} Mpull_Version=false case ${1:-h} in -V) echo "$PROGNAME: "'$Id: mpull,v 1.10 2012/03/12 16:59:35 ksb Exp $' echo "$PROGNAME: safe directory template: $Mpull_Temp" Mpull_Version=true ;; -h) echo "$PROGNAME: [rsync-opts] msrc-dir [mmsrc-opts] [utility]" echo "$PROGNAME: -V" echo "$PROGNAME: -h" echo "rsync-opts forced options to rsync" echo "msrc-dir path from the master source root to reach target" mmsrc -h | egrep -v '^(mmsrc:|macro[ ]|b[ ])' echo "$PROGNAME: also any database option to hxmd" exit 0 ;; -*) while expr _"$1" : _"-.*" >/dev/null ; do Mpull_RSOPTS="$Mpull_RSOPTS $1" shift done ;; *) ;; esac Pkg=$1 shift # See if we can find something better than "auto.cf" OPTIND=1 while getopts :hlsVzB:C:D:d:E:f:G:I:j:k:m:M:o:U:u:X:y:Y:Z: opt ; do case "$opt" in \?) if [ _P = _$OPTARG ] ; then echo "$PROGNAME: -P: please remove from option specification" 1>&2 else echo "$PROGNAME: -$OPTARG: unknown option" 1>&2 fi exit 64 ;; # USAGE :) echo "$PROGNAME: -$OPTARG: missing specification" 1>&2 exit 64 ;; # USAGE C|X|Z) eval Mpull_${opt}NF=\$Mpull_${opt}NF:\$OPTARG ;; D) case $OPTARG in HOST=*) Mpull_HOST=${OPTARG#HOST=} ;; esac ;; d) if expr _$OPTARG : '.*X.*' >/dev/null ; then Mpull_Trace=true fi ;; # The rest of the options are beyond our understanding -- ksb esac done Mpull_CNF=${Mpull_CNF#:} Mpull_XNF=${Mpull_XNF#:} Mpull_ZNF=${Mpull_ZNF#:} # Using efmd would be easier, but we might not have it installed. --ksb # The exit below for unknown host or config file is (NOUSER) : ${MPULL_CONFIG:=-C${Mpull_CNF:-auto.cf}${Mpull_XNF:+" -X$Mpull_XNF"}${Mpull_ZNF:+" -Z$Mpull_ZNF"}} : ${MPULL_HOST:=$Mpull_HOST} if [ -z "$MPULL_FROM" ] ; then MPULL_FROM=`hxmd $MPULL_CONFIG -EHOST=$MPULL_HOST 'echo ifdef(\`MPULL_FROM'\'',\`\`MPULL_FROM'\'\'',\`\`msrc::msrc'\'\'')'` || exit 67 # NOUSER, missing config fi if [ -z "$MPULL_SRC" ] ; then MPULL_SRC=`hxmd $MPULL_CONFIG -EHOST=$MPULL_HOST 'echo ifdef(\`MPULL_LOCALROOT'\'',\`\`MPULL_LOCALROOT'\'\'',\`\`/usr/src'\'\'')'` || exit 67 # NOUSER, missing config fi if [ -z "$MPULL_FROM" -o -z "$MPULL_SRC" ] ; then echo "$PROGNAME: $MPULL_HOST: not defined in $MPULL_CONFIG" exit 68 # NOHOST, host not in config fi if $Mpull_Version ; then echo "$PROGNAME: default MPULL_CONFIG: $MPULL_CONFIG" echo "$PROGNAME: default MPULL_HOST: $MPULL_HOST" if [ -d "$MPULL_SRC" ] ; then echo "$PROGNAME: default MPULL_SRC: $MPULL_SRC" else echo "$PROGNAME: default MPULL_SRC: $MPULL_SRC [No such file or directory]" fi echo "$PROGNAME: default MPULL_FROM: $MPULL_FROM" exit 0 fi # Recursive calls get our same environment, this is hardly ever a problem, # but when you need to remove them, just unset them in a recipe or script. export MPULL_CONFIG MPULL_HOST MPULL_FROM MPULL_SRC # Check our environment if [ ! -d "$MPULL_SRC" ] ; then echo "$PROGNAME: $MPULL_HOST: $MPULL_SRC: no such directory" exit 73 # CANTCREAT, won't create top level fi if ! cd $MPULL_SRC ; then exit 69 # UNAVAILABLE, can't get to that directory fi # Default to rsync server, fall-back to rsync over ssh, which # is local site policy and should be edited as needed -- ksb # (Change the first "::" to a ":" to make parsing easier below.) if expr _"$MPULL_FROM" : _'[^:]*:[^:].*' >/dev/null ; then SEP=":" : ${RSYNC_RSH:=ssh} export RSYNC_RSH else SEP="::" MPULL_FROM=`echo "$MPULL_FROM" |sed -e 's/::/:/1'` fi # Parse host[/port][:module] if expr _"$MPULL_FROM" : '_[^:]*$' >/dev/null ; then Mpull_MODULE= Mpull_HOST=$MPULL_FROM else Mpull_MODULE=${MPULL_FROM##*:} Mpull_HOST=${MPULL_FROM%%:*} fi if expr _"$Mpull_HOST" : '_[^/]*$' >/dev/null ; then Mpull_PORT= else Mpull_PORT=${Mpull_HOST##*/} Mpull_HOST=${Mpull_HOST%%/*} fi : ${Mpull_HOST:=msrc} ${Mpull_PORT:=873} ${Mpull_MODULE:=msrc} if [ _:: != _$SEP ] ; then : do not check ssh because that is harder than it looks elif ! $Mpull_RSYNC --no-motd --port=$Mpull_PORT $Mpull_RSOPTS $Mpull_HOST$SEP$Mpull_MODULE >/dev/null ; then echo "$PROGNAME: $Mpull_RSYNC: $Mpull_HOST$SEP$Mpull_MODULE failed to list" 1>&2 exit 66 # NOINPUT, can't connect to rsync service fi RtDIR="" trap 'rm -rf $RtDIR' EXIT ERR HUP RtDIR=`mktemp -d ${TMPDIR:=/tmp}/$Mpull_Temp` || exit 70 # SOFTWARE Ret=0 mkdir -p $RtDIR/$Pkg || exit 78 # CONFIG, tempdir is out of space? mkdir -p $MPULL_SRC/$Pkg || exit 77 # PERM, source cache is not +w? if $Mpull_Trace ; then echo "$Mpull_RSYNC -arSH --port=$Mpull_PORT $Mpull_RSOPTS $Mpull_HOST$SEP$Mpull_MODULE/$Pkg/ $RtDIR/$Pkg" fi $Mpull_RSYNC -arSH --port=$Mpull_PORT $Mpull_RSOPTS $Mpull_HOST$SEP$Mpull_MODULE/$Pkg/ $RtDIR/$Pkg || exit 76 # PROTOCOL, rsync failure cd $RtDIR/$Pkg || exit 77 # NOPERM, can't access dir? if $Mpull_Trace ; then echo "mmsrc -y INTO=$MPULL_SRC/$Pkg ${Mpull_CNF:-"-Cauto.cf"} $@" fi mmsrc -y "INTO=$MPULL_SRC/$Pkg" ${Mpull_CNF:-"-Cauto.cf"} "$@" # trap cleans up for us exit $?