#!/bin/sh # $Id: sxxu,v 1.5 2010/04/20 17:25:38 andrew Exp $ # Copyright (c) 2010 Andrew Fresh # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # # based on siteXXtools/generate # Copyright (c) 2006 Alex Holst OSREV=$(uname -r| sed 's/\.//g') SRCDIR=`pwd` COMMONDIR=common WRKDIR=`mktemp -d` RELEASEDIR=/tmp function copy_special { local _src="$1" local _dst="$2" if [ ! -d "$_src" ]; then echo "$_src does not exist!" return fi cd "$_src" find . \( \ -path './siteXX' \ -o -name 'CVS' \ -o -name '.git' \ -o -name '.svn' \ \) -prune -o -print \ | { local _file while read _file ; do if [ -d "$_file" ]; then mkdir -p "${_dst}/${_file}" else cp "$_file" "${_dst}/${_file}" fi done } cd ${OLDPWD} } function populate_from { local _src="$1" if [ X"${_src}" == X"" ]; then echo "populate_from " return fi if [ ! -d "${SRCDIR}/${_src}" ]; then return fi echo -n " $_src" copy_special "${SRCDIR}/${_src}" "${WRKINST}" if [ -d "${SRCDIR}/${_src}/siteXX" ]; then copy_special "${SRCDIR}/${_src}/siteXX" "${WRKINST}/var/siteXX/${_src}" if [ -e "${SRCDIR}/${_src}/siteXX/roles" ]; then local _role while read _role; do populate_from $_role done < "${SRCDIR}/${_src}/siteXX/roles" fi fi } cd ${SRCDIR} set -A machines "$@" if [ ${#machines[@]} -eq 0 ]; then local _i=0 local _d for _d in *; do [ ! -d "$_d" ] && continue [ "${_d#role-}" != "$_d" ] && continue machines[$_i]="${_d}" _i=$((_i+1)) done fi local _i=0 while [ $_i -lt ${#machines[@]} ]; do machine=`basename "${machines[$_i]}"` _i=$(( $_i+1 )) if [ ! -d "${machine}" ]; then echo ${machine} does not exist continue fi local _site=site${OSREV} if [ X"${machine}" != X"${COMMONDIR}" ]; then _site="${_site}-${machine}" fi echo -n populating: WRKINST="${WRKDIR}/${_site}" populate_from "${machine}" if [ X"${machine}" != X"${COMMONDIR}" \ -a -d "${SRCDIR}/${COMMONDIR}" ]; then populate_from $COMMONDIR fi local _tgz="${RELEASEDIR}/${_site}.tgz" echo -n "\n creating $_tgz" tar -cz -C "${WRKINST}" -f "$_tgz" . echo ' . . . done' done rm -rf $WRKDIR