aboutsummaryrefslogtreecommitdiff
blob: 5dd27493b50813cb563cff1e12aa6667eb5c1820 (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
148
149
150
151
#!/bin/bash
# vim: set sw=4 sts=4 et :
# Copyright: 2008 Gentoo Foundation
# Author(s): Nirbheek Chauhan <nirbheek.chauhan@gmail.com>
# License: GPL-2
#
# jobuild-functions.sh: Functions for jobuild.sh.
# 
# Immortal lh!
#

die() {
    echo "$*"
    exit 1
}

jvars() {
    P=${jobuild##*/}
    P=${P%.jobuild}
    PN=${P%-*}
    PV=${P##*-}
}

atoms() {
    local temp
    temp="${jobuild%/*}/conf/${P}.atoms"
    [ -f "${temp}" ] && ATOMS=$(<"${temp}")
}

initialize() {
    jvars
    atoms
}

has() {
    local this=${1}; shift
    local those=${@}
    for i in ${those}; do
	[ "${this}" == "${i}" ] && return 0
    done
    return 1
}

# Lifted shamelessly from pkgcore
unpack() {
    local x y myfail srcdir taropts tar_subdir
    taropts='--no-same-owner'

    [ -z "$*" ] && die "Nothing passed to the 'unpack' command"

    for x in "$@"; do
        echo ">>> Unpacking ${x} to ${PWD}"
        myfail="failure unpacking ${x}"
        y="${x%.*}"
        y="${y##*.}"
        if [ "${x:0:2}" == "./" ]; then
            srcdir=''
        else
            srcdir="${JOBFILES_DIR}"
        fi

        [ ! -s "${srcdir}${x}" ] && die "$myfail: empty file"
        [ "${x/${JOBFILES_DIR}}" != "${x}" ] && \
            die "Arguments to unpack() should not begin with \${JOBFILES_DIR}."

        case "${x}" in
            *.tar)
                tar xf "${srcdir}${x}" ${taropts} || die "$myfail"
                ;;
            *.tar.gz|*.tgz|*.tar.Z)
                tar xzf "${srcdir}${x}" ${taropts} || die "$myfail"
                ;;
            *.tar.bz2|*.tbz2|*.tbz)
                bzip2 -dc "${srcdir}${x}" | tar xf - ${taropts}
                assert "$myfail"
                ;;
            *.ZIP|*.zip|*.jar)
                unzip -qo "${srcdir}${x}" || die "$myfail"
                ;;
            *.gz|*.Z|*.z)
                gzip -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
                ;;
            *.bz2|*.bz)
                bzip2 -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
                ;;
            *.7Z|*.7z)
                local my_output
                my_output="$(7z x -y "${srcdir}/${x}")"
                if [ $? -ne 0 ]; then
                    echo "${my_output}" >&2
                    die "$myfail"
                fi
                ;;
            *.RAR|*.rar)
                unrar x -idq -o+ "${srcdir}/${x}" || die "$myfail"
                ;;
            *.LHa|*.LHA|*.lha|*.lzh)
                lha xfq "${srcdir}/${x}" || die "$myfail"
                ;;
            *.a|*.deb)
                ar x "${srcdir}/${x}" || die "$myfail"
                ;;
            *.lzma)
                if [ "${y}" == "tar" ]; then
                    lzma -dc "${srcdir}${x}" | tar xof - ${taropts}
                    assert "$myfail"
                else
                    lzma -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
                fi
                ;;
            *)
                echo "unpack ${x}: file format not recognized. Ignoring."
                ;;
        esac
    done
    find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \
         xargs -0 chmod -fR a+rX,u+w,g-w,o-w
                        
}

src_unpack() {
    :
}

get_param() {
    # Param to extract
    local param="${1}"
    local jobuild="${2}"
    initialise

    if ! source "${jobuild}"; then
        die "Unable to source ${jobuild}"
    fi
    eval echo \$${param}
}

get_jobuild_path() {
    echo "${AUTOTUA_DIR}/jobtage/${1}"
}

run_all_phases() {
    local jobuild="${1}"
    initialise

    if ! source "${jobuild}"; then
        die "Unable to source ${jobuild}"
    fi
    src_unpack
    do_work
    cleanup
}