Annotation of openbsd/sxxu/sxxu, Revision 1.15
1.2 andrew 1: #!/bin/sh
2: # $Id$
3:
1.5 andrew 4: # Copyright (c) 2010 Andrew Fresh <andrew@afresh1.com>
5: #
6: # Permission to use, copy, modify, and distribute this software for any
7: # purpose with or without fee is hereby granted, provided that the above
8: # copyright notice and this permission notice appear in all copies.
9: #
10: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17: #
18: # based on siteXXtools/generate
19: # Copyright (c) 2006 Alex Holst <a@mongers.org>
20:
1.2 andrew 21: OSREV=$(uname -r| sed 's/\.//g')
22: SRCDIR=`pwd`
23: COMMONDIR=common
24: RELEASEDIR=/tmp
1.8 andrew 25: INSTALL_SITE=install.siteXX
1.2 andrew 26:
27: function copy_special {
1.4 andrew 28: local _src="$1"
29: local _dst="$2"
1.2 andrew 30:
1.3 andrew 31: if [ ! -d "$_src" ]; then
1.2 andrew 32: echo "$_src does not exist!"
33: return
34: fi
35:
1.4 andrew 36: cd "$_src"
1.3 andrew 37: find . \( \
38: -path './siteXX' \
39: -o -name 'CVS' \
40: -o -name '.git' \
41: -o -name '.svn' \
42: \) -prune -o -print \
1.2 andrew 43: | {
44: local _file
45: while read _file ; do
1.3 andrew 46: if [ -d "$_file" ]; then
47: mkdir -p "${_dst}/${_file}"
1.2 andrew 48: else
1.3 andrew 49: cp "$_file" "${_dst}/${_file}"
1.2 andrew 50: fi
51: done
52: }
53:
1.10 andrew 54: cd "${OLDPWD}"
1.2 andrew 55: }
56:
1.6 andrew 57: function include {
1.4 andrew 58: local _src="$1"
1.2 andrew 59:
60: if [ X"${_src}" == X"" ]; then
1.6 andrew 61: echo "include <dir>"
1.2 andrew 62: return
63: fi
1.4 andrew 64: if [ ! -d "${SRCDIR}/${_src}" ]; then
1.2 andrew 65: return
66: fi
67:
1.12 andrew 68: local _siteXX_src="${SRCDIR}/${_src}/siteXX"
69: local _siteXX_dst="${WRKINST}/var/siteXX/${_src}"
70: if [ -d "$_siteXX_dst" ]; then
1.15 ! andrew 71: echo -n " !!!${_src}!!!"
1.11 andrew 72: return
73: fi
1.12 andrew 74: mkdir -p "$_siteXX_dst"
1.11 andrew 75:
1.2 andrew 76: echo -n " $_src"
77:
78: copy_special "${SRCDIR}/${_src}" "${WRKINST}"
79:
1.12 andrew 80: if [ -d "$_siteXX_src" ]; then
81: copy_special "$_siteXX_src" "$_siteXX_dst"
1.3 andrew 82:
1.13 andrew 83: if [ -z "$REGEN_MTREE" -a -e "${_siteXX_src}/mtree" ]; then
84: mtree -Uep "${WRKINST}" < "${_siteXX_src}/mtree" > /dev/null
85:
86: local _mtree_out=`mktemp`
87: mtree -ep "${WRKINST}" < "${_siteXX_src}/mtree" > $_mtree_out
88: if [ $? -ne 0 ]; then
89: echo "\nMTREE PROBLEMS FOUND"
90: cat $_mtree_out
91: fi
92: rm -f $_mtree_out
1.12 andrew 93: fi
94:
1.13 andrew 95: [ -z "$NORECURSE" ] || return
1.12 andrew 96:
97: if [ -e "${_siteXX_src}/roles" ]; then
1.3 andrew 98: local _role
99: while read _role; do
1.11 andrew 100: include "$_role"
1.12 andrew 101: done < "${_siteXX_src}/roles"
1.2 andrew 102: fi
103: fi
1.3 andrew 104: }
1.2 andrew 105:
1.3 andrew 106: cd ${SRCDIR}
1.2 andrew 107:
1.8 andrew 108: for _INSTALL_SITE in \
109: install.site \
110: "${SAMPLE_DIR}/install.siteXX" \
111: "${SAMPLE_DIR}/install.site"
112: do
113: if [ -e "$_INSTALL_SITE" ]; then
114: INSTALL_SITE="$_INSTALL_SITE"
115: break
116: fi
117: done
118:
1.7 andrew 119: local _cfg
120: for _cfg in .siteXXrc ~/.siteXXrc /etc/siteXX.conf; do
121: [ -e $_cfg ] && . $_cfg && break
122: done
123:
1.13 andrew 124: while getopts mkw:R arg; do
1.12 andrew 125: case ${arg} in
126: m)
127: REGEN_MTREE=1
128: NORECURSE=1
1.15 ! andrew 129: NOGZIP=1
1.12 andrew 130: ;;
1.13 andrew 131: R)
132: NORECURSE=1
1.15 ! andrew 133: NOGZIP=1
1.13 andrew 134: ;;
1.12 andrew 135: k)
136: NOREMOVE=1
137: ;;
138: w)
139: WRKDIR=${OPTARG}
140: esac
141: done
1.13 andrew 142: shift $(($OPTIND - 1))
143:
144: if [ -z "$WRKDIR" ]; then
145: WRKDIR=`mktemp -d -t sxxu.XXXXXXXXX` || exit 1
146: fi
147:
1.15 ! andrew 148: echo WRKDIR: $WRKDIR
! 149: [ -z "$REGEN_MTREE" ] || echo Regenerate mtree
! 150: echo '#*#*#*#'
! 151:
1.7 andrew 152:
1.13 andrew 153: set -A machines -- "$@"
1.4 andrew 154: if [ ${#machines[@]} -eq 0 ]; then
155: local _i=0
156: local _d
157: for _d in *; do
158: [ ! -d "$_d" ] && continue
1.15 ! andrew 159: [ -z "${NORECURSE}" -a "${_d#role-}" != "$_d" ] && continue
1.4 andrew 160: machines[$_i]="${_d}"
161: _i=$((_i+1))
1.2 andrew 162: done
163: fi
164:
1.10 andrew 165: local machine
166: for machine in "${machines[@]}"; do
1.13 andrew 167: machine=`basename -- "$machine"`
1.4 andrew 168:
169: if [ ! -d "${machine}" ]; then
1.3 andrew 170: echo ${machine} does not exist
171: continue
172: fi
1.4 andrew 173:
1.2 andrew 174: local _site=site${OSREV}
175: if [ X"${machine}" != X"${COMMONDIR}" ]; then
1.4 andrew 176: _site="${_site}-${machine}"
1.2 andrew 177: fi
178:
1.15 ! andrew 179: echo -n populating: $_site
1.2 andrew 180:
1.4 andrew 181: WRKINST="${WRKDIR}/${_site}"
1.2 andrew 182:
1.15 ! andrew 183: if [ -z "${REGEN_MTREE}" -o ! -e "${WRKINST}" ]; then
! 184: echo -n "\n including:"
! 185: include "${machine}"
! 186: fi
1.2 andrew 187:
1.15 ! andrew 188: if [ -z "$NORECURSE" ]; then
1.12 andrew 189: if [ X"${machine}" != X"${COMMONDIR}" \
190: -a -d "${SRCDIR}/${COMMONDIR}" ]; then
191: include $COMMONDIR
192: fi
193:
194: if [ -e "${INSTALL_SITE}" ]; then
195: cp ${INSTALL_SITE} "$WRKINST/install.site"
196: fi
1.15 ! andrew 197: fi
1.8 andrew 198:
1.15 ! andrew 199: if [ ! -z "${REGEN_MTREE}" ]; then
! 200: local _mtree="${SRCDIR}/${machine}/siteXX/mtree"
! 201: echo -n "\nregenerate: ${_mtree#${SRCDIR}/}"
! 202:
! 203: mkdir -p "${SRCDIR}/${machine}/siteXX" \
! 204: "${WRKINST}/var/siteXX/${machine}"
! 205: mtree -cp "${WRKINST}" -k uid,gid,mode > "$_mtree"
! 206: fi
! 207:
! 208: if [ -z "$NOGZIP" ]; then
1.12 andrew 209: local _tgz="${RELEASEDIR}/${_site}.tgz"
210: echo -n "\n creating: $_tgz"
211: tar -cz -C "${WRKINST}" -f "$_tgz" .
1.2 andrew 212: fi
1.15 ! andrew 213:
1.2 andrew 214: echo ' . . . done'
215: done
216:
1.13 andrew 217: if [ -z "$NOREMOVE" ]; then
1.12 andrew 218: rm -rf $WRKDIR
219: fi
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>