From 180de2f492cca5e0b48b5411557c73f2dedb7f4d Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 18 Sep 2015 18:24:02 +0200 Subject: [PATCH] Bootstrap: - new command 'modbuild' to build modules - separate bootstrapping from other build-blocks - review BASH libraries - adapt build-blocks in bootstrapping --- Bootstrap/Modules/build | 10 +- .../Pmodules/libpbuild.bash | 89 +---------- Bootstrap/Pmodules/libpmodules.bash | 115 -------------- Bootstrap/Pmodules/libstd.bash | 141 ++++++++++++++++++ Bootstrap/Pmodules/modbuild | 105 +++++++++++++ Bootstrap/Pmodules/modmanage.bash.in | 1 + Bootstrap/Pmodules/modulecmd.bash.in | 1 + Bootstrap/Tcl/build | 12 +- Bootstrap/bash/build | 8 +- Bootstrap/compile_pmodules.sh | 13 +- .../versions.conf} | 0 Bootstrap/coreutils/build | 8 +- Bootstrap/dialog/build | 8 +- Bootstrap/getopt/build | 14 +- Bootstrap/gettext/build | 8 +- Bootstrap/install_pmodules.sh | 20 +-- bin/pbuild | 8 - config/environment.bash | 1 - lib/lib.bash | 140 ----------------- lib/libem.bash | 1 - 20 files changed, 306 insertions(+), 397 deletions(-) rename lib/libpmodules.bash => Bootstrap/Pmodules/libpbuild.bash (93%) create mode 100644 Bootstrap/Pmodules/libstd.bash create mode 100755 Bootstrap/Pmodules/modbuild rename Bootstrap/{Pmodules_version.conf => config/versions.conf} (100%) delete mode 100755 bin/pbuild delete mode 120000 config/environment.bash delete mode 100644 lib/lib.bash delete mode 120000 lib/libem.bash diff --git a/Bootstrap/Modules/build b/Bootstrap/Modules/build index c2cb49c..410fc78 100755 --- a/Bootstrap/Modules/build +++ b/Bootstrap/Modules/build @@ -1,10 +1,10 @@ -#!/usr/bin/env pbuild +#!/usr/bin/env modbuild TCL_DIR="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}" PATH="${TCL_DIR}/bin:${PATH}" -pmodules.configure() { +pbuild::configure() { case ${OS} in Linux ) declare -x LIBS="-lz -lpthread" @@ -23,7 +23,7 @@ pmodules.configure() { || exit 1 } -pmodules.post_install() { +pbuild::post_install() { rm -v ${PREFIX}/Modules/bin/add.modules rm -v ${PREFIX}/Modules/bin/mkroot rm -rfv ${PREFIX}/Modules/modulefiles @@ -45,8 +45,8 @@ module() { # use system gcc to compile declare -rx CC=gcc -pmodules.add_to_group 'Tools' -pmodules.make_all +pbuild::add_to_group 'Tools' +pbuild::make_all # Local Variables: # mode: sh diff --git a/lib/libpmodules.bash b/Bootstrap/Pmodules/libpbuild.bash similarity index 93% rename from lib/libpmodules.bash rename to Bootstrap/Pmodules/libpbuild.bash index 42ff8de..3a12d3f 100644 --- a/lib/libpmodules.bash +++ b/Bootstrap/Pmodules/libpbuild.bash @@ -12,10 +12,6 @@ if [[ -z ${BUILD_BLOCK} ]]; then declare -r BUILD_BLOCK="${BUILD_BLOCK_DIR}"/$(basename "$0") fi -declare -rx SHLIBDIR=$( cd $(dirname "$BASH_SOURCE") && pwd ) -source "${SHLIBDIR}/lib.bash" - -declare -rx BUILD_BASEDIR=$(std::abspath "${SHLIBDIR}/..") PATH=/usr/bin:/bin:/usr/sbin:/sbin @@ -27,19 +23,16 @@ if [[ "${OS}" == "Darwin" ]]; then fi - # number of parallel make jobs declare -i JOBS=3 -source "$(readlink ${BUILD_BASEDIR}/config/environment.bash)" - declare -xr BUILD_CONFIGDIR="${BUILD_BASEDIR}/config" declare -xr BUILD_SCRIPTSDIR="${BUILD_BASEDIR}/scripts" declare -xr BUILD_TMPDIR="${BUILD_BASEDIR}/tmp" declare -xr BUILD_DOWNLOADSDIR="${BUILD_BASEDIR}/Downloads" declare -xr BUILD_VERSIONSFILE="${BUILD_CONFIGDIR}/versions.conf" -source "${BUILD_CONFIGDIR}/Pmodules.conf" +#source "${BUILD_CONFIGDIR}/Pmodules.conf" declare -x PREFIX='' declare -x DOCDIR='' @@ -688,7 +681,8 @@ check_compiler() { std::die 0 "Package cannot be build with ${COMPILER}/${COMPILER_VERSION}." } -# unfortunatelly we need sometime an OS depended post-install + +# unfortunatelly sometime we need an OS depended post-install post_install_linux() { cd "${PREFIX}" # solve multilib problem with LIBRARY_PATH on 64bit Linux @@ -715,7 +709,7 @@ pbuild::make_all() { setup_env2_bootstrap fi - if [[ ! -d "${PREFIX}" ]] || [[ ${force_rebuild} == 'yes' ]]; then + if [[ ! -d "${PREFIX}" ]] || [[ ${force_rebuild} == 'yes' ]] || [[ ${bootstrap} == 'yes' ]]; then building='yes' echo "Building $P/$V ..." [[ ${dry_run} == yes ]] && std::die 0 "" @@ -747,6 +741,9 @@ pbuild::make_all() { cd "${MODULE_BUILDDIR}" pbuild::install pbuild::post_install + if typeset -F pbuild::post_install_${OS} 1>/dev/null 2>&1; then + pbuild::post_install_${OS} "$@" + fi pbuild::install_doc post_install if [[ ${bootstrap} == 'no' ]]; then @@ -772,81 +769,12 @@ pbuild::make_all() { return 0 } -# -# legacy functions, should be removed asap -# -pmodules.supported_os() { - pbuild::supported_os "$@" -} - -pmodules.add_to_group() { - pbuild::add_to_group "@" -} - -pmodules.set_build_dependencies() { - pbuild::set_build_dependencies "$@" -} - -pmodules.set_runtime_dependencies() { - pbuild::set_runtime_dependencies "$@" -} - -pmodules.set_docfiles() { - pbuild::set_docfiles "$@" -} - -pmodules.set_supported_compilers() { - pbuild::set_supported_compilers "$@" -} - -pmodules.cleanup_env() { - pbuild::cleanup_env "$@" -} - -pmodules.pre_configure() { - pbuild::pre_configure "$@" -} - -pmodules.configure() { - pbuild::configure "$@" -} - -pmodules.build() { - pbuild::build "$@" -} - -pmodules.install() { - pbuild::install "$@" -} - -pmodules.post_install() { - pbuild::post_install "$@" -} - -pmodules.install_doc() { - pbuild::install_doc "$@" -} - -pmodules.cleanup_build() { - pbuild::cleanup_build "$@" -} - -pmodules.cleanup_src() { - pbuild::cleanup_src "$@" -} - - -pmodules.make_all() { - pbuild::make_all "$@" -} - ############################################################################## # debug_on='no' force_rebuild='no' ENVIRONMENT_ARGS='' dry_run='no' -bootstrap='no' enable_cleanup_build='yes' enable_cleanup_src='no' @@ -951,8 +879,7 @@ if [[ ${bootstrap} == no ]]; then else unset PMODULES_HOME unset PMODULES_VERSION - read_versions "${BUILD_BASEDIR}/Bootstrap/Pmodules_version.conf" - source "/opt/psi/config/environment.bash" + std::read_versions "${BUILD_BASEDIR}/config/versions.conf" fi P=$(basename $(dirname "${BUILD_BLOCK}")) diff --git a/Bootstrap/Pmodules/libpmodules.bash b/Bootstrap/Pmodules/libpmodules.bash index 9e7d27e..db19b96 100644 --- a/Bootstrap/Pmodules/libpmodules.bash +++ b/Bootstrap/Pmodules/libpmodules.bash @@ -35,121 +35,6 @@ pmodules::check_env() { } -std::log() { - local -ri fd=$1 - local -r fmt="$2\n" - shift 2 - printf -- "$fmt" "$@" 1>&$fd -} - -std::info() { - std::log 2 "$1" "${@:2}" -} - -std::error() { - std::log 2 "$1" "${@:2}" -} - -std::debug() { - [[ ${PMODULES_DEBUG} ]] || return 0 - std::log 2 "$@" -} - -std::die() { - local -ri ec=$1 - shift - if [[ -n $@ ]]; then - local -r fmt=$1 - shift - std::log 2 "$fmt" "$@" - fi - exit $ec -} - -# -# get answer to yes/no question -# -# $1: prompt -# -std::get_YN_answer() { - local -r prompt="$1" - local ans - read -p "${prompt}" ans - case ${ans} in - y|Y ) - return 0;; - * ) - return 1;; - esac -} - -# -# return normalized abolute pathname -# $1: filename -std::get_abspath() { - local -r fname=$1 - [[ -r "${fname}" ]] || return 1 - if [[ -d ${fname} ]]; then - echo $(cd "${fname}" && pwd) - else - local -r dname=$(dirname "${fname}") - echo $(cd "${dname}" && pwd)/$(basename "${fname}") - fi -} - -std::append_path () { - local -r P=$1 - local -r d=$2 - - if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then - if [[ -z ${!P} ]]; then - eval $P=${d} - else - eval $P=${!P}:${d} - fi - fi -} - -std::prepend_path () { - local -r P=$1 - local -r d=$2 - - if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then - if [[ -z ${!P} ]]; then - eval $P=${d} - else - eval $P=${d}:${!P} - fi - fi -} - -std::remove_path() { - local -r P=$1 - local -r d=$2 - local new_path='' - local -r _P=( ${!P//:/ } ) - # loop over all entries in path - for entry in "${_P[@]}"; do - [[ "${entry}" != "${d}" ]] && new_path+=":${entry}" - done - # remove leading ':' - eval ${P}="${new_path:1}" -} - -# -# split file name -# -std::split_fname() { - local -r savedIFS="${IFS}" - IFS='/' - local std__split_fname_result__=( $(echo "${@: -1}") ) - IFS=${savedIFS} - eval $1=\(\"\${std__split_fname_result__[@]}\"\) - if (( $# >= 3 )); then - eval $2=${#std__split_fname_result__[@]} - fi -} - # Local Variables: # mode: sh # sh-basic-offset: 8 diff --git a/Bootstrap/Pmodules/libstd.bash b/Bootstrap/Pmodules/libstd.bash new file mode 100644 index 0000000..3f142bb --- /dev/null +++ b/Bootstrap/Pmodules/libstd.bash @@ -0,0 +1,141 @@ +#!/bin/bash + +# +# logging/message functions +# +std::log() { + local -ri fd=$1 + local -r fmt="$2\n" + shift 2 + printf -- "$fmt" "$@" 1>&$fd +} + +std::info() { + std::log 2 "$1" "${@:2}" +} + +std::error() { + std::log 2 "$1" "${@:2}" +} + +std::debug() { + [[ ${PMODULES_DEBUG} ]] || return 0 + std::log 2 "$@" +} + +std::die() { + local -ri ec=$1 + shift + if [[ -n $@ ]]; then + local -r fmt=$1 + shift + std::log 2 "$fmt" "$@" + fi + exit $ec +} + +# +# get answer to yes/no question +# +# $1: prompt +# +std::get_YN_answer() { + local -r prompt="$1" + local ans + read -p "${prompt}" ans + case ${ans} in + y|Y ) + return 0;; + * ) + return 1;; + esac +} + +# +# return normalized abolute pathname +# $1: filename +std::get_abspath() { + local -r fname=$1 + [[ -r "${fname}" ]] || return 1 + if [[ -d ${fname} ]]; then + echo $(cd "${fname}" && pwd) + else + local -r dname=$(dirname "${fname}") + echo $(cd "${dname}" && pwd)/$(basename "${fname}") + fi +} + +std::append_path () { + local -r P=$1 + local -r d=$2 + + if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then + if [[ -z ${!P} ]]; then + eval $P=${d} + else + eval $P=${!P}:${d} + fi + fi +} + +std::prepend_path () { + local -r P=$1 + local -r d=$2 + + if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then + if [[ -z ${!P} ]]; then + eval $P=${d} + else + eval $P=${d}:${!P} + fi + fi +} + +std::remove_path() { + local -r P=$1 + local -r d=$2 + local new_path='' + local -r _P=( ${!P//:/ } ) + # loop over all entries in path + for entry in "${_P[@]}"; do + [[ "${entry}" != "${d}" ]] && new_path+=":${entry}" + done + # remove leading ':' + eval ${P}="${new_path:1}" +} + +# +# split file name +# +std::split_fname() { + local -r savedIFS="${IFS}" + IFS='/' + local std__split_fname_result__=( $(echo "${@: -1}") ) + IFS=${savedIFS} + eval $1=\(\"\${std__split_fname_result__[@]}\"\) + if (( $# >= 3 )); then + eval $2=${#std__split_fname_result__[@]} + fi +} + +std::read_versions() { + local -r fname="$1" + local varname='' + while read _name _version; do + [[ -z ${_name} ]] && continue + [[ -z ${_version} ]] && continue + [[ "${_name:0:1}" == '#' ]] && continue + var_name=$(echo ${_name} | tr [:lower:] [:upper:])_VERSION + # don't set version, if already set + if [[ -z ${!var_name} ]]; then + eval ${var_name}="${_version}" + fi + done < "${fname}" +} + + +# Local Variables: +# mode: sh +# sh-basic-offset: 8 +# tab-width: 8 +# End: diff --git a/Bootstrap/Pmodules/modbuild b/Bootstrap/Pmodules/modbuild new file mode 100755 index 0000000..a029ffd --- /dev/null +++ b/Bootstrap/Pmodules/modbuild @@ -0,0 +1,105 @@ +#!/bin/bash + +set -x + +declare -r mydir=$(dirname "$0") +declare -r libpbuild='libpbuild.bash' +declare -r libstd='libstd.bash' +declare -r pmodule_environment='environment.bash' + +# source BASH library with standard functions +if [[ -r ${mydir}/${libstd} ]]; then + source "${mydir}/${libstd}" +elif [[ -r ${mydir}/../lib/${libstd} ]]; then + source "${mydir}/../lib/${libstd}" +else + echo "Oops: required BASH library '${libstd}' not found" 1>&2 + exit 1 +fi + +declare -rx BUILD_BLOCK=$(std::get_abspath "$1") +declare -rx BUILD_BLOCK_DIR=$(dirname "${BUILD_BLOCK}") +shift 1 + +# source Pmodule environment configuration +if [[ -r ${mydir}/../config/${pmodule_environment} ]]; then + # we are bootstrapping + source "${mydir}/../config/${pmodule_environment}" + declare -rx BUILD_BASEDIR=$(std::get_abspath "${mydir}/..") + bootstrap='yes' + +elif [[ -n ${PMODULES_ROOT} ]] && [[ -n ${PMODULES_CONFIG_DIR} ]] && \ + [[ -r ${PMODULES_ROOT}/${PMODULES_CONFIG_DIR}/${pmodule_environment} ]]; then + source ${PMODULES_ROOT}/${PMODULES_CONFIG_DIR}/${pmodule_environment} + declare -rx BUILD_BASEDIR=$(std::get_abspath "${BUILD_BLOCK_DIR}/../../..") + bootstrap='no' + +fi + +# +# We need GNU versions of the following utilities. This code works +# well on Linux and Mac OS X with MacPorts. +# :FIXME: implement a smarter, portable solution. +# +shopt -s expand_aliases +unalias -a + +__path=$(which gdate 2>/dev/null) +if [[ $__path ]]; then + alias date=$__path +else + alias date=$(which date 2>/dev/null) +fi + +__path=$(which ginstall 2>/dev/null) +if [[ $__path ]]; then + alias install=$__path +else + alias install=$(which install 2>/dev/null) +fi + +__path=$(which greadlink 2>/dev/null) +if [[ $__path ]]; then + alias readlink=$__path +else + alias readlink=$(which readlink 2>/dev/null) +fi + +__path=$(which gsed 2>/dev/null) +if [[ $__path ]]; then + alias sed=$__path +else + alias sed=$(which sed 2>/dev/null) +fi + +# +# set an error handler. If a function _exit() exists, it will be called +# with the passed exit code. +# +# $1 exit code +# +set -o errexit + +trap "std::error_handler" ERR + +std::error_handler() { + local -i ec=$? + + typeset -F _exit 1>/dev/null 2>&1 && _exit "${ec}" + exit ${ec} +} + +# +# run build +# + +if [[ -r ${mydir}/${libpbuild} ]]; then + source "${mydir}/${libpbuild}" +elif [[ -r ${mydir}/../lib/${libpbuild} ]]; then + source "${mydir}/../lib/${libpbuild}" +else + echo "Oops: required BASH library '${libpbuild}' not found" 1>&2 + exit 1 +fi + +source "${BUILD_BLOCK}" diff --git a/Bootstrap/Pmodules/modmanage.bash.in b/Bootstrap/Pmodules/modmanage.bash.in index 87ed047..015fd48 100755 --- a/Bootstrap/Pmodules/modmanage.bash.in +++ b/Bootstrap/Pmodules/modmanage.bash.in @@ -12,6 +12,7 @@ declare -r bindir="${prefix}/bin" declare -r libdir="${prefix}/lib" declare -r libexecdir="${prefix}/libexec" +source "${libdir}/libstd.bash" source "${libdir}/libpmodules.bash" PATH="${bindir}:${PATH}" diff --git a/Bootstrap/Pmodules/modulecmd.bash.in b/Bootstrap/Pmodules/modulecmd.bash.in index 918b751..adf9475 100755 --- a/Bootstrap/Pmodules/modulecmd.bash.in +++ b/Bootstrap/Pmodules/modulecmd.bash.in @@ -14,6 +14,7 @@ declare -r bindir="${prefix}/bin" declare -r libdir="${prefix}/lib" declare -r libexecdir="${prefix}/libexec" +source "${libdir}/libstd.bash" source "${libdir}/libpmodules.bash" PATH="${bindir}:${PATH}" diff --git a/Bootstrap/Tcl/build b/Bootstrap/Tcl/build index 379122e..2f7bab6 100755 --- a/Bootstrap/Tcl/build +++ b/Bootstrap/Tcl/build @@ -1,6 +1,6 @@ -#!/usr/bin/env pbuild +#!/usr/bin/env modbuild -pmodules.configure() { +pbuild::configure() { case ${OS} in Linux ) srcdir="${MODULE_SRCDIR}/unix" @@ -15,10 +15,10 @@ pmodules.configure() { || exit 1 } -pmodules.post_install() { +pbuild::post_install() { { cd "${PREFIX}"/bin && rm -f tclsh && ln -fs tclsh${V%.*} tclsh; }; } -pmodules.add_to_group 'Tools' -pmodules.set_docfiles 'license.terms' 'README' -pmodules.make_all +pbuild::add_to_group 'Tools' +pbuild::set_docfiles 'license.terms' 'README' +pbuild::make_all diff --git a/Bootstrap/bash/build b/Bootstrap/bash/build index 70cdb1a..27e258a 100755 --- a/Bootstrap/bash/build +++ b/Bootstrap/bash/build @@ -1,10 +1,10 @@ -#!/usr/bin/env pbuild +#!/usr/bin/env modbuild -pmodules.configure() { +pbuild::configure() { "${MODULE_SRCDIR}"/configure \ --prefix="${PREFIX}" \ || exit 1 } -pmodules.add_to_group 'Tools' -pmodules.make_all +pbuild::add_to_group 'Tools' +pbuild::make_all diff --git a/Bootstrap/compile_pmodules.sh b/Bootstrap/compile_pmodules.sh index 00fcdb2..b8181ed 100755 --- a/Bootstrap/compile_pmodules.sh +++ b/Bootstrap/compile_pmodules.sh @@ -1,15 +1,14 @@ #!/bin/bash -declare -r BASE_DIR=$(cd "$(dirname $0)/.." && pwd) -declare -r BOOTSTRAP_DIR="${BASE_DIR}/Bootstrap" - -source "${BASE_DIR}/lib/lib.bash" +declare -r BOOTSTRAP_DIR=$(dirname "$0") unset PMODULES_HOME unset PMODULES_VERSION -read_versions "${BOOTSTRAP_DIR}/Pmodules_version.conf" -source "/opt/psi/config/environment.bash" +source "${BOOTSTRAP_DIR}/Pmodules/libstd.bash" +source "${BOOTSTRAP_DIR}/config/environment.bash" + +std::read_versions "${BOOTSTRAP_DIR}/config/versions.conf" #if [[ -n ${PMODULES_DIR} ]] && [[ "${PMODULES_DIR}" != "/" ]] && [[ -d "${PMODULES_DIR}" ]]; then # rm -rf "${PMODULES_DIR}" @@ -19,7 +18,7 @@ build () { local -r name="$1" local -r version="$2" - "${BOOTSTRAP_DIR}/${name}/build" --bootstrap --disable-cleanup "${version}" || \ + "${BOOTSTRAP_DIR}/Pmodules/modbuild" "${BOOTSTRAP_DIR}/${name}/build" --disable-cleanup "${version}" || \ std::die 3 "Compiling '${name}' failed!" } diff --git a/Bootstrap/Pmodules_version.conf b/Bootstrap/config/versions.conf similarity index 100% rename from Bootstrap/Pmodules_version.conf rename to Bootstrap/config/versions.conf diff --git a/Bootstrap/coreutils/build b/Bootstrap/coreutils/build index 63030c7..ed5e87a 100755 --- a/Bootstrap/coreutils/build +++ b/Bootstrap/coreutils/build @@ -1,10 +1,10 @@ -#!/usr/bin/env pbuild +#!/usr/bin/env modbuild -pmodules.configure() { +pbuild::configure() { "${MODULE_SRCDIR}"/configure \ --prefix="${PREFIX}" \ || exit 1 } -pmodules.add_to_group 'Tools' -pmodules.make_all +pbuild::add_to_group 'Tools' +pbuild::make_all diff --git a/Bootstrap/dialog/build b/Bootstrap/dialog/build index 70cdb1a..27e258a 100755 --- a/Bootstrap/dialog/build +++ b/Bootstrap/dialog/build @@ -1,10 +1,10 @@ -#!/usr/bin/env pbuild +#!/usr/bin/env modbuild -pmodules.configure() { +pbuild::configure() { "${MODULE_SRCDIR}"/configure \ --prefix="${PREFIX}" \ || exit 1 } -pmodules.add_to_group 'Tools' -pmodules.make_all +pbuild::add_to_group 'Tools' +pbuild::make_all diff --git a/Bootstrap/getopt/build b/Bootstrap/getopt/build index b7984cb..d486ed3 100755 --- a/Bootstrap/getopt/build +++ b/Bootstrap/getopt/build @@ -1,10 +1,10 @@ -#!/usr/bin/env pbuild +#!/usr/bin/env modbuild -pmodules.configure() { +pbuild::configure() { : } -pmodules.build() { +pbuild::build() { case ${OS} in Linux ) declare -x LDFLAGS="-lintl" @@ -18,20 +18,20 @@ pmodules.build() { make -e } -pmodules.install() { +pbuild::install() { cd "${MODULE_SRCDIR}" declare -x DESTDIR="${PREFIX}" declare -x prefix='' make -e install } -pmodules.cleanup_build() { +pbuild::cleanup_build() { cd "${MODULE_SRCDIR}" make -e realclean } -pmodules.add_to_group 'Tools' -pmodules.make_all +pbuild::add_to_group 'Tools' +pbuild::make_all # Local Variables: # mode: sh diff --git a/Bootstrap/gettext/build b/Bootstrap/gettext/build index ad631df..c859d43 100755 --- a/Bootstrap/gettext/build +++ b/Bootstrap/gettext/build @@ -1,6 +1,6 @@ -#!/usr/bin/env pbuild +#!/usr/bin/env modbuild -pmodules.configure() { +pbuild::configure() { "${MODULE_SRCDIR}"/configure \ --prefix="${PREFIX}" \ --disable-java \ @@ -18,5 +18,5 @@ pmodules.configure() { || exit 1 } -pmodules.add_to_group 'Tools' -pmodules.make_all +pbuild::add_to_group 'Tools' +pbuild::make_all diff --git a/Bootstrap/install_pmodules.sh b/Bootstrap/install_pmodules.sh index d6965c4..489625a 100755 --- a/Bootstrap/install_pmodules.sh +++ b/Bootstrap/install_pmodules.sh @@ -1,16 +1,13 @@ #!/bin/bash +declare BOOTSTRAP_DIR=$(dirname "$0") +source "${BOOTSTRAP_DIR}/Pmodules/libstd.bash" +source "${BOOTSTRAP_DIR}/config/environment.bash" -declare -r BASE_DIR=$(cd "$(dirname $0)/.." && pwd) -declare -r BOOTSTRAP_DIR="${BASE_DIR}/Bootstrap" +declare -r BOOTSTRAP_DIR=$(std::get_abspath "${BOOTSTRAP_DIR}") declare -r SRC_DIR="${BOOTSTRAP_DIR}/Pmodules" -source "${BASE_DIR}/lib/lib.bash" +std::read_versions "${BOOTSTRAP_DIR}/config/versions.conf" -unset PMODULES_HOME -unset PMODULES_VERSION - -read_versions "${BOOTSTRAP_DIR}/Pmodules_version.conf" -source "/opt/psi/config/environment.bash" echo "Installing to ${PMODULES_HOME} ..." sed_cmd="s:@PMODULES_HOME@:${PMODULES_HOME}:g;" @@ -30,14 +27,17 @@ install -m 0755 "${SRC_DIR}/modulecmd.bash" "${PMODULES_HOME}/libexec" install -m 0755 "${SRC_DIR}/modmanage" "${PMODULES_HOME}/bin" install -m 0755 "${SRC_DIR}/modmanage.bash" "${PMODULES_HOME}/libexec" install -m 0755 "${SRC_DIR}/dialog.bash" "${PMODULES_HOME}/bin" +install -m 0755 "${SRC_DIR}/modbuild" "${PMODULES_HOME}/bin" -install -m 0755 "${SRC_DIR}/environment.bash" "${PMODULES_HOME}/config" -install -m 0755 "${SRC_DIR}/profile.bash" "${PMODULES_HOME}/config" +install -m 0755 "${SRC_DIR}/environment.bash" "${PMODULES_HOME}/config/environment.bash.in" +install -m 0755 "${SRC_DIR}/profile.bash" "${PMODULES_HOME}/config/profile.bash.in" install -m 0644 "${SRC_DIR}/bash" "${PMODULES_HOME}/init" install -m 0644 "${SRC_DIR}/bash_completion" "${PMODULES_HOME}/init" install -m 0644 "${SRC_DIR}/libpmodules.bash" "${PMODULES_HOME}/lib" +install -m 0644 "${SRC_DIR}/libpbuild.bash" "${PMODULES_HOME}/lib" +install -m 0644 "${SRC_DIR}/libstd.bash" "${PMODULES_HOME}/lib" install -m 0644 "${SRC_DIR}/libmodules.tcl" "${PMODULES_HOME}/lib/tcl8.6" { diff --git a/bin/pbuild b/bin/pbuild deleted file mode 100755 index 4415733..0000000 --- a/bin/pbuild +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -source $(dirname $0)/../lib/lib.bash -declare -rx BUILD_BLOCK=$(std::abspath "$1") -declare -rx BUILD_BLOCK_DIR=$(dirname "${BUILD_BLOCK}") -shift 1 -source $(dirname $0)/../lib/libpmodules.bash -source "${BUILD_BLOCK}" diff --git a/config/environment.bash b/config/environment.bash deleted file mode 120000 index f551b30..0000000 --- a/config/environment.bash +++ /dev/null @@ -1 +0,0 @@ -/opt/psi/config/environment.bash \ No newline at end of file diff --git a/lib/lib.bash b/lib/lib.bash deleted file mode 100644 index 1a86d87..0000000 --- a/lib/lib.bash +++ /dev/null @@ -1,140 +0,0 @@ -#!/bin/bash - -# -# We need GNU versions of the following utilities. This code works -# well on Linux and Mac OS X with MacPorts. -# :FIXME: implement a smarter, portable solution. -# -shopt -s expand_aliases -unalias -a - -__path=$(which gdate 2>/dev/null) -if [[ $__path ]]; then - alias date=$__path -else - alias date=$(which date 2>/dev/null) -fi - -__path=$(which ginstall 2>/dev/null) -if [[ $__path ]]; then - alias install=$__path -else - alias install=$(which install 2>/dev/null) -fi - -__path=$(which greadlink 2>/dev/null) -if [[ $__path ]]; then - alias readlink=$__path -else - alias readlink=$(which readlink 2>/dev/null) -fi - -__path=$(which gsed 2>/dev/null) -if [[ $__path ]]; then - alias sed=$__path -else - alias sed=$(which sed 2>/dev/null) -fi - -# -# set an error handler. If a function _exit() exists, it will be called -# with the passed exit code. -# -# $1 exit code -# -set -o errexit - -trap "std::error_handler" ERR - -std::error_handler() { - local -i ec=$? - - typeset -F _exit 1>/dev/null 2>&1 && _exit "${ec}" - exit ${ec} -} - -# -# logging/message functions -# -std::log() { - local -ri fd=$1 - local -r fmt="$2\n" - shift 2 - printf -- "$fmt" "$@" >> /dev/fd/$fd -} - -std::info() { - std::log 2 "$1\n" "${@:2}" -} - -std::error() { - std::log 2 "$1\n" "${@:2}" -} - -std::debug() { - [[ ${PMODULES_DEBUG} ]] || return 0 - std::log 2 "$@" -} - -std::die() { - local -ri ec=$1 - shift - local cout - if (( ec == 0)); then - cout='1' - else - cout='2' - fi - if [[ -n $@ ]]; then - local -r fmt=$1 - shift - std::log $cout "$fmt" "$@" - fi - exit $ec -} - -std::abspath () { - readlink -f "$1" -} - -std::append_path () { - local -r P=$1 - local -r d=$2 - - if ! egrep -q "(^|:)${d}($|:)" <<<${!P} ; then - if [[ -z ${!P} ]]; then - eval $P=${d} - else - eval $P=${!P}:${d} - fi - fi -} - -std::prepend_path () { - local -r P=$1 - local -r d=$2 - - if ! egrep -q "(^|:)${d}($|:)" <<<${!P} ; then - if [[ -z ${!P} ]]; then - eval $P=${d} - else - eval $P="${d}:${!P}" - fi - fi -} - -read_versions() { - local -r fname="$1" - local varname='' - while read _name _version; do - [[ -z ${_name} ]] && continue - [[ -z ${_version} ]] && continue - [[ "${_name:0:1}" == '#' ]] && continue - var_name=$(echo ${_name} | tr [:lower:] [:upper:])_VERSION - # don't set version, if already set - if [[ -z ${!var_name} ]]; then - eval ${var_name}="${_version}" - fi - done < "${fname}" -} - diff --git a/lib/libem.bash b/lib/libem.bash deleted file mode 120000 index 8d08235..0000000 --- a/lib/libem.bash +++ /dev/null @@ -1 +0,0 @@ -libpmodules.bash \ No newline at end of file