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

Diff of /eclass/eutils.eclass

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

Revision 1.366 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.366 2011/09/30 16:51:01 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
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 17
18if [[ ${___ECLASS_ONCE_EUTILS} != "recur -_+^+_- spank" ]] ; then
19___ECLASS_ONCE_EUTILS="recur -_+^+_- spank"
20
18inherit multilib portability 21inherit multilib portability user
19 22
20DESCRIPTION="Based on the ${ECLASS} eclass" 23DESCRIPTION="Based on the ${ECLASS} eclass"
21 24
22if has "${EAPI:-0}" 0 1 2; then 25if has "${EAPI:-0}" 0 1 2; then
23 26
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.
335 local STDERR_TARGET="${T}/${patchname}.out" 403 local STDERR_TARGET="${T}/${patchname}.out"
336 if [[ -e ${STDERR_TARGET} ]] ; then 404 if [[ -e ${STDERR_TARGET} ]] ; then
337 STDERR_TARGET="${T}/${patchname}-$$.out" 405 STDERR_TARGET="${T}/${patchname}-$$.out"
338 fi 406 fi
339 407
340 printf "***** %s *****\n\n" "${patchname}" > "${STDERR_TARGET}" 408 printf "***** %s *****\nPWD: %s\n\n" "${patchname}" "${PWD}" > "${STDERR_TARGET}"
341 409
342 # Decompress the patch if need be 410 # Decompress the patch if need be
343 local count=0 411 local count=0
344 local PATCH_TARGET 412 local PATCH_TARGET
345 if [[ -n ${PIPE_CMD} ]] ; then 413 if [[ -n ${PIPE_CMD} ]] ; then
527 TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX 595 TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX
528 else 596 else
529 TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX 597 TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX
530 fi 598 fi
531 fi 599 fi
532}
533
534# @FUNCTION: egetent
535# @USAGE: <database> <key>
536# @MAINTAINER:
537# base-system@gentoo.org (Linux)
538# Joe Jezak <josejx@gmail.com> (OS X)
539# usata@gentoo.org (OS X)
540# Aaron Walker <ka0ttic@gentoo.org> (FreeBSD)
541# @DESCRIPTION:
542# Small wrapper for getent (Linux),
543# nidump (< Mac OS X 10.5), dscl (Mac OS X 10.5),
544# and pw (FreeBSD) used in enewuser()/enewgroup()
545egetent() {
546 case ${CHOST} in
547 *-darwin[678])
548 case "$2" in
549 *[!0-9]*) # Non numeric
550 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2\$/) {print \$0;exit;} }"
551 ;;
552 *) # Numeric
553 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
554 ;;
555 esac
556 ;;
557 *-darwin*)
558 local mytype=$1
559 [[ "passwd" == $mytype ]] && mytype="Users"
560 [[ "group" == $mytype ]] && mytype="Groups"
561 case "$2" in
562 *[!0-9]*) # Non numeric
563 dscl . -read /$mytype/$2 2>/dev/null |grep RecordName
564 ;;
565 *) # Numeric
566 local mykey="UniqueID"
567 [[ $mytype == "Groups" ]] && mykey="PrimaryGroupID"
568 dscl . -search /$mytype $mykey $2 2>/dev/null
569 ;;
570 esac
571 ;;
572 *-freebsd*|*-dragonfly*)
573 local opts action="user"
574 [[ $1 == "passwd" ]] || action="group"
575
576 # lookup by uid/gid
577 if [[ $2 == [[:digit:]]* ]] ; then
578 [[ ${action} == "user" ]] && opts="-u" || opts="-g"
579 fi
580
581 pw show ${action} ${opts} "$2" -q
582 ;;
583 *-netbsd*|*-openbsd*)
584 grep "$2:\*:" /etc/$1
585 ;;
586 *)
587 type -p nscd >& /dev/null && nscd -i "$1"
588 getent "$1" "$2"
589 ;;
590 esac
591}
592
593# @FUNCTION: enewuser
594# @USAGE: <user> [uid] [shell] [homedir] [groups] [params]
595# @DESCRIPTION:
596# Same as enewgroup, you are not required to understand how to properly add
597# a user to the system. The only required parameter is the username.
598# Default uid is (pass -1 for this) next available, default shell is
599# /bin/false, default homedir is /dev/null, there are no default groups,
600# and default params sets the comment as 'added by portage for ${PN}'.
601enewuser() {
602 case ${EBUILD_PHASE} in
603 unpack|compile|test|install)
604 eerror "'enewuser()' called from '${EBUILD_PHASE}()' which is not a pkg_* function."
605 eerror "Package fails at QA and at life. Please file a bug."
606 die "Bad package! enewuser is only for use in pkg_* functions!"
607 esac
608
609 # get the username
610 local euser=$1; shift
611 if [[ -z ${euser} ]] ; then
612 eerror "No username specified !"
613 die "Cannot call enewuser without a username"
614 fi
615
616 # lets see if the username already exists
617 if [[ -n $(egetent passwd "${euser}") ]] ; then
618 return 0
619 fi
620 einfo "Adding user '${euser}' to your system ..."
621
622 # options to pass to useradd
623 local opts=
624
625 # handle uid
626 local euid=$1; shift
627 if [[ -n ${euid} && ${euid} != -1 ]] ; then
628 if [[ ${euid} -gt 0 ]] ; then
629 if [[ -n $(egetent passwd ${euid}) ]] ; then
630 euid="next"
631 fi
632 else
633 eerror "Userid given but is not greater than 0 !"
634 die "${euid} is not a valid UID"
635 fi
636 else
637 euid="next"
638 fi
639 if [[ ${euid} == "next" ]] ; then
640 for ((euid = 101; euid <= 999; euid++)); do
641 [[ -z $(egetent passwd ${euid}) ]] && break
642 done
643 fi
644 opts="${opts} -u ${euid}"
645 einfo " - Userid: ${euid}"
646
647 # handle shell
648 local eshell=$1; shift
649 if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]] ; then
650 if [[ ! -e ${ROOT}${eshell} ]] ; then
651 eerror "A shell was specified but it does not exist !"
652 die "${eshell} does not exist in ${ROOT}"
653 fi
654 if [[ ${eshell} == */false || ${eshell} == */nologin ]] ; then
655 eerror "Do not specify ${eshell} yourself, use -1"
656 die "Pass '-1' as the shell parameter"
657 fi
658 else
659 for shell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null ; do
660 [[ -x ${ROOT}${shell} ]] && break
661 done
662
663 if [[ ${shell} == "/dev/null" ]] ; then
664 eerror "Unable to identify the shell to use, proceeding with userland default."
665 case ${USERLAND} in
666 GNU) shell="/bin/false" ;;
667 BSD) shell="/sbin/nologin" ;;
668 Darwin) shell="/usr/sbin/nologin" ;;
669 *) die "Unable to identify the default shell for userland ${USERLAND}"
670 esac
671 fi
672
673 eshell=${shell}
674 fi
675 einfo " - Shell: ${eshell}"
676 opts="${opts} -s ${eshell}"
677
678 # handle homedir
679 local ehome=$1; shift
680 if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]] ; then
681 ehome="/dev/null"
682 fi
683 einfo " - Home: ${ehome}"
684 opts="${opts} -d ${ehome}"
685
686 # handle groups
687 local egroups=$1; shift
688 if [[ ! -z ${egroups} ]] ; then
689 local oldifs=${IFS}
690 local defgroup="" exgroups=""
691
692 export IFS=","
693 for g in ${egroups} ; do
694 export IFS=${oldifs}
695 if [[ -z $(egetent group "${g}") ]] ; then
696 eerror "You must add group ${g} to the system first"
697 die "${g} is not a valid GID"
698 fi
699 if [[ -z ${defgroup} ]] ; then
700 defgroup=${g}
701 else
702 exgroups="${exgroups},${g}"
703 fi
704 export IFS=","
705 done
706 export IFS=${oldifs}
707
708 opts="${opts} -g ${defgroup}"
709 if [[ ! -z ${exgroups} ]] ; then
710 opts="${opts} -G ${exgroups:1}"
711 fi
712 else
713 egroups="(none)"
714 fi
715 einfo " - Groups: ${egroups}"
716
717 # handle extra and add the user
718 local oldsandbox=${SANDBOX_ON}
719 export SANDBOX_ON="0"
720 case ${CHOST} in
721 *-darwin*)
722 ### Make the user
723 if [[ -z $@ ]] ; then
724 dscl . create /users/${euser} uid ${euid}
725 dscl . create /users/${euser} shell ${eshell}
726 dscl . create /users/${euser} home ${ehome}
727 dscl . create /users/${euser} realname "added by portage for ${PN}"
728 ### Add the user to the groups specified
729 local oldifs=${IFS}
730 export IFS=","
731 for g in ${egroups} ; do
732 dscl . merge /groups/${g} users ${euser}
733 done
734 export IFS=${oldifs}
735 else
736 einfo "Extra options are not supported on Darwin yet"
737 einfo "Please report the ebuild along with the info below"
738 einfo "eextra: $@"
739 die "Required function missing"
740 fi
741 ;;
742 *-freebsd*|*-dragonfly*)
743 if [[ -z $@ ]] ; then
744 pw useradd ${euser} ${opts} \
745 -c "added by portage for ${PN}" \
746 die "enewuser failed"
747 else
748 einfo " - Extra: $@"
749 pw useradd ${euser} ${opts} \
750 "$@" || die "enewuser failed"
751 fi
752 ;;
753
754 *-netbsd*)
755 if [[ -z $@ ]] ; then
756 useradd ${opts} ${euser} || die "enewuser failed"
757 else
758 einfo " - Extra: $@"
759 useradd ${opts} ${euser} "$@" || die "enewuser failed"
760 fi
761 ;;
762
763 *-openbsd*)
764 if [[ -z $@ ]] ; then
765 useradd -u ${euid} -s ${eshell} \
766 -d ${ehome} -c "Added by portage for ${PN}" \
767 -g ${egroups} ${euser} || die "enewuser failed"
768 else
769 einfo " - Extra: $@"
770 useradd -u ${euid} -s ${eshell} \
771 -d ${ehome} -c "Added by portage for ${PN}" \
772 -g ${egroups} ${euser} "$@" || die "enewuser failed"
773 fi
774 ;;
775
776 *)
777 if [[ -z $@ ]] ; then
778 useradd -r ${opts} \
779 -c "added by portage for ${PN}" \
780 ${euser} \
781 || die "enewuser failed"
782 else
783 einfo " - Extra: $@"
784 useradd -r ${opts} "$@" \
785 ${euser} \
786 || die "enewuser failed"
787 fi
788 ;;
789 esac
790
791 if [[ ! -e ${ROOT}/${ehome} ]] ; then
792 einfo " - Creating ${ehome} in ${ROOT}"
793 mkdir -p "${ROOT}/${ehome}"
794 chown ${euser} "${ROOT}/${ehome}"
795 chmod 755 "${ROOT}/${ehome}"
796 fi
797
798 export SANDBOX_ON=${oldsandbox}
799}
800
801# @FUNCTION: enewgroup
802# @USAGE: <group> [gid]
803# @DESCRIPTION:
804# This function does not require you to understand how to properly add a
805# group to the system. Just give it a group name to add and enewgroup will
806# do the rest. You may specify the gid for the group or allow the group to
807# allocate the next available one.
808enewgroup() {
809 case ${EBUILD_PHASE} in
810 unpack|compile|test|install)
811 eerror "'enewgroup()' called from '${EBUILD_PHASE}()' which is not a pkg_* function."
812 eerror "Package fails at QA and at life. Please file a bug."
813 die "Bad package! enewgroup is only for use in pkg_* functions!"
814 esac
815
816 # get the group
817 local egroup="$1"; shift
818 if [ -z "${egroup}" ]
819 then
820 eerror "No group specified !"
821 die "Cannot call enewgroup without a group"
822 fi
823
824 # see if group already exists
825 if [[ -n $(egetent group "${egroup}") ]]; then
826 return 0
827 fi
828 einfo "Adding group '${egroup}' to your system ..."
829
830 # options to pass to useradd
831 local opts=
832
833 # handle gid
834 local egid="$1"; shift
835 if [ ! -z "${egid}" ]
836 then
837 if [ "${egid}" -gt 0 ]
838 then
839 if [ -z "`egetent group ${egid}`" ]
840 then
841 if [[ "${CHOST}" == *-darwin* ]]; then
842 opts="${opts} ${egid}"
843 else
844 opts="${opts} -g ${egid}"
845 fi
846 else
847 egid="next available; requested gid taken"
848 fi
849 else
850 eerror "Groupid given but is not greater than 0 !"
851 die "${egid} is not a valid GID"
852 fi
853 else
854 egid="next available"
855 fi
856 einfo " - Groupid: ${egid}"
857
858 # handle extra
859 local eextra="$@"
860 opts="${opts} ${eextra}"
861
862 # add the group
863 local oldsandbox="${SANDBOX_ON}"
864 export SANDBOX_ON="0"
865 case ${CHOST} in
866 *-darwin*)
867 if [ ! -z "${eextra}" ];
868 then
869 einfo "Extra options are not supported on Darwin/OS X yet"
870 einfo "Please report the ebuild along with the info below"
871 einfo "eextra: ${eextra}"
872 die "Required function missing"
873 fi
874
875 # If we need the next available
876 case ${egid} in
877 *[!0-9]*) # Non numeric
878 for ((egid = 101; egid <= 999; egid++)); do
879 [[ -z $(egetent group ${egid}) ]] && break
880 done
881 esac
882 dscl . create /groups/${egroup} gid ${egid}
883 dscl . create /groups/${egroup} passwd '*'
884 ;;
885
886 *-freebsd*|*-dragonfly*)
887 case ${egid} in
888 *[!0-9]*) # Non numeric
889 for ((egid = 101; egid <= 999; egid++)); do
890 [[ -z $(egetent group ${egid}) ]] && break
891 done
892 esac
893 pw groupadd ${egroup} -g ${egid} || die "enewgroup failed"
894 ;;
895
896 *-netbsd*)
897 case ${egid} in
898 *[!0-9]*) # Non numeric
899 for ((egid = 101; egid <= 999; egid++)); do
900 [[ -z $(egetent group ${egid}) ]] && break
901 done
902 esac
903 groupadd -g ${egid} ${egroup} || die "enewgroup failed"
904 ;;
905
906 *)
907 # We specify -r so that we get a GID in the system range from login.defs
908 groupadd -r ${opts} ${egroup} || die "enewgroup failed"
909 ;;
910 esac
911 export SANDBOX_ON="${oldsandbox}"
912} 600}
913 601
914# @FUNCTION: edos2unix 602# @FUNCTION: edos2unix
915# @USAGE: <file> [more files ...] 603# @USAGE: <file> [more files ...]
916# @DESCRIPTION: 604# @DESCRIPTION:
1462 eerror "Unknown filetype \"${filetype}\" ?" 1150 eerror "Unknown filetype \"${filetype}\" ?"
1463 false 1151 false
1464 ;; 1152 ;;
1465 esac 1153 esac
1466 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})" 1154 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
1467}
1468
1469# @FUNCTION: check_license
1470# @USAGE: [license]
1471# @DESCRIPTION:
1472# Display a license for user to accept. If no license is
1473# specified, then ${LICENSE} is used.
1474check_license() {
1475 local lic=$1
1476 if [ -z "${lic}" ] ; then
1477 lic="${PORTDIR}/licenses/${LICENSE}"
1478 else
1479 if [ -e "${PORTDIR}/licenses/${lic}" ] ; then
1480 lic="${PORTDIR}/licenses/${lic}"
1481 elif [ -e "${PWD}/${lic}" ] ; then
1482 lic="${PWD}/${lic}"
1483 elif [ -e "${lic}" ] ; then
1484 lic="${lic}"
1485 fi
1486 fi
1487 local l="`basename ${lic}`"
1488
1489 # here is where we check for the licenses the user already
1490 # accepted ... if we don't find a match, we make the user accept
1491 local alic
1492 eshopts_push -o noglob # so that bash doesn't expand "*"
1493 for alic in ${ACCEPT_LICENSE} ; do
1494 if [[ ${alic} == ${l} ]]; then
1495 eshopts_pop
1496 return 0
1497 fi
1498 done
1499 eshopts_pop
1500 [ ! -f "${lic}" ] && die "Could not find requested license ${lic}"
1501
1502 local licmsg=$(emktemp)
1503 cat <<-EOF > ${licmsg}
1504 **********************************************************
1505 The following license outlines the terms of use of this
1506 package. You MUST accept this license for installation to
1507 continue. When you are done viewing, hit 'q'. If you
1508 CTRL+C out of this, the install will not run!
1509 **********************************************************
1510
1511 EOF
1512 cat ${lic} >> ${licmsg}
1513 ${PAGER:-less} ${licmsg} || die "Could not execute pager (${PAGER}) to accept ${lic}"
1514 einfon "Do you accept the terms of this license (${l})? [yes/no] "
1515 read alic
1516 case ${alic} in
1517 yes|Yes|y|Y)
1518 return 0
1519 ;;
1520 *)
1521 echo;echo;echo
1522 eerror "You MUST accept the license to continue! Exiting!"
1523 die "Failed to accept license"
1524 ;;
1525 esac
1526} 1155}
1527 1156
1528# @FUNCTION: cdrom_get_cds 1157# @FUNCTION: cdrom_get_cds
1529# @USAGE: <file on cd1> [file on cd2] [file on cd3] [...] 1158# @USAGE: <file on cd1> [file on cd2] [file on cd3] [...]
1530# @DESCRIPTION: 1159# @DESCRIPTION:
2045 local liuse=( ${IUSE} ) 1674 local liuse=( ${IUSE} )
2046 1675
2047 has "${flag}" "${liuse[@]#[+-]}" 1676 has "${flag}" "${liuse[@]#[+-]}"
2048} 1677}
2049 1678
1679# @FUNCTION: use_if_iuse
1680# @USAGE: <flag>
1681# @DESCRIPTION:
1682# Return true if the given flag is in USE and IUSE.
1683#
1684# Note that this function should not be used in the global scope.
1685use_if_iuse() {
1686 in_iuse $1 || return 1
1687 use $1
1688}
1689
2050# @FUNCTION: usex 1690# @FUNCTION: usex
2051# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix] 1691# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
2052# @DESCRIPTION: 1692# @DESCRIPTION:
2053# 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"),
2054# otherwise echo [false output][false suffix] (defaults to "no"). 1694# otherwise echo [false output][false suffix] (defaults to "no").
2055usex() { 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.366  
changed lines
  Added in v.1.373

  ViewVC Help
Powered by ViewVC 1.1.20