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

Contents of /eclass/cdrom.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations) (download)
Fri Jul 11 08:21:58 2014 UTC (5 months, 2 weeks ago) by ulm
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +4 -4 lines
Avoid reserved names for functions and variables, bug 516092.

1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/cdrom.eclass,v 1.5 2012/01/18 12:42:06 vapier Exp $
4
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 ${_CDROM_ECLASS} ]]; then
19 _CDROM_ECLASS=1
20
21 inherit portability
22
23 # @ECLASS-VARIABLE: CDROM_OPTIONAL
24 # @DEFAULT_UNSET
25 # @DESCRIPTION:
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
31 IUSE="cdinstall"
32 PROPERTIES="cdinstall? ( interactive )"
33 else
34 PROPERTIES="interactive"
35 fi
36
37 # @FUNCTION: cdrom_get_cds
38 # @USAGE: <file on cd1> [file on cd2] [file on cd3] [...]
39 # @DESCRIPTION:
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.
43 #
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.
49 #
50 # For those multi cd ebuilds, see the cdrom_load_next_cd() function.
51 cdrom_get_cds() {
52 # first we figure out how many cds we're dealing with by
53 # the # of files they gave us
54 local cdcnt=0
55 local f=
56 for f in "$@" ; do
57 ((++cdcnt))
58 export CDROM_CHECK_${cdcnt}="$f"
59 done
60 export CDROM_TOTAL_CDS=${cdcnt}
61 export CDROM_CURRENT_CD=1
62
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
66 local var=
67 cdcnt=0
68 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
69 ((++cdcnt))
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}"
78 fi
79 done
80 export CDROM_ROOT=${CD_ROOT_1:-${CD_ROOT}}
81 einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
82 export CDROM_SET=-1
83 for f in ${CDROM_CHECK_1//:/ } ; do
84 ((++CDROM_SET))
85 [[ -e ${CDROM_ROOT}/${f} ]] && break
86 done
87 export CDROM_MATCH=${f}
88 return
89 fi
90
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}}"
95 echo
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."
100 echo
101 einfo "For example:"
102 einfo "export CD_ROOT=/mnt/cdrom"
103 echo
104 else
105 if [[ -n ${CDROM_NAME_SET} ]] ; then
106 # Translate the CDROM_NAME_SET array into CDROM_NAME_#
107 cdcnt=0
108 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
109 ((++cdcnt))
110 export CDROM_NAME_${cdcnt}="${CDROM_NAME_SET[$((${cdcnt}-1))]}"
111 done
112 fi
113
114 einfo "This package will need access to ${CDROM_TOTAL_CDS} cds."
115 cdcnt=0
116 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
117 ((++cdcnt))
118 var="CDROM_NAME_${cdcnt}"
119 [[ ! -z ${!var} ]] && einfo " CD ${cdcnt}: ${!var}"
120 done
121 echo
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:"
125 einfon ""
126 cdcnt=0
127 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
128 ((++cdcnt))
129 echo -n " CD_ROOT_${cdcnt}"
130 done
131 echo
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."
136 echo
137 einfo "For example:"
138 einfo "export CD_ROOT_1=/mnt/cdrom"
139 echo
140 fi
141
142 export CDROM_SET=""
143 export CDROM_CURRENT_CD=0
144 cdrom_load_next_cd
145 }
146
147 # @FUNCTION: cdrom_load_next_cd
148 # @DESCRIPTION:
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() {
157 local var
158 ((++CDROM_CURRENT_CD))
159
160 unset CDROM_ROOT
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}
166 else
167 export CDROM_ROOT=${!var}
168 fi
169
170 einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
171 }
172
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() {
181 local mline=""
182 local showedmsg=0 showjolietmsg=0
183
184 while [[ -z ${CDROM_ROOT} ]] ; do
185 local i=0
186 local -a cdset=(${*//:/ })
187 if [[ -n ${CDROM_SET} ]] ; then
188 cdset=(${cdset[${CDROM_SET}]})
189 fi
190
191 while [[ -n ${cdset[${i}]} ]] ; do
192 local dir=$(dirname ${cdset[${i}]})
193 local file=$(basename ${cdset[${i}]})
194
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,"* ]] \
199 && continue
200 point=${point//\040/ }
201 [[ ! -d ${point}/${dir} ]] && continue
202 [[ -z $(find "${point}/${dir}" -maxdepth 1 -iname "${file}") ]] \
203 && continue
204 export CDROM_ROOT=${point}
205 export CDROM_SET=${i}
206 export CDROM_MATCH=${cdset[${i}]}
207 return
208 done <<< "$(get_mounts)"
209
210 ((++i))
211 done
212
213 echo
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 !"
218 else
219 einfo "Please insert+mount the ${CDROM_NAME} cdrom now !"
220 fi
221 else
222 if [[ -z ${CDROM_NAME_1} ]] ; then
223 einfo "Please insert+mount cd #${CDROM_CURRENT_CD}" \
224 "for ${PN} now !"
225 else
226 local var="CDROM_NAME_${CDROM_CURRENT_CD}"
227 einfo "Please insert+mount the ${!var} cdrom now !"
228 fi
229 fi
230 showedmsg=1
231 fi
232 einfo "Press return to scan for the cd again"
233 einfo "or hit CTRL+C to abort the emerge."
234 echo
235 if [[ ${showjolietmsg} -eq 0 ]] ; then
236 showjolietmsg=1
237 else
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."
242 fi
243 read || die "something is screwed with your system"
244 done
245 }
246
247 fi

  ViewVC Help
Powered by ViewVC 1.1.20