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

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

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

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