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

Diff of /eclass/eutils.eclass

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

Revision 1.370 Revision 1.373
1# Copyright 1999-2011 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/eutils.eclass,v 1.370 2011/12/02 10:22:41 ferringb Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.373 2011/12/16 23:38:41 vapier Exp $
4 4
5# @ECLASS: eutils.eclass 5# @ECLASS: eutils.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# base-system@gentoo.org 7# base-system@gentoo.org
8# @BLURB: many extra (but common) functions that are used in ebuilds 8# @BLURB: many extra (but common) functions that are used in ebuilds
12# are not required in all ebuilds but enough utilize them to have a common 12# are not required in all ebuilds but enough utilize them to have a common
13# home rather than having multiple ebuilds implementing the same thing. 13# home rather than having multiple ebuilds implementing the same thing.
14# 14#
15# Due to the nature of this eclass, some functions may have maintainers 15# Due to the nature of this eclass, some functions may have maintainers
16# different from the overall eclass! 16# different from the overall eclass!
17
18if [[ ${___ECLASS_ONCE_EUTILS} != "recur -_+^+_- spank" ]] ; then
19___ECLASS_ONCE_EUTILS="recur -_+^+_- spank"
17 20
18inherit multilib portability user 21inherit multilib portability user
19 22
20DESCRIPTION="Based on the ${ECLASS} eclass" 23DESCRIPTION="Based on the ${ECLASS} eclass"
21 24
93# Remove .svn directories recursiveley. Useful when a source tarball contains 96# Remove .svn directories recursiveley. Useful when a source tarball contains
94# internal Subversion directories. Defaults to $PWD. 97# internal Subversion directories. Defaults to $PWD.
95esvn_clean() { 98esvn_clean() {
96 [[ -z $* ]] && set -- . 99 [[ -z $* ]] && set -- .
97 find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf 100 find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf
101}
102
103# @FUNCTION: estack_push
104# @USAGE: <stack> [items to push]
105# @DESCRIPTION:
106# Push any number of items onto the specified stack. Pick a name that
107# is a valid variable (i.e. stick to alphanumerics), and push as many
108# items as you like onto the stack at once.
109#
110# The following code snippet will echo 5, then 4, then 3, then ...
111# @CODE
112# estack_push mystack 1 2 3 4 5
113# while estack_pop mystack i ; do
114# echo "${i}"
115# done
116# @CODE
117estack_push() {
118 [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments"
119 local stack_name="__ESTACK_$1__" ; shift
120 eval ${stack_name}+=\( \"\$@\" \)
121}
122
123# @FUNCTION: estack_pop
124# @USAGE: <stack> [variable]
125# @DESCRIPTION:
126# Pop a single item off the specified stack. If a variable is specified,
127# the popped item is stored there. If no more items are available, return
128# 1, else return 0. See estack_push for more info.
129estack_pop() {
130 [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments"
131
132 # We use the fugly __estack_xxx var names to avoid collision with
133 # passing back the return value. If we used "local i" and the
134 # caller ran `estack_pop ... i`, we'd end up setting the local
135 # copy of "i" rather than the caller's copy. The __estack_xxx
136 # garbage is preferable to using $1/$2 everywhere as that is a
137 # bit harder to read.
138 local __estack_name="__ESTACK_$1__" ; shift
139 local __estack_retvar=$1 ; shift
140 eval local __estack_i=\${#${__estack_name}[@]}
141 # Don't warn -- let the caller interpret this as a failure
142 # or as normal behavior (akin to `shift`)
143 [[ $(( --__estack_i )) -eq -1 ]] && return 1
144
145 if [[ -n ${__estack_retvar} ]] ; then
146 eval ${__estack_retvar}=\"\${${__estack_name}[${__estack_i}]}\"
147 fi
148 eval unset ${__estack_name}[${__estack_i}]
98} 149}
99 150
100# @FUNCTION: eshopts_push 151# @FUNCTION: eshopts_push
101# @USAGE: [options to `set` or `shopt`] 152# @USAGE: [options to `set` or `shopt`]
102# @DESCRIPTION: 153# @DESCRIPTION:
121# eshopts_pop 172# eshopts_pop
122# @CODE 173# @CODE
123eshopts_push() { 174eshopts_push() {
124 # have to assume __ESHOPTS_SAVE__ isn't screwed with 175 # have to assume __ESHOPTS_SAVE__ isn't screwed with
125 # as a `declare -a` here will reset its value 176 # as a `declare -a` here will reset its value
126 local i=${#__ESHOPTS_SAVE__[@]}
127 if [[ $1 == -[su] ]] ; then 177 if [[ $1 == -[su] ]] ; then
128 __ESHOPTS_SAVE__[$i]=$(shopt -p) 178 estack_push eshopts "$(shopt -p)"
129 [[ $# -eq 0 ]] && return 0 179 [[ $# -eq 0 ]] && return 0
130 shopt "$@" || die "eshopts_push: bad options to shopt: $*" 180 shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*"
131 else 181 else
132 __ESHOPTS_SAVE__[$i]=$- 182 estack_push eshopts $-
133 [[ $# -eq 0 ]] && return 0 183 [[ $# -eq 0 ]] && return 0
134 set "$@" || die "eshopts_push: bad options to set: $*" 184 set "$@" || die "${FUNCNAME}: bad options to set: $*"
135 fi 185 fi
136} 186}
137 187
138# @FUNCTION: eshopts_pop 188# @FUNCTION: eshopts_pop
139# @USAGE: 189# @USAGE:
140# @DESCRIPTION: 190# @DESCRIPTION:
141# Restore the shell options to the state saved with the corresponding 191# Restore the shell options to the state saved with the corresponding
142# eshopts_push call. See that function for more details. 192# eshopts_push call. See that function for more details.
143eshopts_pop() { 193eshopts_pop() {
144 [[ $# -ne 0 ]] && die "eshopts_pop takes no arguments" 194 local s
145 local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 )) 195 estack_pop eshopts s || die "${FUNCNAME}: unbalanced push"
146 [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair"
147 local s=${__ESHOPTS_SAVE__[$i]}
148 unset __ESHOPTS_SAVE__[$i]
149 if [[ ${s} == "shopt -"* ]] ; then 196 if [[ ${s} == "shopt -"* ]] ; then
150 eval "${s}" || die "eshopts_pop: sanity: invalid shopt options: ${s}" 197 eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}"
151 else 198 else
152 set +$- || die "eshopts_pop: sanity: invalid shell settings: $-" 199 set +$- || die "${FUNCNAME}: sanity: invalid shell settings: $-"
153 set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}" 200 set -${s} || die "${FUNCNAME}: sanity: unable to restore saved shell settings: ${s}"
154 fi 201 fi
202}
203
204# @FUNCTION: eumask_push
205# @USAGE: <new umask>
206# @DESCRIPTION:
207# Set the umask to the new value specified while saving the previous
208# value onto a stack. Useful for temporarily changing the umask.
209eumask_push() {
210 estack_push eumask "$(umask)"
211 umask "$@" || die "${FUNCNAME}: bad options to umask: $*"
212}
213
214# @FUNCTION: eumask_pop
215# @USAGE:
216# @DESCRIPTION:
217# Restore the previous umask state.
218eumask_pop() {
219 local s
220 estack_pop eumask s || die "${FUNCNAME}: unbalanced push"
221 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
155} 222}
156 223
157# @VARIABLE: EPATCH_SOURCE 224# @VARIABLE: EPATCH_SOURCE
158# @DESCRIPTION: 225# @DESCRIPTION:
159# Default directory to search for patches. 226# Default directory to search for patches.
1083 eerror "Unknown filetype \"${filetype}\" ?" 1150 eerror "Unknown filetype \"${filetype}\" ?"
1084 false 1151 false
1085 ;; 1152 ;;
1086 esac 1153 esac
1087 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})" 1154 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
1088}
1089
1090# @FUNCTION: check_license
1091# @USAGE: [license]
1092# @DESCRIPTION:
1093# Display a license for user to accept. If no license is
1094# specified, then ${LICENSE} is used.
1095check_license() {
1096 local lic=$1
1097 if [ -z "${lic}" ] ; then
1098 lic="${PORTDIR}/licenses/${LICENSE}"
1099 else
1100 if [ -e "${PORTDIR}/licenses/${lic}" ] ; then
1101 lic="${PORTDIR}/licenses/${lic}"
1102 elif [ -e "${PWD}/${lic}" ] ; then
1103 lic="${PWD}/${lic}"
1104 elif [ -e "${lic}" ] ; then
1105 lic="${lic}"
1106 fi
1107 fi
1108 local l="`basename ${lic}`"
1109
1110 # here is where we check for the licenses the user already
1111 # accepted ... if we don't find a match, we make the user accept
1112 local alic
1113 eshopts_push -o noglob # so that bash doesn't expand "*"
1114 for alic in ${ACCEPT_LICENSE} ; do
1115 if [[ ${alic} == ${l} ]]; then
1116 eshopts_pop
1117 return 0
1118 fi
1119 done
1120 eshopts_pop
1121 [ ! -f "${lic}" ] && die "Could not find requested license ${lic}"
1122
1123 local licmsg=$(emktemp)
1124 cat <<-EOF > ${licmsg}
1125 **********************************************************
1126 The following license outlines the terms of use of this
1127 package. You MUST accept this license for installation to
1128 continue. When you are done viewing, hit 'q'. If you
1129 CTRL+C out of this, the install will not run!
1130 **********************************************************
1131
1132 EOF
1133 cat ${lic} >> ${licmsg}
1134 ${PAGER:-less} ${licmsg} || die "Could not execute pager (${PAGER}) to accept ${lic}"
1135 einfon "Do you accept the terms of this license (${l})? [yes/no] "
1136 read alic
1137 case ${alic} in
1138 yes|Yes|y|Y)
1139 return 0
1140 ;;
1141 *)
1142 echo;echo;echo
1143 eerror "You MUST accept the license to continue! Exiting!"
1144 die "Failed to accept license"
1145 ;;
1146 esac
1147} 1155}
1148 1156
1149# @FUNCTION: cdrom_get_cds 1157# @FUNCTION: cdrom_get_cds
1150# @USAGE: <file on cd1> [file on cd2] [file on cd3] [...] 1158# @USAGE: <file on cd1> [file on cd2] [file on cd3] [...]
1151# @DESCRIPTION: 1159# @DESCRIPTION:
1683# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix] 1691# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
1684# @DESCRIPTION: 1692# @DESCRIPTION:
1685# If USE flag is set, echo [true output][true suffix] (defaults to "yes"), 1693# If USE flag is set, echo [true output][true suffix] (defaults to "yes"),
1686# otherwise echo [false output][false suffix] (defaults to "no"). 1694# otherwise echo [false output][false suffix] (defaults to "no").
1687usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 1695usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1696
1697check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; }
1698
1699fi

Legend:
Removed from v.1.370  
changed lines
  Added in v.1.373

  ViewVC Help
Powered by ViewVC 1.1.20