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

Contents of /eclass/cdrom.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Fri Jan 13 20:23:06 2012 UTC (2 years, 10 months ago) by ulm
Branch: MAIN
Split out CD-ROM functions from eutils.eclass.

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

  ViewVC Help
Powered by ViewVC 1.1.20