## ## OSSP due - Dynamic User Environment ## Copyright (c) 1994-2004 Ralf S. Engelschall ## Copyright (c) 1994-2004 The OSSP Project ## ## This file is part of OSSP due, a dynamic user environment ## which can found at http://www.ossp.org/pkg/tool/due/ ## ## Permission to use, copy, modify, and distribute this software for ## any purpose with or without fee is hereby granted, provided that ## the above copyright notice and this permission notice appear in all ## copies. ## ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ## SUCH DAMAGE. ## ## ~/.duerc: OSSP due run-command script ## # global DUE variables holding names of available # and actually loaded modules DUE_AVAILABLE="" DUE_LOADED="" # the DUE frontend command function due () { # parse command line local opt_h=no local opt_v=${DUE_VERBOSE:-no} local opt_p="" local opt OPTIND=1 while getopts hvp: opt; do case ${opt} in h ) opt_h=yes ;; v ) opt_v=yes ;; p ) opt_p=$OPTARG ;; esac done shift $((${OPTIND} - 1)) if [ ".${opt_h}" = .h ]; then echo "Usage: due [-h] [-v] [-p ] load [+|-] ..." return 0 fi # determine path to DUE modules local mod_path_system="" local mod_path="${DUE_PATH:-"$HOME/.due:@"}" if [ ".${opt_p}" != . ]; then mod_path="${opt_p}" fi mod_path=`echo "${mod_path}" |\ sed -e "s;@;${mod_path_system};" |\ sed -e 's/::/:/g' -e 's/^://' -e 's/:$//'` # determine available modules if [ -z ${DUE_AVAILABLE} ]; then local mod_dir for mod_dir in ${mod_path//:/ }; do [ ".${mod_dir}" = . ] && continue [ -d ${mod_dir} ] || continue local mod_name for mod_name in . `cd ${mod_dir} && echo due.*.sh`; do [ ".${mod_name}" = ".." -o ".${mod_name}" = ".*" ] && continue mod_name=${mod_name/#due./} mod_name=${mod_name/%.sh/} eval "DUE_AVAILABLE=\"${DUE_AVAILABLE}${DUE_AVAILABLE:+,}${mod_name}\"" done done fi # dispatch into commands cmd="$1" shift case "${cmd}" in load ) # by default all modules are disabled local mod_name for mod_name in ${DUE_AVAILABLE//,/ }; do eval "local mod_enable_${mod_name}=no" done # determine whether to enable or disable requested module(s) for mod_name in "$@"; do local val=yes case "${mod_name}" in +* ) val=yes; mod_name=${mod_name:1} ;; -* ) val=no; mod_name=${mod_name:1} ;; esac if [ ".${mod_name}" = .all ]; then for mod_name in ${DUE_AVAILABLE//,/ }; do eval "mod_enable_${mod_name}=${val}" done else local exists eval "exists=\${mod_enable_${mod_name}}" if [ ".${exists}" = . ]; then echo "due:ERROR: invalid module \"${mod_name}\"" 1>&2 return 1 fi eval "mod_enable_${mod_name}=${val}" fi done # load enabled (and still not loaded) modules for mod_name in ${DUE_AVAILABLE//,/ }; do eval "val=\${mod_enable_${mod_name}}" if [ ".${val}" = .yes ]; then local loadit=yes for loaded in ${DUE_LOADED//,/ }; do if [ ".${loaded}" = ".${mod_name}" ]; then # module already loaded loadit=no break fi done if [ ".${loadit}" = .yes ]; then local mod_file="" local mod_dir for mod_dir in ${mod_path//:/ }; do [ ".${mod_dir}" = . ] && continue if [ -f "${mod_dir}/due.${mod_name}.sh" ]; then mod_file="${mod_dir}/due.${mod_name}.sh" break fi done if [ ".${mod_file}" = . ]; then # should not happen here again echo "due:ERROR: invalid module \"${mod_name}\"" 1>&2 return 1 fi local verbose=${DUE_VERBOSE} DUE_VERBOSE=${opt_v} source ${mod_file} DUE_VERBOSE=${verbose} DUE_LOADED="${DUE_LOADED}${DUE_LOADED:+,}${mod_name}" if [ ".${opt_v}" = .yes ]; then echo "due: loaded shell module \"${mod_name}\"" 1>&2 fi fi fi done ;; * ) echo "due:ERROR: invalid command \"${cmd}\"" 1>&2 return 1 ;; esac return 0 }