aboutsummaryrefslogtreecommitdiff
path: root/cran/cran.bash
blob: 7a2e18b483a3c9fff4a106f7009d247e8d5cf742 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
# vim: set sw=4 sts=4 et :

# Copyright (c) 2006 Danny van Dyk <kugelfang@gentoo.org>
#
# Based in part upon ebuild.sh from Portage, which is Copyright 1995-2005
# Gentoo Foundation and distributed under the terms of the GNU General
# Public License v2.
#
# This file is part of the Paludis package manager. Paludis is free software;
# you can redistribute it and/or modify it under the terms of the GNU General
# Public License as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.
#
# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA  02111-1307  USA

. ${PALUDIS_EBUILD_DIR}/echo_functions.bash

shopt -s expand_aliases

CRAN_KILL_PID=$$
alias die='diefunc "$FUNCNAME" "$LINENO"'
trap 'echo "die trap: exiting with error." 1>&2 ; exit 250' 15

for f in ${PALUDIS_BASHRC_FILES} ; do
    if [[ -f ${f} ]] ; then
        ebuild_notice "debug" "Loading bashrc file ${f}"
        source ${f}
    else
        ebuild_notice "debug" "Skipping bashrc file ${f}"
    fi
done

diefunc()
{
    local func="$1" line="$2"
    shift 2
    echo 1>&2
    echo "!!! ERROR in cran/${PN:-?}:" 1>&2
    echo "!!! In ${func:-?} at line ${line:-?}" 1>&2
    echo "!!! ${*:-(no message provided)}" 1>&2
    echo 1>&2

    echo "!!! Call stack:" 1>&2
    for (( n = 1 ; n < ${#FUNCNAME[@]} ; ++n )) ; do
        funcname=${FUNCNAME[${n}]}
        sourcefile=${BASH_SOURCE[${n}]}
        lineno=${BASH_LINENO[$(( n - 1 ))]}
        echo "!!!    * ${funcname} (${sourcefile}:${lineno})" 1>&2
    done
    echo 1>&2

    kill ${CRAN_KILL_PID}
    exit 249
}

cran_command() {
    local ret=1 command=${1}
    shift

    ebuild_section "Starting ${command}"

    if type cran_do_${command} &> /dev/null ; then
        cran_do_${command} || die "Failed to run command: ${command}"
    else
        die "Unknown command: ${command}"
    fi

    ebuild_section "Done ${command}"
}

cran_do_clean() {
    [[ -e ${WORKDIR} ]] && rm -rf ${WORKDIR}
    [[ -e ${IMAGE} ]] && rm -rf ${IMAGE}
    return 0
}

cran_do_fetch() {
    local mirror ret=0
    shift

    for mirror in ${PALUDIS_CRAN_MIRRORS[@]} ; do
        mkdir -p ${DISTDIR}
        cd ${DISTDIR}

        if [[ -e ${DISTFILE} ]] ; then
            echo "Already fetched: $(basename ${DISTFILE})"
            return 0
        fi

        local dofetch="${PALUDIS_EBUILD_DIR}/fetchers/do$(echo ${mirror%%://*})"
        local a="${mirror}/src/contrib/${DISTFILE}"
        if [[ -f "${dofetch}" ]] ; then
            ${dofetch} "${a}" "${DISTFILE}"
            ret=$?
        else
            eerror "Don't know how to fetch '${a}'"
            ret=1
        fi
        if [[ ${ret} == 0 ]] ; then
            break
        else
            echo "Failed to run \"${command}\" for mirror ${mirror}."
        fi
    done
    if [[ ${ret} != 0 ]] ; then
        echo "Finally failed to run \"${command}\"."
    fi
}

cran_do_install() {
    if [[ -e "${WORKDIR}" ]] ; then
        rm -Rf "${WORKDIR}" || die "Could not remove existing WORKDIR: ${WORKDIR}"
    fi
    mkdir -p "${WORKDIR}"
    cd "${WORKDIR}" || die "Could not cd to WORKDIR: ${WORKDIR}"

    local dounpack="${PALUDIS_EBUILD_DIR}/utils/dounpack"
    ${dounpack} "${DISTFILE}"

    # \todo Sandbox this?
    R CMD INSTALL -l "${IMAGE}/${PALUDIS_CRAN_LIBRARY##${ROOT}}" ${PN}
}

cran_do_merge() {
    [[ -e "${IMAGE}/${INSTALL_TO##${ROOT}}/R.css" ]] \
        && rm -f "${IMAGE}/${PALUDIS_CRAN_LIBRARY##${ROOT}}/R.css"
    mkdir -p "${PALUDIS_CRAN_LIBRARY}/paludis/${PN}"
    ${PALUDIS_EBUILD_DIR}/utils/merge "${IMAGE}" "${ROOT}" "${PALUDIS_CRAN_LIBRARY}/paludis/${PN}/CONTENTS"
    echo ${REPOSITORY} > "${PALUDIS_CRAN_LIBRARY}/paludis/${PN}/REPOSITORY"
}

cran_do_unmerge() {
    [[ -e "${PALUDIS_CRAN_LIBRARY}/paludis/${PN}/CONTENTS" ]] || die "CONTENTS file is missing for package ${PN}"
    ${PALUDIS_EBUILD_DIR}/utils/unmerge "${ROOT}" "${PALUDIS_CRAN_LIBRARY}/paludis/${PN}/CONTENTS"
}

for cmd in $* ; do
    cran_command ${cmd}
done