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

Contents of /eclass/cdrom.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Sun Jan 15 14:13:46 2012 UTC (2 years, 11 months ago) by ulm
Branch: MAIN
Changes since 1.2: +11 -1 lines
New variable CDROM_DISABLE_PROPERTIES. Set PROPERTIES only if this is unset.

1 ulm 1.2 # Copyright 1999-2012 Gentoo Foundation
2 ulm 1.1 # Distributed under the terms of the GNU General Public License v2
3 ulm 1.3 # $Header: /var/cvsroot/gentoo-x86/eclass/cdrom.eclass,v 1.2 2012/01/13 22:35:16 ulm Exp $
4 ulm 1.1
5     # @ECLASS: cdrom.eclass
6     # @MAINTAINER:
7     # games@gentoo.org
8     # @BLURB: Functions for CD-ROM handling
9     # @DESCRIPTION:
10     # Acquire cd(s) for those lovely cd-based emerges. Yes, this violates
11     # the whole 'non-interactive' policy, but damnit I want CD support!
12     #
13     # With these cdrom functions we handle all the user interaction and
14     # standardize everything. All you have to do is call cdrom_get_cds()
15     # and when the function returns, you can assume that the cd has been
16     # found at CDROM_ROOT.
17    
18     if [[ -z ${___ECLASS_ONCE_CDROM} ]]; then
19     ___ECLASS_ONCE_CDROM=1
20    
21     inherit portability
22    
23 ulm 1.3 # @ECLASS-VARIABLE: CDROM_DISABLE_PROPERTIES
24     # @DEFAULT_UNSET
25     # @DESCRIPTION:
26     # By default, the eclass sets PROPERTIES="interactive".
27     # A non-empty value of CDROM_DISABLE_PROPERTIES suppresses this.
28    
29     if [[ -z ${CDROM_DISABLE_PROPERTIES} ]]; then
30     PROPERTIES="interactive"
31     fi
32    
33 ulm 1.1 # @FUNCTION: cdrom_get_cds
34     # @USAGE: <file on cd1> [file on cd2] [file on cd3] [...]
35     # @DESCRIPTION:
36     # The function will attempt to locate a cd based upon a file that is on
37     # the cd. The more files you give this function, the more cds the cdrom
38     # functions will handle.
39     #
40     # Normally the cdrom functions will refer to the cds as 'cd #1', 'cd #2',
41     # etc... If you want to give the cds better names, then just export
42     # the appropriate CDROM_NAME variable before calling cdrom_get_cds().
43     # Use CDROM_NAME for one cd, or CDROM_NAME_# for multiple cds. You can
44     # also use the CDROM_NAME_SET bash array.
45     #
46     # For those multi cd ebuilds, see the cdrom_load_next_cd() function.
47     cdrom_get_cds() {
48     # first we figure out how many cds we're dealing with by
49     # the # of files they gave us
50     local cdcnt=0
51     local f=
52     for f in "$@" ; do
53     ((++cdcnt))
54     export CDROM_CHECK_${cdcnt}="$f"
55     done
56     export CDROM_TOTAL_CDS=${cdcnt}
57     export CDROM_CURRENT_CD=1
58    
59     # now we see if the user gave use CD_ROOT ...
60     # if they did, let's just believe them that it's correct
61     if [[ -n ${CD_ROOT}${CD_ROOT_1} ]] ; then
62     local var=
63     cdcnt=0
64     while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
65     ((++cdcnt))
66     var="CD_ROOT_${cdcnt}"
67     [[ -z ${!var} ]] && var="CD_ROOT"
68     if [[ -z ${!var} ]] ; then
69     eerror "You must either use just the CD_ROOT"
70     eerror "or specify ALL the CD_ROOT_X variables."
71     eerror "In this case, you will need" \
72     "${CDROM_TOTAL_CDS} CD_ROOT_X variables."
73     die "could not locate CD_ROOT_${cdcnt}"
74     fi
75     done
76     export CDROM_ROOT=${CD_ROOT_1:-${CD_ROOT}}
77     einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
78     export CDROM_SET=-1
79     for f in ${CDROM_CHECK_1//:/ } ; do
80     ((++CDROM_SET))
81     [[ -e ${CDROM_ROOT}/${f} ]] && break
82     done
83     export CDROM_MATCH=${f}
84     return
85     fi
86    
87     # User didn't help us out so lets make sure they know they can
88     # simplify the whole process ...
89     if [[ ${CDROM_TOTAL_CDS} -eq 1 ]] ; then
90     einfo "This ebuild will need the ${CDROM_NAME:-cdrom for ${PN}}"
91     echo
92     einfo "If you do not have the CD, but have the data files"
93     einfo "mounted somewhere on your filesystem, just export"
94     einfo "the variable CD_ROOT so that it points to the"
95     einfo "directory containing the files."
96     echo
97     einfo "For example:"
98     einfo "export CD_ROOT=/mnt/cdrom"
99     echo
100     else
101     if [[ -n ${CDROM_NAME_SET} ]] ; then
102     # Translate the CDROM_NAME_SET array into CDROM_NAME_#
103     cdcnt=0
104     while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
105     ((++cdcnt))
106     export CDROM_NAME_${cdcnt}="${CDROM_NAME_SET[$((${cdcnt}-1))]}"
107     done
108     fi
109    
110     einfo "This package will need access to ${CDROM_TOTAL_CDS} cds."
111     cdcnt=0
112     while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
113     ((++cdcnt))
114     var="CDROM_NAME_${cdcnt}"
115     [[ ! -z ${!var} ]] && einfo " CD ${cdcnt}: ${!var}"
116     done
117     echo
118     einfo "If you do not have the CDs, but have the data files"
119     einfo "mounted somewhere on your filesystem, just export"
120     einfo "the following variables so they point to the right place:"
121     einfon ""
122     cdcnt=0
123     while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
124     ((++cdcnt))
125     echo -n " CD_ROOT_${cdcnt}"
126     done
127     echo
128     einfo "Or, if you have all the files in the same place, or"
129     einfo "you only have one cdrom, you can export CD_ROOT"
130     einfo "and that place will be used as the same data source"
131     einfo "for all the CDs."
132     echo
133     einfo "For example:"
134     einfo "export CD_ROOT_1=/mnt/cdrom"
135     echo
136     fi
137    
138     export CDROM_SET=""
139     export CDROM_CURRENT_CD=0
140     cdrom_load_next_cd
141     }
142    
143     # @FUNCTION: cdrom_load_next_cd
144     # @DESCRIPTION:
145     # Some packages are so big they come on multiple CDs. When you're done
146     # reading files off a CD and want access to the next one, just call this
147     # function. Again, all the messy details of user interaction are taken
148     # care of for you. Once this returns, just read the variable CDROM_ROOT
149     # for the location of the mounted CD. Note that you can only go forward
150     # in the CD list, so make sure you only call this function when you're
151     # done using the current CD.
152     cdrom_load_next_cd() {
153     local var
154     ((++CDROM_CURRENT_CD))
155    
156     unset CDROM_ROOT
157     var=CD_ROOT_${CDROM_CURRENT_CD}
158     [[ -z ${!var} ]] && var="CD_ROOT"
159     if [[ -z ${!var} ]] ; then
160     var="CDROM_CHECK_${CDROM_CURRENT_CD}"
161     _cdrom_locate_file_on_cd ${!var}
162     else
163     export CDROM_ROOT=${!var}
164     fi
165    
166     einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
167     }
168    
169     # this is used internally by the cdrom_get_cds() and cdrom_load_next_cd()
170     # functions. this should *never* be called from an ebuild.
171     # all it does is try to locate a give file on a cd ... if the cd isn't
172     # found, then a message asking for the user to insert the cdrom will be
173     # displayed and we'll hang out here until:
174     # (1) the file is found on a mounted cdrom
175     # (2) the user hits CTRL+C
176     _cdrom_locate_file_on_cd() {
177     local mline=""
178     local showedmsg=0 showjolietmsg=0
179    
180     while [[ -z ${CDROM_ROOT} ]] ; do
181     local i=0
182     local -a cdset=(${*//:/ })
183     if [[ -n ${CDROM_SET} ]] ; then
184     cdset=(${cdset[${CDROM_SET}]})
185     fi
186    
187     while [[ -n ${cdset[${i}]} ]] ; do
188     local dir=$(dirname ${cdset[${i}]})
189     local file=$(basename ${cdset[${i}]})
190    
191     local point= node= fs= foo=
192     while read point node fs foo ; do
193     [[ " cd9660 iso9660 udf " != *" ${fs} "* ]] && \
194     ! [[ ${fs} == "subfs" && ",${opts}," == *",fs=cdfss,"* ]] \
195     && continue
196     point=${point//\040/ }
197     [[ ! -d ${point}/${dir} ]] && continue
198     [[ -z $(find "${point}/${dir}" -maxdepth 1 -iname "${file}") ]] \
199     && continue
200     export CDROM_ROOT=${point}
201     export CDROM_SET=${i}
202     export CDROM_MATCH=${cdset[${i}]}
203     return
204     done <<< "$(get_mounts)"
205    
206     ((++i))
207     done
208    
209     echo
210     if [[ ${showedmsg} -eq 0 ]] ; then
211     if [[ ${CDROM_TOTAL_CDS} -eq 1 ]] ; then
212     if [[ -z ${CDROM_NAME} ]] ; then
213     einfo "Please insert+mount the cdrom for ${PN} now !"
214     else
215     einfo "Please insert+mount the ${CDROM_NAME} cdrom now !"
216     fi
217     else
218     if [[ -z ${CDROM_NAME_1} ]] ; then
219     einfo "Please insert+mount cd #${CDROM_CURRENT_CD}" \
220     "for ${PN} now !"
221     else
222     local var="CDROM_NAME_${CDROM_CURRENT_CD}"
223     einfo "Please insert+mount the ${!var} cdrom now !"
224     fi
225     fi
226     showedmsg=1
227     fi
228     einfo "Press return to scan for the cd again"
229     einfo "or hit CTRL+C to abort the emerge."
230     echo
231     if [[ ${showjolietmsg} -eq 0 ]] ; then
232     showjolietmsg=1
233     else
234     ewarn "If you are having trouble with the detection"
235     ewarn "of your CD, it is possible that you do not have"
236     ewarn "Joliet support enabled in your kernel. Please"
237     ewarn "check that CONFIG_JOLIET is enabled in your kernel."
238     fi
239     read || die "something is screwed with your system"
240     done
241     }
242    
243     fi

  ViewVC Help
Powered by ViewVC 1.1.20