#!/bin/sh # $Id: sxxu,v 1.10 2010/04/20 17:25:43 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 INSTALL_SITE=install.siteXX 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 include { local _src="$1" if [ X"${_src}" == X"" ]; then echo "include " 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 include $_role done < "${SRCDIR}/${_src}/siteXX/roles" fi fi } cd ${SRCDIR} for _INSTALL_SITE in \ install.site \ "${SAMPLE_DIR}/install.siteXX" \ "${SAMPLE_DIR}/install.site" do if [ -e "$_INSTALL_SITE" ]; then INSTALL_SITE="$_INSTALL_SITE" break fi done local _cfg for _cfg in .siteXXrc ~/.siteXXrc /etc/siteXX.conf; do [ -e $_cfg ] && . $_cfg && break done 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 machine for machine in "${machines[@]}"; do machine=`basename "$machine"` 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 populating: $_site echo -n ' including:' WRKINST="${WRKDIR}/${_site}" include "${machine}" if [ X"${machine}" != X"${COMMONDIR}" \ -a -d "${SRCDIR}/${COMMONDIR}" ]; then include $COMMONDIR fi if [ -e "${INSTALL_SITE}" ]; then cp ${INSTALL_SITE} "$WRKINST/install.site" fi local _tgz="${RELEASEDIR}/${_site}.tgz" echo -n "\n creating: $_tgz" tar -cz -C "${WRKINST}" -f "$_tgz" . echo ' . . . done' done rm -rf $WRKDIR