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