Annotation of openbsd/sxxu/install.sxxu, Revision 1.16
1.6 andrew 1: #!/bin/ksh -
1.16 ! andrew 2: # $Id: install.sxxu,v 1.15 2010/04/22 22:50:42 andrew Exp $
1.4 andrew 3:
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 (and some parts taken from) siteXXtools/install.site
19: # Copyright (c) 2006 Alex Holst <a@mongers.org>
20:
1.6 andrew 21: BASEDIR=/var/siteXX
1.9 andrew 22: useradd_args="-m -gid =uid"
1.6 andrew 23: [ -e /var/siteXX/siteXXrc ] && . /var/siteXX/siteXXrc
24:
25: export PKG_PATH
26:
27: do_pre() {
1.14 andrew 28: echo 'Running post install from sxxu'
1.6 andrew 29: }
30:
31: do_post() {
1.14 andrew 32: echo 'See /var/log/install.log for install messages.'
1.6 andrew 33: }
34:
1.16 ! andrew 35: # Strip comments (and leading/trailing whitespace if IFS is set)
! 36: # from a file and spew to stdout
! 37: stripcom() {
! 38: local _file="$1"
! 39: local _line
! 40:
! 41: {
! 42: while read _line ; do
! 43: _line=${_line%%#*} # strip comments
! 44: test -z "$_line" && continue
! 45: echo $_line
! 46: done
! 47: } < $_file
! 48: }
! 49:
! 50:
1.6 andrew 51: process_roles() {
52: local _oldpwd="${PWD}"
53:
54: cd "${BASEDIR}"
55: if [ ! -e roles ]; then
56: echo 'No roles defined.'
57: exit
58: fi
59:
60: local _roles
1.16 ! andrew 61: unset _roles
1.6 andrew 62: set -A _roles
63: local _role
1.16 ! andrew 64: stripcom roles | while read _role; do
1.14 andrew 65: if [ -n "${_role}" ]; then
66: _roles[${#_roles[@]}]="$_role"
67: fi
1.16 ! andrew 68: done
1.6 andrew 69:
70: for _role in "${_roles[@]}"; do
71: apply_role "$_role"
72: done
1.4 andrew 73:
1.6 andrew 74: cd "${_oldpwd}"
75: }
1.4 andrew 76:
1.6 andrew 77:
78: append_pkg_path() {
79: [ ! -e pkg_path ] && return
80:
81: echo ' ==> Setting PKG_PATH'
1.4 andrew 82: local _line
1.16 ! andrew 83: stripcom pkg_path | while read _line; do
1.6 andrew 84: if [ -z "${PKG_PATH}" ]; then
85: PKG_PATH="$_line"
86: else
87: PKG_PATH="${PKG_PATH}:${_line}"
88: fi
1.16 ! andrew 89: done
! 90:
1.9 andrew 91: PKG_PATH=`eval echo $PKG_PATH`
1.6 andrew 92: }
93:
94: run_command_lists() {
95: local _f
96: for _f in *_list; do
97: [ ! -f "${_f}" ] && continue
98:
99: local _cmd=`basename "${_f%_list}"`
100: local _args=`eval echo \\${${_cmd}_args}`
101:
102: echo " ==> Running $_cmd $_args"
103: local _line
1.16 ! andrew 104: stripcom "${_f}" | while read _line; do
1.14 andrew 105: echo " => ${_cmd} ${_args} ${_line}"
1.6 andrew 106: eval ${_cmd} ${_args} ${_line}
1.16 ! andrew 107: done
1.6 andrew 108: done
109: }
110:
111: apply_patches() {
112: [ ! -d patches ] && return
113:
114: echo ' ==> Applying patches'
115: local _p
1.9 andrew 116: for _p in patches/*; do
1.11 andrew 117: [ X"patches/*" == X"${_p}" ] && continue
1.6 andrew 118: echo " => $_p"
119: # -N Always assume a forward patch.
120: # -t Never prompt; assume the user is expert
121: # -p0 full path, always
1.16 ! andrew 122: patch -N -t -p0 -d / < "$_p"
1.6 andrew 123: done
124: }
125:
126: install_packages() {
127: [ ! -d packages ] && return
128:
129: echo ' ==> Installing packages'
130: find packages -name '*.tgz' -print0 | xargs -0 pkg_add ${pkg_add_args}
131: }
132:
133: apply_role() {
134: local _role="$1"
135:
1.10 andrew 136: local _oldpwd="${PWD}"
137: local _rolepwd="${BASEDIR}/${_role}"
138:
139: if [ ! -d "${_rolepwd}" ]; then
1.6 andrew 140: echo "===> Missing ${_role}"
141: return
142: fi
143:
1.15 andrew 144: echo "===> Applying role ${_role}"
1.6 andrew 145:
1.10 andrew 146: cd "${_rolepwd}"
147: if [ -e ./siteXXrc ]; then
1.6 andrew 148: echo ' ==> Including siteXXrc'
1.10 andrew 149: . ./siteXXrc
1.6 andrew 150: fi
151:
1.8 andrew 152: cd "${_rolepwd}" && append_pkg_path
153: cd "${_rolepwd}" && run_command_lists
154: cd "${_rolepwd}" && apply_patches
155: cd "${_rolepwd}" && install_packages
1.6 andrew 156:
1.10 andrew 157: cd "${_rolepwd}"
158: if [ -e ./install.site ]; then
159: if [ -x ./install.site ]; then
1.6 andrew 160: echo ' ==> Running install.site'
161: ./install.site
162: else
163: echo ' ==> Including install.site'
1.10 andrew 164: . ./install.site
1.6 andrew 165: fi
166: fi
167:
168: cd "${_oldpwd}"
169: }
170:
171:
172: if [ ! -d "${BASEDIR}" ]; then
173: echo Nothing to do.
174: exit
175: fi
176:
1.12 andrew 177: do_pre 2>&1 | /usr/bin/tee /var/log/install.log
1.13 andrew 178: process_roles 2>&1 | /usr/bin/tee -a /var/log/install.log | grep '^...>'
1.14 andrew 179: do_post 2>&1 | /usr/bin/tee -a /var/log/install.log
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>