[BACK]Return to install.sxxu CVS log [TXT][DIR] Up to [local] / openbsd / sxxu

Annotation of openbsd/sxxu/install.sxxu, Revision 1.13

1.6       andrew      1: #!/bin/ksh -
1.13    ! andrew      2: # $Id: install.sxxu,v 1.12 2010/04/22 21:24:29 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() {
                     28:     # nothing to do
                     29: }
                     30:
                     31: do_post() {
                     32:     # nothing to do
                     33: }
                     34:
                     35: process_roles() {
                     36:     local _oldpwd="${PWD}"
                     37:
                     38:     cd "${BASEDIR}"
                     39:     if [ ! -e roles ]; then
                     40:         echo 'No roles defined.'
                     41:         exit
                     42:     fi
                     43:
                     44:     local _roles
                     45:     set -A _roles
                     46:     local _role
                     47:     while read _role; do
1.9       andrew     48:        if [ -n "${_role}" ]; then
                     49:                _roles[${#_roles[@]}]="$_role"
                     50:        fi
1.6       andrew     51:     done < roles
                     52:
                     53:     for _role in "${_roles[@]}"; do
                     54:         apply_role "$_role"
                     55:     done
1.4       andrew     56:
1.6       andrew     57:     cd "${_oldpwd}"
                     58: }
1.4       andrew     59:
1.6       andrew     60:
                     61: append_pkg_path() {
                     62:     [ ! -e pkg_path ] && return
                     63:
                     64:     echo ' ==> Setting PKG_PATH'
1.4       andrew     65:     local _line
                     66:     while read _line; do
1.6       andrew     67:         if [ -z "${PKG_PATH}" ]; then
                     68:             PKG_PATH="$_line"
                     69:         else
                     70:             PKG_PATH="${PKG_PATH}:${_line}"
                     71:         fi
                     72:     done < pkg_path
1.9       andrew     73:     PKG_PATH=`eval echo $PKG_PATH`
1.6       andrew     74: }
                     75:
                     76: run_command_lists() {
                     77:     local _f
                     78:     for _f in *_list; do
                     79:         [ ! -f "${_f}" ] && continue
                     80:
                     81:         local _cmd=`basename "${_f%_list}"`
                     82:         local _args=`eval echo \\${${_cmd}_args}`
                     83:
                     84:         echo " ==> Running $_cmd $_args"
                     85:         local _line
                     86:         while read _line; do
                     87:             echo "  => ${_line}"
                     88:             eval ${_cmd} ${_args} ${_line}
                     89:         done < ${_f}
                     90:     done
                     91: }
                     92:
                     93: apply_patches() {
                     94:     [ ! -d patches ] && return
                     95:
                     96:     echo ' ==> Applying patches'
                     97:     local _p
1.9       andrew     98:     for _p in patches/*; do
1.11      andrew     99:         [ X"patches/*" == X"${_p}" ] && continue
1.6       andrew    100:         echo "  => $_p"
                    101:         # -N Always assume a forward patch.
                    102:         # -t Never prompt; assume the user is expert
                    103:         # -p0 full path, always
1.9       andrew    104:         patch -N -t -p0 -d / < $_p
1.6       andrew    105:     done
                    106: }
                    107:
                    108: install_packages() {
                    109:     [ ! -d packages ] && return
                    110:
                    111:     echo ' ==> Installing packages'
                    112:     find packages -name '*.tgz' -print0 | xargs -0 pkg_add ${pkg_add_args}
                    113: }
                    114:
                    115: apply_role() {
                    116:     local _role="$1"
                    117:
1.10      andrew    118:     local _oldpwd="${PWD}"
                    119:     local _rolepwd="${BASEDIR}/${_role}"
                    120:
                    121:     if [ ! -d "${_rolepwd}" ]; then
1.6       andrew    122:         echo "===> Missing ${_role}"
                    123:         return
                    124:     fi
                    125:
                    126:     echo "===> Applying ${_role}"
                    127:
1.10      andrew    128:     cd "${_rolepwd}"
                    129:     if [ -e ./siteXXrc ]; then
1.6       andrew    130:         echo ' ==> Including siteXXrc'
1.10      andrew    131:         . ./siteXXrc
1.6       andrew    132:     fi
                    133:
1.8       andrew    134:     cd "${_rolepwd}" && append_pkg_path
                    135:     cd "${_rolepwd}" && run_command_lists
                    136:     cd "${_rolepwd}" && apply_patches
                    137:     cd "${_rolepwd}" && install_packages
1.6       andrew    138:
1.10      andrew    139:     cd "${_rolepwd}"
                    140:     if [ -e ./install.site ]; then
                    141:         if [ -x ./install.site ]; then
1.6       andrew    142:             echo ' ==> Running install.site'
                    143:             ./install.site
                    144:         else
                    145:             echo ' ==> Including install.site'
1.10      andrew    146:             . ./install.site
1.6       andrew    147:         fi
                    148:     fi
                    149:
                    150:     cd "${_oldpwd}"
                    151: }
                    152:
                    153:
                    154: if [ ! -d "${BASEDIR}" ]; then
                    155:     echo Nothing to do.
                    156:     exit
                    157: fi
                    158:
1.12      andrew    159: do_pre        2>&1 | /usr/bin/tee    /var/log/install.log
1.13    ! andrew    160: process_roles 2>&1 | /usr/bin/tee -a /var/log/install.log | grep '^...>'
        !           161: do_post       2>&1 | /usr/bin/tee -a /var/log/install.log | grep '^...>'
        !           162: echo See /var/log/install.log for install messages.

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>