1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: cdrom.eclass
8 # @BLURB: Functions for CD-ROM handling
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!
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.
18 if [[ -z ${_CDROM_ECLASS} ]]; then
23 # @ECLASS-VARIABLE: CDROM_OPTIONAL
26 # By default, the eclass sets PROPERTIES="interactive" on the assumption
27 # that people will be using these. If your package optionally supports
28 # disc based installed, then set this to "yes", and we'll set things
29 # conditionally based on USE=cdinstall.
30 if [[ ${CDROM_OPTIONAL} == "yes" ]] ; then
32 PROPERTIES="cdinstall? ( interactive )"
34 PROPERTIES="interactive"
37 # @FUNCTION: cdrom_get_cds
38 # @USAGE: <file on cd1> [file on cd2] [file on cd3] [...]
40 # The function will attempt to locate a cd based upon a file that is on
41 # the cd. The more files you give this function, the more cds the cdrom
42 # functions will handle.
44 # Normally the cdrom functions will refer to the cds as 'cd #1', 'cd #2',
45 # etc... If you want to give the cds better names, then just export
46 # the appropriate CDROM_NAME variable before calling cdrom_get_cds().
47 # Use CDROM_NAME for one cd, or CDROM_NAME_# for multiple cds. You can
48 # also use the CDROM_NAME_SET bash array.
50 # For those multi cd ebuilds, see the cdrom_load_next_cd() function.
52 # first we figure out how many cds we're dealing with by
53 # the # of files they gave us
58 export CDROM_CHECK_${cdcnt}="$f"
60 export CDROM_TOTAL_CDS=${cdcnt}
61 export CDROM_CURRENT_CD=1
63 # now we see if the user gave use CD_ROOT ...
64 # if they did, let's just believe them that it's correct
65 if [[ -n ${CD_ROOT}${CD_ROOT_1} ]] ; then
68 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
70 var="CD_ROOT_${cdcnt}"
71 [[ -z ${!var} ]] && var="CD_ROOT"
72 if [[ -z ${!var} ]] ; then
73 eerror "You must either use just the CD_ROOT"
74 eerror "or specify ALL the CD_ROOT_X variables."
75 eerror "In this case, you will need" \
76 "${CDROM_TOTAL_CDS} CD_ROOT_X variables."
77 die "could not locate CD_ROOT_${cdcnt}"
80 export CDROM_ROOT=${CD_ROOT_1:-${CD_ROOT}}
81 einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
83 for f in ${CDROM_CHECK_1//:/ } ; do
85 [[ -e ${CDROM_ROOT}/${f} ]] && break
87 export CDROM_MATCH=${f}
91 # User didn't help us out so lets make sure they know they can
92 # simplify the whole process ...
93 if [[ ${CDROM_TOTAL_CDS} -eq 1 ]] ; then
94 einfo "This ebuild will need the ${CDROM_NAME:-cdrom for ${PN}}"
96 einfo "If you do not have the CD, but have the data files"
97 einfo "mounted somewhere on your filesystem, just export"
98 einfo "the variable CD_ROOT so that it points to the"
99 einfo "directory containing the files."
102 einfo "export CD_ROOT=/mnt/cdrom"
105 if [[ -n ${CDROM_NAME_SET} ]] ; then
106 # Translate the CDROM_NAME_SET array into CDROM_NAME_#
108 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
110 export CDROM_NAME_${cdcnt}="${CDROM_NAME_SET[$((${cdcnt}-1))]}"
114 einfo "This package will need access to ${CDROM_TOTAL_CDS} cds."
116 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
118 var="CDROM_NAME_${cdcnt}"
119 [[ ! -z ${!var} ]] && einfo " CD ${cdcnt}: ${!var}"
122 einfo "If you do not have the CDs, but have the data files"
123 einfo "mounted somewhere on your filesystem, just export"
124 einfo "the following variables so they point to the right place:"
127 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
129 echo -n " CD_ROOT_${cdcnt}"
132 einfo "Or, if you have all the files in the same place, or"
133 einfo "you only have one cdrom, you can export CD_ROOT"
134 einfo "and that place will be used as the same data source"
135 einfo "for all the CDs."
138 einfo "export CD_ROOT_1=/mnt/cdrom"
143 export CDROM_CURRENT_CD=0
147 # @FUNCTION: cdrom_load_next_cd
149 # Some packages are so big they come on multiple CDs. When you're done
150 # reading files off a CD and want access to the next one, just call this
151 # function. Again, all the messy details of user interaction are taken
152 # care of for you. Once this returns, just read the variable CDROM_ROOT
153 # for the location of the mounted CD. Note that you can only go forward
154 # in the CD list, so make sure you only call this function when you're
155 # done using the current CD.
156 cdrom_load_next_cd() {
158 ((++CDROM_CURRENT_CD))
161 var=CD_ROOT_${CDROM_CURRENT_CD}
162 [[ -z ${!var} ]] && var="CD_ROOT"
163 if [[ -z ${!var} ]] ; then
164 var="CDROM_CHECK_${CDROM_CURRENT_CD}"
165 _cdrom_locate_file_on_cd ${!var}
167 export CDROM_ROOT=${!var}
170 einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
173 # this is used internally by the cdrom_get_cds() and cdrom_load_next_cd()
174 # functions. this should *never* be called from an ebuild.
175 # all it does is try to locate a give file on a cd ... if the cd isn't
176 # found, then a message asking for the user to insert the cdrom will be
177 # displayed and we'll hang out here until:
178 # (1) the file is found on a mounted cdrom
179 # (2) the user hits CTRL+C
180 _cdrom_locate_file_on_cd() {
182 local showedmsg=0 showjolietmsg=0
184 while [[ -z ${CDROM_ROOT} ]] ; do
186 local -a cdset=(${*//:/ })
187 if [[ -n ${CDROM_SET} ]] ; then
188 cdset=(${cdset[${CDROM_SET}]})
191 while [[ -n ${cdset[${i}]} ]] ; do
192 local dir=$(dirname ${cdset[${i}]})
193 local file=$(basename ${cdset[${i}]})
195 local point= node= fs= foo=
196 while read point node fs foo ; do
197 [[ " cd9660 iso9660 udf " != *" ${fs} "* ]] && \
198 ! [[ ${fs} == "subfs" && ",${opts}," == *",fs=cdfss,"* ]] \
200 point=${point//\040/ }
201 [[ ! -d ${point}/${dir} ]] && continue
202 [[ -z $(find "${point}/${dir}" -maxdepth 1 -iname "${file}") ]] \
204 export CDROM_ROOT=${point}
205 export CDROM_SET=${i}
206 export CDROM_MATCH=${cdset[${i}]}
208 done <<< "$(get_mounts)"
214 if [[ ${showedmsg} -eq 0 ]] ; then
215 if [[ ${CDROM_TOTAL_CDS} -eq 1 ]] ; then
216 if [[ -z ${CDROM_NAME} ]] ; then
217 einfo "Please insert+mount the cdrom for ${PN} now !"
219 einfo "Please insert+mount the ${CDROM_NAME} cdrom now !"
222 if [[ -z ${CDROM_NAME_1} ]] ; then
223 einfo "Please insert+mount cd #${CDROM_CURRENT_CD}" \
226 local var="CDROM_NAME_${CDROM_CURRENT_CD}"
227 einfo "Please insert+mount the ${!var} cdrom now !"
232 einfo "Press return to scan for the cd again"
233 einfo "or hit CTRL+C to abort the emerge."
235 if [[ ${showjolietmsg} -eq 0 ]] ; then
238 ewarn "If you are having trouble with the detection"
239 ewarn "of your CD, it is possible that you do not have"
240 ewarn "Joliet support enabled in your kernel. Please"
241 ewarn "check that CONFIG_JOLIET is enabled in your kernel."
243 read || die "something is screwed with your system"