| 1 | # Copyright 1999-2012 Gentoo Foundation |
1 | # Copyright 1999-2012 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.379 2012/01/31 06:44:00 ulm Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.380 2012/01/31 06:55:37 ulm Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: eutils.eclass |
5 | # @ECLASS: eutils.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # base-system@gentoo.org |
7 | # base-system@gentoo.org |
| 8 | # @BLURB: many extra (but common) functions that are used in ebuilds |
8 | # @BLURB: many extra (but common) functions that are used in ebuilds |
| … | |
… | |
| 16 | # different from the overall eclass! |
16 | # different from the overall eclass! |
| 17 | |
17 | |
| 18 | if [[ ${___ECLASS_ONCE_EUTILS} != "recur -_+^+_- spank" ]] ; then |
18 | if [[ ${___ECLASS_ONCE_EUTILS} != "recur -_+^+_- spank" ]] ; then |
| 19 | ___ECLASS_ONCE_EUTILS="recur -_+^+_- spank" |
19 | ___ECLASS_ONCE_EUTILS="recur -_+^+_- spank" |
| 20 | |
20 | |
| 21 | inherit multilib cdrom user |
21 | inherit multilib portability user |
| 22 | |
22 | |
| 23 | DESCRIPTION="Based on the ${ECLASS} eclass" |
23 | DESCRIPTION="Based on the ${ECLASS} eclass" |
| 24 | |
24 | |
| 25 | if has "${EAPI:-0}" 0 1 2; then |
25 | if has "${EAPI:-0}" 0 1 2; then |
| 26 | |
26 | |
| … | |
… | |
| 1151 | eerror "Unknown filetype \"${filetype}\" ?" |
1151 | eerror "Unknown filetype \"${filetype}\" ?" |
| 1152 | false |
1152 | false |
| 1153 | ;; |
1153 | ;; |
| 1154 | esac |
1154 | esac |
| 1155 | assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})" |
1155 | assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})" |
|
|
1156 | } |
|
|
1157 | |
|
|
1158 | # @FUNCTION: cdrom_get_cds |
|
|
1159 | # @USAGE: <file on cd1> [file on cd2] [file on cd3] [...] |
|
|
1160 | # @DESCRIPTION: |
|
|
1161 | # Aquire cd(s) for those lovely cd-based emerges. Yes, this violates |
|
|
1162 | # the whole 'non-interactive' policy, but damnit I want CD support ! |
|
|
1163 | # |
|
|
1164 | # With these cdrom functions we handle all the user interaction and |
|
|
1165 | # standardize everything. All you have to do is call cdrom_get_cds() |
|
|
1166 | # and when the function returns, you can assume that the cd has been |
|
|
1167 | # found at CDROM_ROOT. |
|
|
1168 | # |
|
|
1169 | # The function will attempt to locate a cd based upon a file that is on |
|
|
1170 | # the cd. The more files you give this function, the more cds |
|
|
1171 | # the cdrom functions will handle. |
|
|
1172 | # |
|
|
1173 | # Normally the cdrom functions will refer to the cds as 'cd #1', 'cd #2', |
|
|
1174 | # etc... If you want to give the cds better names, then just export |
|
|
1175 | # the appropriate CDROM_NAME variable before calling cdrom_get_cds(). |
|
|
1176 | # Use CDROM_NAME for one cd, or CDROM_NAME_# for multiple cds. You can |
|
|
1177 | # also use the CDROM_NAME_SET bash array. |
|
|
1178 | # |
|
|
1179 | # For those multi cd ebuilds, see the cdrom_load_next_cd() function. |
|
|
1180 | cdrom_get_cds() { |
|
|
1181 | # first we figure out how many cds we're dealing with by |
|
|
1182 | # the # of files they gave us |
|
|
1183 | local cdcnt=0 |
|
|
1184 | local f= |
|
|
1185 | for f in "$@" ; do |
|
|
1186 | ((++cdcnt)) |
|
|
1187 | export CDROM_CHECK_${cdcnt}="$f" |
|
|
1188 | done |
|
|
1189 | export CDROM_TOTAL_CDS=${cdcnt} |
|
|
1190 | export CDROM_CURRENT_CD=1 |
|
|
1191 | |
|
|
1192 | # now we see if the user gave use CD_ROOT ... |
|
|
1193 | # if they did, let's just believe them that it's correct |
|
|
1194 | if [[ -n ${CD_ROOT}${CD_ROOT_1} ]] ; then |
|
|
1195 | local var= |
|
|
1196 | cdcnt=0 |
|
|
1197 | while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do |
|
|
1198 | ((++cdcnt)) |
|
|
1199 | var="CD_ROOT_${cdcnt}" |
|
|
1200 | [[ -z ${!var} ]] && var="CD_ROOT" |
|
|
1201 | if [[ -z ${!var} ]] ; then |
|
|
1202 | eerror "You must either use just the CD_ROOT" |
|
|
1203 | eerror "or specify ALL the CD_ROOT_X variables." |
|
|
1204 | eerror "In this case, you will need ${CDROM_TOTAL_CDS} CD_ROOT_X variables." |
|
|
1205 | die "could not locate CD_ROOT_${cdcnt}" |
|
|
1206 | fi |
|
|
1207 | done |
|
|
1208 | export CDROM_ROOT=${CD_ROOT_1:-${CD_ROOT}} |
|
|
1209 | einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}" |
|
|
1210 | export CDROM_SET=-1 |
|
|
1211 | for f in ${CDROM_CHECK_1//:/ } ; do |
|
|
1212 | ((++CDROM_SET)) |
|
|
1213 | [[ -e ${CDROM_ROOT}/${f} ]] && break |
|
|
1214 | done |
|
|
1215 | export CDROM_MATCH=${f} |
|
|
1216 | return |
|
|
1217 | fi |
|
|
1218 | |
|
|
1219 | # User didn't help us out so lets make sure they know they can |
|
|
1220 | # simplify the whole process ... |
|
|
1221 | if [[ ${CDROM_TOTAL_CDS} -eq 1 ]] ; then |
|
|
1222 | einfo "This ebuild will need the ${CDROM_NAME:-cdrom for ${PN}}" |
|
|
1223 | echo |
|
|
1224 | einfo "If you do not have the CD, but have the data files" |
|
|
1225 | einfo "mounted somewhere on your filesystem, just export" |
|
|
1226 | einfo "the variable CD_ROOT so that it points to the" |
|
|
1227 | einfo "directory containing the files." |
|
|
1228 | echo |
|
|
1229 | einfo "For example:" |
|
|
1230 | einfo "export CD_ROOT=/mnt/cdrom" |
|
|
1231 | echo |
|
|
1232 | else |
|
|
1233 | if [[ -n ${CDROM_NAME_SET} ]] ; then |
|
|
1234 | # Translate the CDROM_NAME_SET array into CDROM_NAME_# |
|
|
1235 | cdcnt=0 |
|
|
1236 | while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do |
|
|
1237 | ((++cdcnt)) |
|
|
1238 | export CDROM_NAME_${cdcnt}="${CDROM_NAME_SET[$((${cdcnt}-1))]}" |
|
|
1239 | done |
|
|
1240 | fi |
|
|
1241 | |
|
|
1242 | einfo "This package will need access to ${CDROM_TOTAL_CDS} cds." |
|
|
1243 | cdcnt=0 |
|
|
1244 | while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do |
|
|
1245 | ((++cdcnt)) |
|
|
1246 | var="CDROM_NAME_${cdcnt}" |
|
|
1247 | [[ ! -z ${!var} ]] && einfo " CD ${cdcnt}: ${!var}" |
|
|
1248 | done |
|
|
1249 | echo |
|
|
1250 | einfo "If you do not have the CDs, but have the data files" |
|
|
1251 | einfo "mounted somewhere on your filesystem, just export" |
|
|
1252 | einfo "the following variables so they point to the right place:" |
|
|
1253 | einfon "" |
|
|
1254 | cdcnt=0 |
|
|
1255 | while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do |
|
|
1256 | ((++cdcnt)) |
|
|
1257 | echo -n " CD_ROOT_${cdcnt}" |
|
|
1258 | done |
|
|
1259 | echo |
|
|
1260 | einfo "Or, if you have all the files in the same place, or" |
|
|
1261 | einfo "you only have one cdrom, you can export CD_ROOT" |
|
|
1262 | einfo "and that place will be used as the same data source" |
|
|
1263 | einfo "for all the CDs." |
|
|
1264 | echo |
|
|
1265 | einfo "For example:" |
|
|
1266 | einfo "export CD_ROOT_1=/mnt/cdrom" |
|
|
1267 | echo |
|
|
1268 | fi |
|
|
1269 | |
|
|
1270 | export CDROM_SET="" |
|
|
1271 | export CDROM_CURRENT_CD=0 |
|
|
1272 | cdrom_load_next_cd |
|
|
1273 | } |
|
|
1274 | |
|
|
1275 | # @FUNCTION: cdrom_load_next_cd |
|
|
1276 | # @DESCRIPTION: |
|
|
1277 | # Some packages are so big they come on multiple CDs. When you're done reading |
|
|
1278 | # files off a CD and want access to the next one, just call this function. |
|
|
1279 | # Again, all the messy details of user interaction are taken care of for you. |
|
|
1280 | # Once this returns, just read the variable CDROM_ROOT for the location of the |
|
|
1281 | # mounted CD. Note that you can only go forward in the CD list, so make sure |
|
|
1282 | # you only call this function when you're done using the current CD. |
|
|
1283 | cdrom_load_next_cd() { |
|
|
1284 | local var |
|
|
1285 | ((++CDROM_CURRENT_CD)) |
|
|
1286 | |
|
|
1287 | unset CDROM_ROOT |
|
|
1288 | var=CD_ROOT_${CDROM_CURRENT_CD} |
|
|
1289 | [[ -z ${!var} ]] && var="CD_ROOT" |
|
|
1290 | if [[ -z ${!var} ]] ; then |
|
|
1291 | var="CDROM_CHECK_${CDROM_CURRENT_CD}" |
|
|
1292 | _cdrom_locate_file_on_cd ${!var} |
|
|
1293 | else |
|
|
1294 | export CDROM_ROOT=${!var} |
|
|
1295 | fi |
|
|
1296 | |
|
|
1297 | einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}" |
|
|
1298 | } |
|
|
1299 | |
|
|
1300 | # this is used internally by the cdrom_get_cds() and cdrom_load_next_cd() |
|
|
1301 | # functions. this should *never* be called from an ebuild. |
|
|
1302 | # all it does is try to locate a give file on a cd ... if the cd isn't |
|
|
1303 | # found, then a message asking for the user to insert the cdrom will be |
|
|
1304 | # displayed and we'll hang out here until: |
|
|
1305 | # (1) the file is found on a mounted cdrom |
|
|
1306 | # (2) the user hits CTRL+C |
|
|
1307 | _cdrom_locate_file_on_cd() { |
|
|
1308 | local mline="" |
|
|
1309 | local showedmsg=0 showjolietmsg=0 |
|
|
1310 | |
|
|
1311 | while [[ -z ${CDROM_ROOT} ]] ; do |
|
|
1312 | local i=0 |
|
|
1313 | local -a cdset=(${*//:/ }) |
|
|
1314 | if [[ -n ${CDROM_SET} ]] ; then |
|
|
1315 | cdset=(${cdset[${CDROM_SET}]}) |
|
|
1316 | fi |
|
|
1317 | |
|
|
1318 | while [[ -n ${cdset[${i}]} ]] ; do |
|
|
1319 | local dir=$(dirname ${cdset[${i}]}) |
|
|
1320 | local file=$(basename ${cdset[${i}]}) |
|
|
1321 | |
|
|
1322 | local point= node= fs= foo= |
|
|
1323 | while read point node fs foo ; do |
|
|
1324 | [[ " cd9660 iso9660 udf " != *" ${fs} "* ]] && \ |
|
|
1325 | ! [[ ${fs} == "subfs" && ",${opts}," == *",fs=cdfss,"* ]] \ |
|
|
1326 | && continue |
|
|
1327 | point=${point//\040/ } |
|
|
1328 | [[ ! -d ${point}/${dir} ]] && continue |
|
|
1329 | [[ -z $(find "${point}/${dir}" -maxdepth 1 -iname "${file}") ]] && continue |
|
|
1330 | export CDROM_ROOT=${point} |
|
|
1331 | export CDROM_SET=${i} |
|
|
1332 | export CDROM_MATCH=${cdset[${i}]} |
|
|
1333 | return |
|
|
1334 | done <<< "$(get_mounts)" |
|
|
1335 | |
|
|
1336 | ((++i)) |
|
|
1337 | done |
|
|
1338 | |
|
|
1339 | echo |
|
|
1340 | if [[ ${showedmsg} -eq 0 ]] ; then |
|
|
1341 | if [[ ${CDROM_TOTAL_CDS} -eq 1 ]] ; then |
|
|
1342 | if [[ -z ${CDROM_NAME} ]] ; then |
|
|
1343 | einfo "Please insert+mount the cdrom for ${PN} now !" |
|
|
1344 | else |
|
|
1345 | einfo "Please insert+mount the ${CDROM_NAME} cdrom now !" |
|
|
1346 | fi |
|
|
1347 | else |
|
|
1348 | if [[ -z ${CDROM_NAME_1} ]] ; then |
|
|
1349 | einfo "Please insert+mount cd #${CDROM_CURRENT_CD} for ${PN} now !" |
|
|
1350 | else |
|
|
1351 | local var="CDROM_NAME_${CDROM_CURRENT_CD}" |
|
|
1352 | einfo "Please insert+mount the ${!var} cdrom now !" |
|
|
1353 | fi |
|
|
1354 | fi |
|
|
1355 | showedmsg=1 |
|
|
1356 | fi |
|
|
1357 | einfo "Press return to scan for the cd again" |
|
|
1358 | einfo "or hit CTRL+C to abort the emerge." |
|
|
1359 | echo |
|
|
1360 | if [[ ${showjolietmsg} -eq 0 ]] ; then |
|
|
1361 | showjolietmsg=1 |
|
|
1362 | else |
|
|
1363 | ewarn "If you are having trouble with the detection" |
|
|
1364 | ewarn "of your CD, it is possible that you do not have" |
|
|
1365 | ewarn "Joliet support enabled in your kernel. Please" |
|
|
1366 | ewarn "check that CONFIG_JOLIET is enabled in your kernel." |
|
|
1367 | ebeep 5 |
|
|
1368 | fi |
|
|
1369 | read || die "something is screwed with your system" |
|
|
1370 | done |
| 1156 | } |
1371 | } |
| 1157 | |
1372 | |
| 1158 | # @FUNCTION: strip-linguas |
1373 | # @FUNCTION: strip-linguas |
| 1159 | # @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>] |
1374 | # @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>] |
| 1160 | # @DESCRIPTION: |
1375 | # @DESCRIPTION: |