| 1 | # Copyright 1999-2002 Gentoo Technologies, Inc. |
1 | # Copyright 1999-2003 Gentoo Technologies, Inc. |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
|
|
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.24 2003/03/03 21:27:15 vapier Exp $ |
|
|
4 | # |
| 3 | # Author: Martin Schlemmer <azarah@gentoo.org> |
5 | # Author: Martin Schlemmer <azarah@gentoo.org> |
| 4 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.7 2002/11/25 04:20:07 vapier Exp $ |
6 | # |
| 5 | # This eclass is for general purpose functions that most ebuilds |
7 | # This eclass is for general purpose functions that most ebuilds |
| 6 | # have to implement themselves. |
8 | # have to implement themselves. |
| 7 | # |
9 | # |
| 8 | # NB: If you add anything, please comment it! |
10 | # NB: If you add anything, please comment it! |
| 9 | |
11 | |
| 10 | ECLASS=eutils |
12 | ECLASS=eutils |
| 11 | INHERITED="$INHERITED $ECLASS" |
13 | INHERITED="$INHERITED $ECLASS" |
| 12 | |
14 | |
| 13 | newdepend sys-devel/patch |
15 | newdepend "!bootstrap? ( sys-devel/patch )" |
| 14 | |
16 | |
| 15 | DESCRIPTION="Based on the ${ECLASS} eclass" |
17 | DESCRIPTION="Based on the ${ECLASS} eclass" |
| 16 | |
18 | |
| 17 | # This function generate linker scripts in /usr/lib for dynamic |
19 | # This function generate linker scripts in /usr/lib for dynamic |
| 18 | # libs in /lib. This is to fix linking problems when you have |
20 | # libs in /lib. This is to fix linking problems when you have |
| … | |
… | |
| 90 | # Default options for patch |
92 | # Default options for patch |
| 91 | EPATCH_OPTS="" |
93 | EPATCH_OPTS="" |
| 92 | # List of patches not to apply. Not this is only file names, |
94 | # List of patches not to apply. Not this is only file names, |
| 93 | # and not the full path .. |
95 | # and not the full path .. |
| 94 | EPATCH_EXCLUDE="" |
96 | EPATCH_EXCLUDE="" |
|
|
97 | # Change the printed message for a single patch. |
|
|
98 | EPATCH_SINGLE_MSG="" |
| 95 | |
99 | |
| 96 | # This function is for bulk patching, or in theory for just one |
100 | # This function is for bulk patching, or in theory for just one |
| 97 | # or two patches. |
101 | # or two patches. |
| 98 | # |
102 | # |
| 99 | # It should work with .bz2, .gz, .zip and plain text patches. |
103 | # It should work with .bz2, .gz, .zip and plain text patches. |
| … | |
… | |
| 127 | # <azarah@gentoo.org> (10 Nov 2002) |
131 | # <azarah@gentoo.org> (10 Nov 2002) |
| 128 | # |
132 | # |
| 129 | epatch() { |
133 | epatch() { |
| 130 | local PIPE_CMD="" |
134 | local PIPE_CMD="" |
| 131 | local STDERR_TARGET="${T}/$$.out" |
135 | local STDERR_TARGET="${T}/$$.out" |
|
|
136 | local PATCH_TARGET="${T}/$$.patch" |
|
|
137 | local PATCH_SUFFIX="" |
| 132 | local SINGLE_PATCH="no" |
138 | local SINGLE_PATCH="no" |
| 133 | local x="" |
139 | local x="" |
| 134 | |
140 | |
| 135 | if [ "$#" -gt 1 ] |
141 | if [ "$#" -gt 1 ] |
| 136 | then |
142 | then |
| … | |
… | |
| 147 | |
153 | |
| 148 | elif [ -n "$1" -a -d "$1" ] |
154 | elif [ -n "$1" -a -d "$1" ] |
| 149 | then |
155 | then |
| 150 | local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}" |
156 | local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}" |
| 151 | else |
157 | else |
|
|
158 | if [ ! -d ${EPATCH_SOURCE} ] |
|
|
159 | then |
|
|
160 | if [ -n "$1" -a "${EPATCH_SOURCE}" = "${WORKDIR}/patch" ] |
|
|
161 | then |
|
|
162 | EPATCH_SOURCE="$1" |
|
|
163 | fi |
|
|
164 | |
|
|
165 | echo |
|
|
166 | eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:" |
|
|
167 | eerror |
|
|
168 | eerror " ${EPATCH_SOURCE}" |
|
|
169 | echo |
|
|
170 | die "Cannot find \$EPATCH_SOURCE!" |
|
|
171 | fi |
|
|
172 | |
| 152 | local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}" |
173 | local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}" |
| 153 | fi |
174 | fi |
| 154 | |
175 | |
| 155 | case ${EPATCH_SUFFIX##*\.} in |
176 | case ${EPATCH_SUFFIX##*\.} in |
| 156 | bz2) |
177 | bz2) |
| 157 | PIPE_CMD="bzip2 -dc" |
178 | PIPE_CMD="bzip2 -dc" |
|
|
179 | PATCH_SUFFIX="bz2" |
| 158 | ;; |
180 | ;; |
| 159 | gz|Z|z) |
181 | gz|Z|z) |
| 160 | PIPE_CMD="gzip -dc" |
182 | PIPE_CMD="gzip -dc" |
|
|
183 | PATCH_SUFFIX="gz" |
| 161 | ;; |
184 | ;; |
| 162 | ZIP|zip) |
185 | ZIP|zip) |
| 163 | PIPE_CMD="unzip -p" |
186 | PIPE_CMD="unzip -p" |
|
|
187 | PATCH_SUFFIX="zip" |
| 164 | ;; |
188 | ;; |
| 165 | *) |
189 | *) |
| 166 | PIPE_CMD="cat" |
190 | PIPE_CMD="cat" |
|
|
191 | PATCH_SUFFIX="patch" |
| 167 | ;; |
192 | ;; |
| 168 | esac |
193 | esac |
| 169 | |
194 | |
| 170 | if [ "${SINGLE_PATCH}" = "no" ] |
195 | if [ "${SINGLE_PATCH}" = "no" ] |
| 171 | then |
196 | then |
| … | |
… | |
| 176 | # New ARCH dependant patch naming scheme... |
201 | # New ARCH dependant patch naming scheme... |
| 177 | # |
202 | # |
| 178 | # ???_arch_foo.patch |
203 | # ???_arch_foo.patch |
| 179 | # |
204 | # |
| 180 | if [ -f ${x} ] && \ |
205 | if [ -f ${x} ] && \ |
| 181 | [ -n "$1" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ] |
206 | [ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ] |
| 182 | then |
207 | then |
| 183 | local count=0 |
208 | local count=0 |
| 184 | local popts="${EPATCH_OPTS}" |
209 | local popts="${EPATCH_OPTS}" |
| 185 | |
210 | |
| 186 | if [ -n "${EPATCH_EXCLUDE}" ] |
211 | if [ -n "${EPATCH_EXCLUDE}" ] |
| 187 | then |
212 | then |
| 188 | if [ "${EPATCH_EXCLUDE/${x##*/}}" != "${EPATCH_EXCLUDE}" ] |
213 | if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ] |
| 189 | then |
214 | then |
| 190 | continue |
215 | continue |
| 191 | fi |
216 | fi |
| 192 | fi |
217 | fi |
| 193 | |
218 | |
| 194 | if [ "${SINGLE_PATCH}" = "yes" ] |
219 | if [ "${SINGLE_PATCH}" = "yes" ] |
| 195 | then |
220 | then |
|
|
221 | if [ -n "${EPATCH_SINGLE_MSG}" ] |
|
|
222 | then |
|
|
223 | einfo "${EPATCH_SINGLE_MSG}" |
|
|
224 | else |
| 196 | einfo "Applying ${x##*/}..." |
225 | einfo "Applying ${x##*/}..." |
|
|
226 | fi |
| 197 | else |
227 | else |
| 198 | einfo " ${x##*/}..." |
228 | einfo " ${x##*/}..." |
| 199 | fi |
229 | fi |
| 200 | |
230 | |
| 201 | echo "***** ${x##*/} *****" > ${STDERR_TARGET} |
231 | echo "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} |
| 202 | echo >> ${STDERR_TARGET} |
232 | echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} |
| 203 | |
233 | |
| 204 | # Allow for prefix to differ ... im lazy, so shoot me :/ |
234 | # Allow for prefix to differ ... im lazy, so shoot me :/ |
| 205 | while [ "${count}" -lt 5 ] |
235 | while [ "${count}" -lt 5 ] |
| 206 | do |
236 | do |
| 207 | # Generate some useful debug info ... |
237 | # Generate some useful debug info ... |
| 208 | draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET} |
238 | draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} |
| 209 | echo >> ${STDERR_TARGET} |
239 | echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} |
|
|
240 | |
|
|
241 | if [ "${PATCH_SUFFIX}" != "patch" ] |
|
|
242 | then |
|
|
243 | echo -n "PIPE_COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} |
|
|
244 | echo "${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} |
|
|
245 | else |
|
|
246 | PATCH_TARGET="${x}" |
|
|
247 | fi |
| 210 | |
248 | |
| 211 | echo -n "PATCH COMMAND: " >> ${STDERR_TARGET} |
249 | echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} |
| 212 | echo "${PIPE_CMD} ${x} | patch ${popts} -p${count}" >> ${STDERR_TARGET} |
250 | echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} |
| 213 | |
251 | |
| 214 | echo >> ${STDERR_TARGET} |
252 | echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} |
| 215 | draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET} |
253 | draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} |
|
|
254 | |
|
|
255 | if [ "${PATCH_SUFFIX}" != "patch" ] |
|
|
256 | then |
|
|
257 | if ! (${PIPE_CMD} ${x} > ${PATCH_TARGET}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1 |
|
|
258 | then |
|
|
259 | echo |
|
|
260 | eerror "Could not extract patch!" |
|
|
261 | #die "Could not extract patch!" |
|
|
262 | count=5 |
|
|
263 | break |
|
|
264 | fi |
|
|
265 | fi |
| 216 | |
266 | |
| 217 | if eval ${PIPE_CMD} ${x} | patch ${popts} --dry-run -f -p${count} 2>&1 >> ${STDERR_TARGET} |
267 | if (cat ${PATCH_TARGET} | patch ${popts} --dry-run -f -p${count}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1 |
| 218 | then |
268 | then |
| 219 | eval ${PIPE_CMD} ${x} | patch ${popts} -p${count} 2>&1 >> ${STDERR_TARGET} |
269 | draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
|
|
270 | echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
|
|
271 | echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
|
|
272 | echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
|
|
273 | draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
|
|
274 | |
|
|
275 | cat ${PATCH_TARGET} | patch ${popts} -p${count} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1 |
|
|
276 | |
|
|
277 | if [ "$?" -ne 0 ] |
|
|
278 | then |
|
|
279 | cat ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} |
|
|
280 | echo |
|
|
281 | eerror "A dry-run of patch command succeeded, but actually" |
|
|
282 | eerror "applying the patch failed!" |
|
|
283 | #die "Real world sux compared to the dreamworld!" |
|
|
284 | count=5 |
|
|
285 | fi |
|
|
286 | |
|
|
287 | rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
|
|
288 | |
| 220 | break |
289 | break |
| 221 | fi |
290 | fi |
| 222 | |
291 | |
| 223 | count=$((count + 1)) |
292 | count=$((count + 1)) |
| 224 | done |
293 | done |
| 225 | |
294 | |
|
|
295 | if [ "${PATCH_SUFFIX}" != "patch" ] |
|
|
296 | then |
|
|
297 | rm -f ${PATCH_TARGET} |
|
|
298 | fi |
|
|
299 | |
| 226 | if [ "${count}" -eq 5 ] |
300 | if [ "${count}" -eq 5 ] |
| 227 | then |
301 | then |
|
|
302 | echo |
| 228 | eerror "Failed Patch: ${x##*/}!" |
303 | eerror "Failed Patch: ${x##*/}!" |
| 229 | eerror |
304 | eerror |
| 230 | eerror "Include in your bugreport the contents of:" |
305 | eerror "Include in your bugreport the contents of:" |
| 231 | eerror |
306 | eerror |
| 232 | eerror " ${STDERR_TARGET}" |
307 | eerror " ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}" |
| 233 | eerror |
308 | echo |
| 234 | die "Failed Patch: ${x##*/}!" |
309 | die "Failed Patch: ${x##*/}!" |
| 235 | fi |
310 | fi |
| 236 | |
311 | |
|
|
312 | rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} |
|
|
313 | |
| 237 | eend 0 |
314 | eend 0 |
| 238 | fi |
315 | fi |
| 239 | done |
316 | done |
| 240 | if [ "${SINGLE_PATCH}" = "no" ] |
317 | if [ "${SINGLE_PATCH}" = "no" ] |
| 241 | then |
318 | then |
| 242 | einfo "Done with patching" |
319 | einfo "Done with patching" |
| 243 | fi |
320 | fi |
| 244 | } |
321 | } |
| 245 | |
322 | |
|
|
323 | # This function check how many cpu's are present, and then set |
|
|
324 | # -j in MAKEOPTS accordingly. |
|
|
325 | # |
|
|
326 | # Thanks to nall <nall@gentoo.org> for this. |
|
|
327 | # |
|
|
328 | get_number_of_jobs() { |
|
|
329 | local jobs=0 |
|
|
330 | |
|
|
331 | if [ ! -r /proc/cpuinfo ] |
|
|
332 | then |
|
|
333 | return 1 |
|
|
334 | fi |
|
|
335 | |
|
|
336 | # This bit is from H?kan Wessberg <nacka-gentoo@refug.org>, bug #13565. |
|
|
337 | if [ "`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | wc -l`" -gt 0 ] |
|
|
338 | then |
|
|
339 | ADMINOPTS="`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | cut -d= -f2 | sed 's/\"//g'`" |
|
|
340 | ADMINPARAM="`echo ${ADMINOPTS} | gawk '{match($0, /-j *[0-9]*/, opt); print opt[0]}'`" |
|
|
341 | ADMINPARAM="${ADMINPARAM/-j}" |
|
|
342 | fi |
|
|
343 | |
|
|
344 | export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`" |
|
|
345 | |
|
|
346 | if [ "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \ |
|
|
347 | "${ARCH}" = "arm" -o "${ARCH}" = "mips" ] |
|
|
348 | then |
|
|
349 | # these archs will always have "[Pp]rocessor" |
|
|
350 | jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))" |
|
|
351 | |
|
|
352 | elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ] |
|
|
353 | then |
|
|
354 | # sparc always has "ncpus active" |
|
|
355 | jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
|
|
356 | |
|
|
357 | elif [ "${ARCH}" = "alpha" ] |
|
|
358 | then |
|
|
359 | # alpha has "cpus active", but only when compiled with SMP |
|
|
360 | if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ] |
|
|
361 | then |
|
|
362 | jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
|
|
363 | else |
|
|
364 | jobs=2 |
|
|
365 | fi |
|
|
366 | |
|
|
367 | elif [ "${ARCH}" = "ppc" ] |
|
|
368 | then |
|
|
369 | # ppc has "processor", but only when compiled with SMP |
|
|
370 | if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ] |
|
|
371 | then |
|
|
372 | jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))" |
|
|
373 | else |
|
|
374 | jobs=2 |
|
|
375 | fi |
|
|
376 | else |
|
|
377 | jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))" |
|
|
378 | die "Unknown ARCH -- ${ARCH}!" |
|
|
379 | fi |
|
|
380 | |
|
|
381 | # Make sure the number is valid ... |
|
|
382 | if [ "${jobs}" -lt 1 ] |
|
|
383 | then |
|
|
384 | jobs=1 |
|
|
385 | fi |
|
|
386 | |
|
|
387 | if [ -n "${ADMINPARAM}" ] |
|
|
388 | then |
|
|
389 | if [ "${jobs}" -gt "${ADMINPARAM}" ] |
|
|
390 | then |
|
|
391 | einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..." |
|
|
392 | export MAKEOPTS="${MAKEOPTS} -j${ADMINPARAM}" |
|
|
393 | else |
|
|
394 | einfo "Setting make jobs to \"-j${jobs}\" to ensure successful merge..." |
|
|
395 | export MAKEOPTS="${MAKEOPTS} -j${jobs}" |
|
|
396 | fi |
|
|
397 | fi |
|
|
398 | } |
|
|
399 | |
|
|
400 | # Simplify/standardize adding users to the system |
|
|
401 | # vapier@gentoo.org |
|
|
402 | # |
|
|
403 | # enewuser(username, uid, shell, homedir, groups, extra options) |
|
|
404 | # |
|
|
405 | # Default values if you do not specify any: |
|
|
406 | # username: REQUIRED ! |
|
|
407 | # uid: next available (see useradd(8)) |
|
|
408 | # shell: /bin/false |
|
|
409 | # homedir: /dev/null |
|
|
410 | # groups: none |
|
|
411 | # extra: comment of 'added by portage for ${PN}' |
|
|
412 | enewuser() { |
|
|
413 | # get the username |
|
|
414 | local euser="$1"; shift |
|
|
415 | if [ -z "${euser}" ] ; then |
|
|
416 | eerror "No username specified !" |
|
|
417 | die "Cannot call enewuser without a username" |
|
|
418 | fi |
|
|
419 | einfo "Adding user '${euser}' to your system ..." |
|
|
420 | |
|
|
421 | # setup a file for testing usernames/groups |
|
|
422 | local tmpfile="`mktemp -p ${T}`" |
|
|
423 | touch ${tmpfile} |
|
|
424 | chown ${euser} ${tmpfile} >& /dev/null |
|
|
425 | local realuser="`ls -l ${tmpfile} | awk '{print $3}'`" |
|
|
426 | |
|
|
427 | # see if user already exists |
|
|
428 | if [ "${euser}" == "${realuser}" ] ; then |
|
|
429 | einfo "${euser} already exists on your system :)" |
|
|
430 | return 0 |
|
|
431 | fi |
|
|
432 | |
|
|
433 | # options to pass to useradd |
|
|
434 | local opts="" |
|
|
435 | |
|
|
436 | # handle uid |
|
|
437 | local euid="$1"; shift |
|
|
438 | if [ ! -z "${euid}" ] ; then |
|
|
439 | if [ ${euid} -gt 0 ] ; then |
|
|
440 | opts="${opts} -u ${euid}" |
|
|
441 | else |
|
|
442 | eerror "Userid given but is not greater than 0 !" |
|
|
443 | die "${euid} is not a valid UID" |
|
|
444 | fi |
|
|
445 | else |
|
|
446 | euid="next available" |
|
|
447 | fi |
|
|
448 | einfo " - Userid: ${euid}" |
|
|
449 | |
|
|
450 | # handle shell |
|
|
451 | local eshell="$1"; shift |
|
|
452 | if [ ! -z "${eshell}" ] ; then |
|
|
453 | if [ ! -e ${eshell} ] ; then |
|
|
454 | eerror "A shell was specified but it does not exist !" |
|
|
455 | die "${eshell} does not exist" |
|
|
456 | fi |
|
|
457 | else |
|
|
458 | eshell=/bin/false |
|
|
459 | fi |
|
|
460 | einfo " - Shell: ${eshell}" |
|
|
461 | opts="${opts} -s ${eshell}" |
|
|
462 | |
|
|
463 | # handle homedir |
|
|
464 | local ehome="$1"; shift |
|
|
465 | if [ -z "${ehome}" ] ; then |
|
|
466 | ehome=/dev/null |
|
|
467 | fi |
|
|
468 | einfo " - Home: ${ehome}" |
|
|
469 | opts="${opts} -d ${ehome}" |
|
|
470 | |
|
|
471 | # handle groups |
|
|
472 | local egroups="$1"; shift |
|
|
473 | if [ ! -z "${egroups}" ] ; then |
|
|
474 | local realgroup |
|
|
475 | local oldifs="${IFS}" |
|
|
476 | export IFS="," |
|
|
477 | for g in ${egroups} ; do |
|
|
478 | chgrp ${g} ${tmpfile} >& /dev/null |
|
|
479 | realgroup="`ls -l ${tmpfile} | awk '{print $4}'`" |
|
|
480 | if [ "${g}" != "${realgroup}" ] ; then |
|
|
481 | eerror "You must add ${g} to the system first" |
|
|
482 | die "${g} is not a valid GID" |
|
|
483 | fi |
|
|
484 | done |
|
|
485 | export IFS="${oldifs}" |
|
|
486 | opts="${opts} -g ${egroups}" |
|
|
487 | else |
|
|
488 | egroups="(none)" |
|
|
489 | fi |
|
|
490 | einfo " - Groups: ${egroups}" |
|
|
491 | |
|
|
492 | # handle extra and add the user |
|
|
493 | local eextra="$@" |
|
|
494 | local oldsandbox="${oldsandbox}" |
|
|
495 | export SANDBOX_ON="0" |
|
|
496 | if [ -z "${eextra}" ] ; then |
|
|
497 | useradd ${opts} ${euser} \ |
|
|
498 | -c "added by portage for ${PN}" \ |
|
|
499 | || die "enewuser failed" |
|
|
500 | else |
|
|
501 | einfo " - Extra: ${eextra}" |
|
|
502 | useradd ${opts} ${euser} ${eextra} \ |
|
|
503 | || die "enewuser failed" |
|
|
504 | fi |
|
|
505 | export SANDBOX_ON="${oldsandbox}" |
|
|
506 | |
|
|
507 | if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then |
|
|
508 | einfo " - Creating ${ehome} in ${D}" |
|
|
509 | dodir ${ehome} |
|
|
510 | fperms ${euser} ${ehome} |
|
|
511 | fi |
|
|
512 | } |
|
|
513 | |
|
|
514 | # Simplify/standardize adding groups to the system |
|
|
515 | # vapier@gentoo.org |
|
|
516 | # |
|
|
517 | # enewgroup(group, gid) |
|
|
518 | # |
|
|
519 | # Default values if you do not specify any: |
|
|
520 | # groupname: REQUIRED ! |
|
|
521 | # gid: next available (see groupadd(8)) |
|
|
522 | # extra: none |
|
|
523 | enewgroup() { |
|
|
524 | # get the group |
|
|
525 | local egroup="$1"; shift |
|
|
526 | if [ -z "${egroup}" ] ; then |
|
|
527 | eerror "No group specified !" |
|
|
528 | die "Cannot call enewgroup without a group" |
|
|
529 | fi |
|
|
530 | einfo "Adding group '${egroup}' to your system ..." |
|
|
531 | |
|
|
532 | # setup a file for testing groupname |
|
|
533 | local tmpfile="`mktemp -p ${T}`" |
|
|
534 | touch ${tmpfile} |
|
|
535 | chgrp ${egroup} ${tmpfile} >& /dev/null |
|
|
536 | local realgroup="`ls -l ${tmpfile} | awk '{print $4}'`" |
|
|
537 | |
|
|
538 | # see if group already exists |
|
|
539 | if [ "${egroup}" == "${realgroup}" ] ; then |
|
|
540 | einfo "${egroup} already exists on your system :)" |
|
|
541 | return 0 |
|
|
542 | fi |
|
|
543 | |
|
|
544 | # options to pass to useradd |
|
|
545 | local opts="" |
|
|
546 | |
|
|
547 | # handle gid |
|
|
548 | local egid="$1"; shift |
|
|
549 | if [ ! -z "${egid}" ] ; then |
|
|
550 | if [ ${egid} -gt 0 ] ; then |
|
|
551 | opts="${opts} -g ${egid}" |
|
|
552 | else |
|
|
553 | eerror "Groupid given but is not greater than 0 !" |
|
|
554 | die "${egid} is not a valid GID" |
|
|
555 | fi |
|
|
556 | else |
|
|
557 | egid="next available" |
|
|
558 | fi |
|
|
559 | einfo " - Groupid: ${egid}" |
|
|
560 | |
|
|
561 | # handle extra |
|
|
562 | local eextra="$@" |
|
|
563 | opts="${opts} ${eextra}" |
|
|
564 | |
|
|
565 | # add the group |
|
|
566 | local oldsandbox="${oldsandbox}" |
|
|
567 | export SANDBOX_ON="0" |
|
|
568 | groupadd ${opts} ${egroup} || die "enewgroup failed" |
|
|
569 | export SANDBOX_ON="${oldsandbox}" |
|
|
570 | } |
|
|
571 | |
|
|
572 | # Simple script to replace 'dos2unix' binaries |
|
|
573 | # vapier@gentoo.org |
|
|
574 | # |
|
|
575 | # edos2unix(file, <more files>...) |
|
|
576 | edos2unix() { |
|
|
577 | for f in $@ ; do |
|
|
578 | cp ${f} ${T}/ |
|
|
579 | sed 's/\r$//' ${T}/${f}.old > ${f} |
|
|
580 | done |
|
|
581 | } |