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

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

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

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