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

Diff of /eclass/eutils.eclass

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

Revision 1.369 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.369 2011/12/02 03:27:37 vapier 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
70# implementation if available. Reuses PORTAGE_ELOG_CLASSES as set by the dev 73# implementation if available. Reuses PORTAGE_ELOG_CLASSES as set by the dev
71# profile. 74# profile.
72if ! declare -F eqawarn >/dev/null ; then 75if ! declare -F eqawarn >/dev/null ; then
73 eqawarn() { 76 eqawarn() {
74 has qa ${PORTAGE_ELOG_CLASSES} && ewarn "$@" 77 has qa ${PORTAGE_ELOG_CLASSES} && ewarn "$@"
78 :
75 } 79 }
76fi 80fi
77 81
78# @FUNCTION: ecvs_clean 82# @FUNCTION: ecvs_clean
79# @USAGE: [list of dirs] 83# @USAGE: [list of dirs]
92# Remove .svn directories recursiveley. Useful when a source tarball contains 96# Remove .svn directories recursiveley. Useful when a source tarball contains
93# internal Subversion directories. Defaults to $PWD. 97# internal Subversion directories. Defaults to $PWD.
94esvn_clean() { 98esvn_clean() {
95 [[ -z $* ]] && set -- . 99 [[ -z $* ]] && set -- .
96 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}]
97} 149}
98 150
99# @FUNCTION: eshopts_push 151# @FUNCTION: eshopts_push
100# @USAGE: [options to `set` or `shopt`] 152# @USAGE: [options to `set` or `shopt`]
101# @DESCRIPTION: 153# @DESCRIPTION:
120# eshopts_pop 172# eshopts_pop
121# @CODE 173# @CODE
122eshopts_push() { 174eshopts_push() {
123 # have to assume __ESHOPTS_SAVE__ isn't screwed with 175 # have to assume __ESHOPTS_SAVE__ isn't screwed with
124 # as a `declare -a` here will reset its value 176 # as a `declare -a` here will reset its value
125 local i=${#__ESHOPTS_SAVE__[@]}
126 if [[ $1 == -[su] ]] ; then 177 if [[ $1 == -[su] ]] ; then
127 __ESHOPTS_SAVE__[$i]=$(shopt -p) 178 estack_push eshopts "$(shopt -p)"
128 [[ $# -eq 0 ]] && return 0 179 [[ $# -eq 0 ]] && return 0
129 shopt "$@" || die "eshopts_push: bad options to shopt: $*" 180 shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*"
130 else 181 else
131 __ESHOPTS_SAVE__[$i]=$- 182 estack_push eshopts $-
132 [[ $# -eq 0 ]] && return 0 183 [[ $# -eq 0 ]] && return 0
133 set "$@" || die "eshopts_push: bad options to set: $*" 184 set "$@" || die "${FUNCNAME}: bad options to set: $*"
134 fi 185 fi
135} 186}
136 187
137# @FUNCTION: eshopts_pop 188# @FUNCTION: eshopts_pop
138# @USAGE: 189# @USAGE:
139# @DESCRIPTION: 190# @DESCRIPTION:
140# Restore the shell options to the state saved with the corresponding 191# Restore the shell options to the state saved with the corresponding
141# eshopts_push call. See that function for more details. 192# eshopts_push call. See that function for more details.
142eshopts_pop() { 193eshopts_pop() {
143 [[ $# -ne 0 ]] && die "eshopts_pop takes no arguments" 194 local s
144 local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 )) 195 estack_pop eshopts s || die "${FUNCNAME}: unbalanced push"
145 [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair"
146 local s=${__ESHOPTS_SAVE__[$i]}
147 unset __ESHOPTS_SAVE__[$i]
148 if [[ ${s} == "shopt -"* ]] ; then 196 if [[ ${s} == "shopt -"* ]] ; then
149 eval "${s}" || die "eshopts_pop: sanity: invalid shopt options: ${s}" 197 eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}"
150 else 198 else
151 set +$- || die "eshopts_pop: sanity: invalid shell settings: $-" 199 set +$- || die "${FUNCNAME}: sanity: invalid shell settings: $-"
152 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}"
153 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}"
154} 222}
155 223
156# @VARIABLE: EPATCH_SOURCE 224# @VARIABLE: EPATCH_SOURCE
157# @DESCRIPTION: 225# @DESCRIPTION:
158# Default directory to search for patches. 226# Default directory to search for patches.
1082 eerror "Unknown filetype \"${filetype}\" ?" 1150 eerror "Unknown filetype \"${filetype}\" ?"
1083 false 1151 false
1084 ;; 1152 ;;
1085 esac 1153 esac
1086 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})" 1154 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
1087}
1088
1089# @FUNCTION: check_license
1090# @USAGE: [license]
1091# @DESCRIPTION:
1092# Display a license for user to accept. If no license is
1093# specified, then ${LICENSE} is used.
1094check_license() {
1095 local lic=$1
1096 if [ -z "${lic}" ] ; then
1097 lic="${PORTDIR}/licenses/${LICENSE}"
1098 else
1099 if [ -e "${PORTDIR}/licenses/${lic}" ] ; then
1100 lic="${PORTDIR}/licenses/${lic}"
1101 elif [ -e "${PWD}/${lic}" ] ; then
1102 lic="${PWD}/${lic}"
1103 elif [ -e "${lic}" ] ; then
1104 lic="${lic}"
1105 fi
1106 fi
1107 local l="`basename ${lic}`"
1108
1109 # here is where we check for the licenses the user already
1110 # accepted ... if we don't find a match, we make the user accept
1111 local alic
1112 eshopts_push -o noglob # so that bash doesn't expand "*"
1113 for alic in ${ACCEPT_LICENSE} ; do
1114 if [[ ${alic} == ${l} ]]; then
1115 eshopts_pop
1116 return 0
1117 fi
1118 done
1119 eshopts_pop
1120 [ ! -f "${lic}" ] && die "Could not find requested license ${lic}"
1121
1122 local licmsg=$(emktemp)
1123 cat <<-EOF > ${licmsg}
1124 **********************************************************
1125 The following license outlines the terms of use of this
1126 package. You MUST accept this license for installation to
1127 continue. When you are done viewing, hit 'q'. If you
1128 CTRL+C out of this, the install will not run!
1129 **********************************************************
1130
1131 EOF
1132 cat ${lic} >> ${licmsg}
1133 ${PAGER:-less} ${licmsg} || die "Could not execute pager (${PAGER}) to accept ${lic}"
1134 einfon "Do you accept the terms of this license (${l})? [yes/no] "
1135 read alic
1136 case ${alic} in
1137 yes|Yes|y|Y)
1138 return 0
1139 ;;
1140 *)
1141 echo;echo;echo
1142 eerror "You MUST accept the license to continue! Exiting!"
1143 die "Failed to accept license"
1144 ;;
1145 esac
1146} 1155}
1147 1156
1148# @FUNCTION: cdrom_get_cds 1157# @FUNCTION: cdrom_get_cds
1149# @USAGE: <file on cd1> [file on cd2] [file on cd3] [...] 1158# @USAGE: <file on cd1> [file on cd2] [file on cd3] [...]
1150# @DESCRIPTION: 1159# @DESCRIPTION:
1682# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix] 1691# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
1683# @DESCRIPTION: 1692# @DESCRIPTION:
1684# 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"),
1685# otherwise echo [false output][false suffix] (defaults to "no"). 1694# otherwise echo [false output][false suffix] (defaults to "no").
1686usex() { 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.369  
changed lines
  Added in v.1.373

  ViewVC Help
Powered by ViewVC 1.1.20