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

Diff of /eclass/portability.eclass

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

Revision 1.17 Revision 1.24
1# Copyright 1999-2005 Gentoo Foundation 1# Copyright 1999-2011 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.17 2010/09/24 14:29:49 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v 1.24 2012/01/04 05:57:19 vapier 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#
9# NB: If you add anything, please comment it! 9# NB: If you add anything, please comment it!
10 10
11if [[ ${___ECLASS_ONCE_PORTABILITY} != "recur -_+^+_- spank" ]] ; then
12___ECLASS_ONCE_PORTABILITY="recur -_+^+_- spank"
13
11# treecopy orig1 orig2 orig3 .... dest 14# treecopy orig1 orig2 orig3 .... dest
12# 15#
13# mimic cp --parents copy, but working on BSD userland as well 16# mimic cp --parents copy, but working on BSD userland as well
14treecopy() { 17treecopy() {
15 dest=${!#} 18 local dest=${!#}
16 files_count=$# 19 local files_count=$#
17 20
18 while(( $# > 1 )); do 21 while (( $# > 1 )); do
19 dirstruct=$(dirname "$1") 22 local dirstruct=$(dirname "$1")
20 mkdir -p "${dest}/${dirstruct}" 23 mkdir -p "${dest}/${dirstruct}"
21 cp -pPR "$1" "${dest}/${dirstruct}" 24 cp -pPR "$1" "${dest}/${dirstruct}"
22 25
23 shift 26 shift
24 done 27 done
33 if [[ -n ${p} ]] ; then 36 if [[ -n ${p} ]] ; then
34 "${p}" "$@" 37 "${p}" "$@"
35 return $? 38 return $?
36 fi 39 fi
37 40
41 local min max step
38 case $# in 42 case $# in
39 1) min=1 max=$1 step=1 ;; 43 1) min=1 max=$1 step=1 ;;
40 2) min=$1 max=$2 step=1 ;; 44 2) min=$1 max=$2 step=1 ;;
41 3) min=$1 max=$3 step=$2 ;; 45 3) min=$1 max=$3 step=$2 ;;
42 *) die "seq called with wrong number of arguments" ;; 46 *) die "seq called with wrong number of arguments" ;;
76 # - Interix needs -ldl 80 # - Interix needs -ldl
77 case "${CHOST}" in 81 case "${CHOST}" in
78 *-linux-gnu*|*-linux-uclibc|*-interix*) 82 *-linux-gnu*|*-linux-uclibc|*-interix*)
79 echo "-ldl" 83 echo "-ldl"
80 ;; 84 ;;
81 esac
82}
83
84# Gets the home directory for the specified user
85# it's a wrap around egetent as the position of the home directory in the line
86# varies depending on the os used.
87#
88# To use that, inherit eutils, not portability!
89egethome() {
90 ent=$(egetent passwd $1)
91
92 case ${CHOST} in
93 *-darwin*|*-freebsd*|*-dragonfly*)
94 # Darwin, OSX, FreeBSD and DragonFly use position 9 to store homedir
95 echo ${ent} | cut -d: -f9
96 ;;
97 *)
98 # Linux, NetBSD and OpenBSD use position 6 instead
99 echo ${ent} | cut -d: -f6
100 ;;
101 esac
102}
103
104# Gets the shell for the specified user
105# it's a wrap around egetent as the position of the home directory in the line
106# varies depending on the os used.
107#
108# To use that, inherit eutils, not portability!
109egetshell() {
110 ent=$(egetent passwd "$1")
111
112 case ${CHOST} in
113 *-darwin*|*-freebsd*|*-dragonfly*)
114 # Darwin, OSX, FreeBSD and DragonFly use position 9 to store homedir
115 echo ${ent} | cut -d: -f10
116 ;;
117 *)
118 # Linux, NetBSD and OpenBSD use position 6 instead
119 echo ${ent} cut -d: -f7
120 ;;
121 esac
122}
123
124# Returns true if specified user has a shell that precludes logins
125# on whichever operating system.
126is-login-disabled() {
127 shell=$(egetshell "$1")
128
129 case ${shell} in
130 /bin/false|/usr/bin/false|/sbin/nologin|/usr/sbin/nologin)
131 return 0 ;;
132 *)
133 return 1 ;;
134 esac 85 esac
135} 86}
136 87
137# Gets the name of the BSD-ish make command (pmake from NetBSD) 88# Gets the name of the BSD-ish make command (pmake from NetBSD)
138# 89#
179 fs=${fs%% *} 130 fs=${fs%% *}
180 echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}" 131 echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}"
181 done 132 done
182} 133}
183 134
135_dead_portability_user_funcs() { die "if you really need this, please file a bug for base-system@gentoo.org"; }
136is-login-disabled() { _dead_portability_user_funcs; }
137
138fi

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.24

  ViewVC Help
Powered by ViewVC 1.1.20