blob: 0ec5dfaea91e14810efa9a82ce222b5ec346ad02 (
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
#!/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##*-}
}
# Default function to generate a list of ATOMS to be used by the jobuild
# Should be overridden in the jobuild if required
atoms() {
local temp
temp="${jobuild%/*}/conf/${P}.atoms"
[ -f "${temp}" ] && ATOMS=$(<"${temp}")
}
# Initialise some basic jobuild env variables
initialise() {
jvars
atoms
}
# POST ${2}=${3} to ${1}
# Usage: post ${where} ${key} ${data}
# Result is stored in ${POST}
post() {
POST=$(wget "${1}"?"${2}"=${3} -O -)
}
# Wrapper for package managers
emerge() {
case "${PMAN}" in
emerge)
local CMD="/usr/bin/emerge --verbose --newuse --deep"
case ${1} in
build)
${CMD} ${ATOMS}
;;
build-binpkgs)
${CMD} --buildpkg ${ATOMS}
;;
use-binpkgs)
${CMD} --usepkg --getbinpkg ${ATOMS}
;;
*)
die "Unsupported merge action ${1}"
;;
esac
;;
pmerge)
die "pkgcore support not yet implemented"
;;
paludis)
die "paludis support not yet implemented"
;;
*)
${PMAN} || die "Running custom package manager command ${PMAN} failed"
;;
esac
}
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}
}
run_all_phases() {
local jobuild="${1}"
initialise
if ! source "${jobuild}"; then
die "Unable to source ${jobuild}"
fi
src_unpack
do_work
cleanup
}
|