/[gentoo-x86]/eclass/portability.eclass
Gentoo

Diff of /eclass/portability.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 Revision 1.8
1# Copyright 1999-2005 Gentoo Foundation 1# Copyright 1999-2005 Gentoo Foundation
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/portability.eclass,v 1.1 2005/09/18 17:33:44 flameeyes Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v 1.8 2006/03/08 20:08:13 flameeyes Exp $
4# 4#
5# Author: Diego Pettenò <flameeyes@gentoo.org> 5# Author: Diego Pettenò <flameeyes@gentoo.org>
6# 6#
7# This eclass is created to avoid using non-portable GNUisms inside ebuilds 7# This eclass is created to avoid using non-portable GNUisms inside ebuilds
8# 8#
26 26
27# seq min max 27# seq min max
28# 28#
29# compatibility function that mimes seq command if not available 29# compatibility function that mimes seq command if not available
30seq() { 30seq() {
31 local p
32 p=$(type -P seq) 31 local p=$(type -P seq)
33 32
34 case $# in 33 case $# in
35 1) 34 1) min=1 max=$1 step=1 ;;
36 min=1 35 2) min=$1 max=$2 step=1 ;;
37 max=$1 36 3) min=$1 max=$3 step=$2 ;;
38 step=1 37 *) die "seq called with wrong number of arguments" ;;
39 ;;
40 2)
41 min=$1
42 max=$2
43 step=1
44 ;;
45 3)
46 min=$1
47 max=$3
48 step=$2
49 ;;
50 *)
51 die "seq called with wrong parameters number"
52 esac 38 esac
53 39
54 if [[ -z "${p}" ]]; then 40 if [[ -z ${p} ]] ; then
55 local reps 41 local reps
56 # BSD userland 42 # BSD userland
57 if [[ ${step} != 0 ]]; then 43 if [[ ${step} != 0 ]]; then
58 reps=$(( ($max-$min) / $step +1 )) 44 reps=$(( ($max-$min) / $step +1 ))
59 else 45 else
71 if [[ ${ELIBC} != *BSD ]]; then 57 if [[ ${ELIBC} != *BSD ]]; then
72 echo "-ldl" 58 echo "-ldl"
73 fi 59 fi
74} 60}
75 61
62# Gets the home directory for the specified user
63# it's a wrap around egetent as the position of the home directory in the line
64# varies depending on the os used.
65#
66# To use that, inherit eutils, not portability!
67egethome() {
68 ent=$(egetent passwd $1)
69
70 case ${CHOST} in
71 *-darwin*|*-freebsd*|*-dragonfly*)
72 # Darwin, OSX, FreeBSD and DragonFly use position 9 to store homedir
73 echo ${ent} | cut -d: -f9
74 ;;
75 *)
76 # Linux, NetBSD and OpenBSD use position 6 instead
77 echo ${ent} | cut -d: -f6
78 ;;
79 esac
80}
81
82# Gets the shell for the specified user
83# it's a wrap around egetent as the position of the home directory in the line
84# varies depending on the os used.
85#
86# To use that, inherit eutils, not portability!
87egetshell() {
88 ent=$(egetent passwd "$1")
89
90 case ${CHOST} in
91 *-darwin*|*-freebsd*|*-dragonfly*)
92 # Darwin, OSX, FreeBSD and DragonFly use position 9 to store homedir
93 echo ${ent} | cut -d: -f10
94 ;;
95 *)
96 # Linux, NetBSD and OpenBSD use position 6 instead
97 echo ${ent} cut -d: -f7
98 ;;
99 esac
100}
101
102# Returns true if specified user has a shell that precludes logins
103# on whichever operating system.
104is-login-disabled() {
105 shell=$(egetshell "$1")
106
107 case ${shell} in
108 /bin/false|/usr/bin/false|/sbin/nologin|/usr/sbin/nologin)
109 return 0 ;;
110 *)
111 return 1 ;;
112 esac
113}
114
115# Gets the name of the BSD-ish make command (pmake from NetBSD)
116#
117# This will return make (provided by system packages) for BSD userlands,
118# or bsdmake for Darwin userlands and pmake for the rest of userlands,
119# both of which are provided by sys-devel/pmake package.
120#
121# Note: the bsdmake for Darwin userland is with compatibility with MacOSX
122# default name.
123get_bmake() {
124 if [[ ${USERLAND} == *BSD ]]; then
125 echo make
126 elif [[ ${USERLAND} == "Darwin" ]]; then
127 echo bsdmake
128 else
129 echo pmake
130 fi
131}

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.20