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

Diff of /eclass/eutils.eclass

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

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

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

  ViewVC Help
Powered by ViewVC 1.1.20