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

File: [local] / openbsd / sxxu / Attic / install.sxxu (download)

Revision 1.10, Wed Apr 21 19:13:08 2010 UTC (14 years, 2 months ago) by andrew
Branch: MAIN
Changes since 1.9: +11 -11 lines

better paths to roles, siteXXrc and install.site

#!/bin/ksh -
# $Id: install.sxxu,v 1.10 2010/04/21 19:13:08 andrew Exp $

# Copyright (c) 2010 Andrew Fresh <andrew@afresh1.com>
#
# 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.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# based on (and some parts taken from) siteXXtools/install.site
# Copyright (c) 2006 Alex Holst <a@mongers.org>

BASEDIR=/var/siteXX
useradd_args="-m -gid =uid"
[ -e /var/siteXX/siteXXrc ] && . /var/siteXX/siteXXrc

export PKG_PATH

do_pre() {
    # nothing to do
}

do_post() {
    # nothing to do
}

process_roles() {
    local _oldpwd="${PWD}"

    cd "${BASEDIR}"
    if [ ! -e roles ]; then
        echo 'No roles defined.'
        exit
    fi

    local _roles
    set -A _roles
    local _role
    while read _role; do
	if [ -n "${_role}" ]; then
        	_roles[${#_roles[@]}]="$_role"
	fi
    done < roles
    
    for _role in "${_roles[@]}"; do
        apply_role "$_role"
    done

    cd "${_oldpwd}"
}


append_pkg_path() {
    [ ! -e pkg_path ] && return

    echo ' ==> Setting PKG_PATH'
    local _line
    while read _line; do
        if [ -z "${PKG_PATH}" ]; then
            PKG_PATH="$_line"
        else
            PKG_PATH="${PKG_PATH}:${_line}"
        fi
    done < pkg_path
    PKG_PATH=`eval echo $PKG_PATH`
}

run_command_lists() {
    local _f
    for _f in *_list; do
        [ ! -f "${_f}" ] && continue

        local _cmd=`basename "${_f%_list}"`
        local _args=`eval echo \\${${_cmd}_args}`

        echo " ==> Running $_cmd $_args"
        local _line
        while read _line; do
            echo "  => ${_line}"
            eval ${_cmd} ${_args} ${_line}
        done < ${_f}
    done
}

apply_patches() {
    [ ! -d patches ] && return

    echo ' ==> Applying patches'
    local _p
    for _p in patches/*; do
        echo "  => $_p"
        # -N Always assume a forward patch.
        # -t Never prompt; assume the user is expert
        # -p0 full path, always
        patch -N -t -p0 -d / < $_p
    done
}

install_packages() {
    [ ! -d packages ] && return

    echo ' ==> Installing packages'
    find packages -name '*.tgz' -print0 | xargs -0 pkg_add ${pkg_add_args}
}

apply_role() {
    local _role="$1"

    local _oldpwd="${PWD}"
    local _rolepwd="${BASEDIR}/${_role}"

    if [ ! -d "${_rolepwd}" ]; then
        echo "===> Missing ${_role}"
        return
    fi

    echo "===> Applying ${_role}"

    cd "${_rolepwd}"
    if [ -e ./siteXXrc ]; then
        echo ' ==> Including siteXXrc'
        . ./siteXXrc
    fi

    cd "${_rolepwd}" && append_pkg_path
    cd "${_rolepwd}" && run_command_lists
    cd "${_rolepwd}" && apply_patches
    cd "${_rolepwd}" && install_packages

    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
        fi
    fi

    cd "${_oldpwd}"
}


if [ ! -d "${BASEDIR}" ]; then
    echo Nothing to do.
    exit
fi

do_pre
process_roles
do_post