=================================================================== RCS file: /cvs/openbsd/sxxu/Attic/install.sxxu,v retrieving revision 1.7 retrieving revision 1.16 diff -u -r1.7 -r1.16 --- openbsd/sxxu/Attic/install.sxxu 2010/04/20 18:26:00 1.7 +++ openbsd/sxxu/Attic/install.sxxu 2010/04/23 00:01:30 1.16 @@ -1,5 +1,5 @@ #!/bin/ksh - -# $Id: install.sxxu,v 1.7 2010/04/20 17:26:00 andrew Exp $ +# $Id: install.sxxu,v 1.16 2010/04/22 23:01:30 andrew Exp $ # Copyright (c) 2010 Andrew Fresh # @@ -19,19 +19,35 @@ # Copyright (c) 2006 Alex Holst BASEDIR=/var/siteXX -user_add_args="-m -gid =uid" +useradd_args="-m -gid =uid" [ -e /var/siteXX/siteXXrc ] && . /var/siteXX/siteXXrc export PKG_PATH do_pre() { - # nothing to do + echo 'Running post install from sxxu' } do_post() { - # nothing to do + echo 'See /var/log/install.log for install messages.' } +# Strip comments (and leading/trailing whitespace if IFS is set) +# from a file and spew to stdout +stripcom() { + local _file="$1" + local _line + + { + while read _line ; do + _line=${_line%%#*} # strip comments + test -z "$_line" && continue + echo $_line + done + } < $_file +} + + process_roles() { local _oldpwd="${PWD}" @@ -42,11 +58,14 @@ fi local _roles + unset _roles set -A _roles local _role - while read _role; do - _roles[${#_roles[@]}]="$_role" - done < roles + stripcom roles | while read _role; do + if [ -n "${_role}" ]; then + _roles[${#_roles[@]}]="$_role" + fi + done for _role in "${_roles[@]}"; do apply_role "$_role" @@ -61,13 +80,15 @@ echo ' ==> Setting PKG_PATH' local _line - while read _line; do + stripcom pkg_path | while read _line; do if [ -z "${PKG_PATH}" ]; then PKG_PATH="$_line" else PKG_PATH="${PKG_PATH}:${_line}" fi - done < pkg_path + done + + PKG_PATH=`eval echo $PKG_PATH` } run_command_lists() { @@ -80,10 +101,10 @@ echo " ==> Running $_cmd $_args" local _line - while read _line; do - echo " => ${_line}" + stripcom "${_f}" | while read _line; do + echo " => ${_cmd} ${_args} ${_line}" eval ${_cmd} ${_args} ${_line} - done < ${_f} + done done } @@ -92,12 +113,13 @@ echo ' ==> Applying patches' local _p - for _p in /patches/*; do + for _p in patches/*; do + [ X"patches/*" == X"${_p}" ] && continue echo " => $_p" # -N Always assume a forward patch. # -t Never prompt; assume the user is expert # -p0 full path, always - patch -N -t -p0 < $_p + patch -N -t -p0 -d / < "$_p" done } @@ -111,33 +133,35 @@ apply_role() { local _role="$1" - if [ ! -d "${_role}" ]; then + local _oldpwd="${PWD}" + local _rolepwd="${BASEDIR}/${_role}" + + if [ ! -d "${_rolepwd}" ]; then echo "===> Missing ${_role}" return fi - echo "===> Applying ${_role}" + echo "===> Applying role ${_role}" - local _oldpwd="${PWD}" - cd "${_role}" - - if [ -e siteXXrc ]; then + cd "${_rolepwd}" + if [ -e ./siteXXrc ]; then echo ' ==> Including siteXXrc' - . siteXXrc + . ./siteXXrc fi - append_pkg_path - run_command_lists - apply_patches - install_packages + cd "${_rolepwd}" && append_pkg_path + cd "${_rolepwd}" && run_command_lists + cd "${_rolepwd}" && apply_patches + cd "${_rolepwd}" && install_packages - if [ -e install.site ]; then - if [ -x install.site ]; then + cd "${_rolepwd}" + if [ -e ./install.site ]; then + if [ -x ./install.site ]; then echo ' ==> Running install.site' ./install.site else echo ' ==> Including install.site' - . install.site + . ./install.site fi fi @@ -150,6 +174,6 @@ exit fi -do_pre -process_roles -do_post +do_pre 2>&1 | /usr/bin/tee /var/log/install.log +process_roles 2>&1 | /usr/bin/tee -a /var/log/install.log | grep '^...>' +do_post 2>&1 | /usr/bin/tee -a /var/log/install.log