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

Diff of /eclass/portability.eclass

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

Revision 1.7 Revision 1.20
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.7 2005/12/14 19:52:22 flameeyes Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v 1.20 2011/11/03 00:26:17 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#
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 # First try `seq`
31 local p=$(type -P seq) 32 local p=$(type -P seq)
33 if [[ -n ${p} ]] ; then
34 "${p}" "$@"
35 return $?
36 fi
32 37
33 case $# in 38 case $# in
34 1) min=1 max=$1 step=1 ;; 39 1) min=1 max=$1 step=1 ;;
35 2) min=$1 max=$2 step=1 ;; 40 2) min=$1 max=$2 step=1 ;;
36 3) min=$1 max=$3 step=$2 ;; 41 3) min=$1 max=$3 step=$2 ;;
37 *) die "seq called with wrong number of arguments" ;; 42 *) die "seq called with wrong number of arguments" ;;
38 esac 43 esac
39 44
45 # Then try `jot`
46 p=$(type -P jot)
40 if [[ -z ${p} ]] ; then 47 if [[ -n ${p} ]] ; then
41 local reps 48 local reps
42 # BSD userland 49 # BSD userland
43 if [[ ${step} != 0 ]]; then 50 if [[ ${step} != 0 ]] ; then
44 reps=$(( ($max-$min) / $step +1 )) 51 reps=$(( (max - min) / step + 1 ))
45 else 52 else
46 reps=0 53 reps=0
47 fi 54 fi
48 55
49 jot $reps $min $max $step 56 jot $reps $min $max $step
50 else 57 return $?
51 "${p}" $min $step $max
52 fi 58 fi
59
60 # Screw it, do the output ourselves
61 while :; do
62 [[ $max < $min && $step > 0 ]] && break
63 [[ $min < $max && $step < 0 ]] && break
64 echo $min
65 : $(( min += step ))
66 done
67 return 0
53} 68}
54 69
55# Gets the linker flag to link to dlopen() function 70# Gets the linker flag to link to dlopen() function
56dlopen_lib() { 71dlopen_lib() {
57 if [[ ${ELIBC} != *BSD ]]; then 72 # - Solaris needs nothing
73 # - Darwin needs nothing
74 # - *BSD needs nothing
75 # - Linux needs -ldl (glibc and uclibc)
76 # - Interix needs -ldl
77 case "${CHOST}" in
78 *-linux-gnu*|*-linux-uclibc|*-interix*)
58 echo "-ldl" 79 echo "-ldl"
59 fi
60}
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 cut -d: -f9 <<<${ent}
74 ;; 80 ;;
75 *)
76 # Linux, NetBSD and OpenBSD use position 6 instead
77 cut -d: -f6 <<<${ent}
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 cut -d: -f10 <<<${ent}
94 ;;
95 *)
96 # Linux, NetBSD and OpenBSD use position 6 instead
97 cut -d: -f7 <<<${ent}
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 81 esac
113} 82}
114 83
115# Gets the name of the BSD-ish make command (pmake from NetBSD) 84# Gets the name of the BSD-ish make command (pmake from NetBSD)
116# 85#
127 echo bsdmake 96 echo bsdmake
128 else 97 else
129 echo pmake 98 echo pmake
130 fi 99 fi
131} 100}
101
102# Portable method of getting mount names and points.
103# Returns as "point node fs options"
104# Remember to convert 040 back to a space.
105get_mounts() {
106 local point= node= fs= opts= foo=
107
108 # Linux has /proc/mounts which should always exist
109 if [[ $(uname -s) == "Linux" ]] ; then
110 while read node point fs opts foo ; do
111 echo "${point} ${node} ${fs} ${opts}"
112 done < /proc/mounts
113 return
114 fi
115
116 # OK, pray we have a -p option that outputs mounts in fstab format
117 # using tabs as the seperator.
118 # Then pray that there are no tabs in the either.
119 # Currently only FreeBSD supports this and the other BSDs will
120 # have to be patched.
121 # Athough the BSD's may support /proc, they do NOT put \040 in place
122 # of the spaces and we should not force a /proc either.
123 local IFS=$'\t'
124 LC_ALL=C mount -p | while read node point fs foo ; do
125 opts=${fs#* }
126 fs=${fs%% *}
127 echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}"
128 done
129}
130
131_dead_portability_user_funcs() { die "if you really need this, please file a bug for base-system@gentoo.org"; }
132egetshell() { _dead_portability_user_funcs; }
133is-login-disabled() { _dead_portability_user_funcs; }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.20

  ViewVC Help
Powered by ViewVC 1.1.20