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

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

1.6       andrew      1: #!/bin/ksh -
1.9       andrew      2: # $Id: install.sxxu,v 1.8 2010/04/20 23:21:59 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.6       andrew     99:         echo "  => $_p"
                    100:         # -N Always assume a forward patch.
                    101:         # -t Never prompt; assume the user is expert
                    102:         # -p0 full path, always
1.9       andrew    103:         patch -N -t -p0 -d / < $_p
1.6       andrew    104:     done
                    105: }
                    106:
                    107: install_packages() {
                    108:     [ ! -d packages ] && return
                    109:
                    110:     echo ' ==> Installing packages'
                    111:     find packages -name '*.tgz' -print0 | xargs -0 pkg_add ${pkg_add_args}
                    112: }
                    113:
                    114: apply_role() {
                    115:     local _role="$1"
                    116:
1.10    ! andrew    117:     local _oldpwd="${PWD}"
        !           118:     local _rolepwd="${BASEDIR}/${_role}"
        !           119:
        !           120:     if [ ! -d "${_rolepwd}" ]; then
1.6       andrew    121:         echo "===> Missing ${_role}"
                    122:         return
                    123:     fi
                    124:
                    125:     echo "===> Applying ${_role}"
                    126:
1.10    ! andrew    127:     cd "${_rolepwd}"
        !           128:     if [ -e ./siteXXrc ]; then
1.6       andrew    129:         echo ' ==> Including siteXXrc'
1.10    ! andrew    130:         . ./siteXXrc
1.6       andrew    131:     fi
                    132:
1.8       andrew    133:     cd "${_rolepwd}" && append_pkg_path
                    134:     cd "${_rolepwd}" && run_command_lists
                    135:     cd "${_rolepwd}" && apply_patches
                    136:     cd "${_rolepwd}" && install_packages
1.6       andrew    137:
1.10    ! andrew    138:     cd "${_rolepwd}"
        !           139:     if [ -e ./install.site ]; then
        !           140:         if [ -x ./install.site ]; then
1.6       andrew    141:             echo ' ==> Running install.site'
                    142:             ./install.site
                    143:         else
                    144:             echo ' ==> Including install.site'
1.10    ! andrew    145:             . ./install.site
1.6       andrew    146:         fi
                    147:     fi
                    148:
                    149:     cd "${_oldpwd}"
                    150: }
                    151:
                    152:
                    153: if [ ! -d "${BASEDIR}" ]; then
                    154:     echo Nothing to do.
                    155:     exit
                    156: fi
                    157:
                    158: do_pre
                    159: process_roles
                    160: do_post

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