Contents of /trunk/mage/usr/lib/mage/mage4.functions.sh
Parent Directory | Revision Log
Revision 409 -
(show annotations)
(download)
(as text)
Sat Dec 30 11:39:32 2006 UTC (17 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 62556 byte(s)
Sat Dec 30 11:39:32 2006 UTC (17 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 62556 byte(s)
fixed minclude of mutliple files
1 | #!/bin/bash |
2 | # Magellan Linux Installer Functions (mage.functions.sh) |
3 | # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.23 2006-12-30 11:39:32 niro Exp $ |
4 | |
5 | mage_setup() |
6 | { |
7 | [ ! -d ${MROOT}${INSTALLDB} ] && \ |
8 | install -d ${MROOT}${INSTALLDB} |
9 | [ ! -f ${MROOT}${VIRTUALDB_FILE} ] && \ |
10 | touch ${MROOT}${VIRTUALDB_FILE} |
11 | [ ! -d ${PKGDIR} ] && install -d ${PKGDIR} |
12 | [ ! -d ${BUILDDIR} ] && install -d ${BUILDDIR} |
13 | [ ! -d ${MAGEDIR} ] && install -d ${MAGEDIR} |
14 | |
15 | return 0 |
16 | } |
17 | |
18 | unpack_packages() |
19 | { |
20 | local list="$@" |
21 | local magefile |
22 | local pkg |
23 | local pkgtype |
24 | local count_current |
25 | local count_total |
26 | |
27 | # get count of total packages |
28 | declare -i count_current=0 |
29 | declare -i count_total=0 |
30 | |
31 | for i in ${list}; do (( count_total++ )); done |
32 | |
33 | for magefile in ${list} |
34 | do |
35 | pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" |
36 | pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
37 | |
38 | (( count_current++ )) |
39 | xtitle "[ (${count_current}/${count_total}) Unpacking ${pkg} ]" |
40 | |
41 | # abort on virtual pkg |
42 | if [[ ${pkgtype} = virtual ]] |
43 | then |
44 | echo -ne " ${COLBLUE}---${COLDEFAULT}" |
45 | echo " !unpack virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
46 | continue |
47 | fi |
48 | |
49 | # abort on sources pkg |
50 | if [[ ${pkgtype} = sources ]] |
51 | then |
52 | echo -ne " ${COLBLUE}---${COLDEFAULT}" |
53 | echo " !unpack sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
54 | continue |
55 | fi |
56 | |
57 | echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... " |
58 | tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}" |
59 | done |
60 | |
61 | # add a crlf for a better view |
62 | if [ ${count_total} -gt 1 ]; then echo; fi |
63 | } |
64 | |
65 | |
66 | # fix_mtime path/to/$mtime/reffile $pathto/file |
67 | # creates a given reference file and fixes given file |
68 | # returns new mtime |
69 | fix_mtime() |
70 | { |
71 | local reference="$1" |
72 | local pathto="$2" |
73 | local mtime |
74 | |
75 | mtime=$(stat -c %Y "${reference}") |
76 | touch \ |
77 | --no-create \ |
78 | --time=mtime \ |
79 | --reference "${reference}" \ |
80 | "${pathto}" |
81 | |
82 | echo "${mtime}" |
83 | } |
84 | |
85 | # fix_descriptor pkgname/.dir "foo1" "foo2" |
86 | fix_descriptor() |
87 | { |
88 | local descriptor="$1" |
89 | local output |
90 | local i |
91 | shift |
92 | |
93 | for i in $@ |
94 | do |
95 | if [[ -z ${output} ]] |
96 | then |
97 | output="${i}" |
98 | else |
99 | output="${output}§${i}" |
100 | fi |
101 | done |
102 | |
103 | echo "${output}" >> ${BUILDDIR}/${descriptor}_fixed |
104 | } |
105 | |
106 | ################################################### |
107 | # function install_direcories # |
108 | # install_direcories $PKGNAME # |
109 | ################################################### |
110 | install_directories() |
111 | { |
112 | local pkgname="$1" |
113 | local pathto |
114 | local posix |
115 | local user |
116 | local group |
117 | local IFS |
118 | |
119 | # sanity checks; abort if not given |
120 | [ -z "${pkgname}" ] && die "install_directories() \$pkgname not given." |
121 | |
122 | # check needed global vars |
123 | [ -z "${BUILDDIR}" ] && die "install_directories() \$BUILDDIR not set." |
124 | |
125 | [ ! -f ${BUILDDIR}/${pkgname}/.dirs ] && die "install_directories() .dirs not found" |
126 | |
127 | # sets fieldseperator to "§" instead of " " |
128 | IFS=§ |
129 | |
130 | while read pathto posix user group |
131 | do |
132 | [ -z "${pathto}" ] && continue |
133 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR: ${MROOT}${pathto}" |
134 | |
135 | |
136 | # monitors /etc/env.d -> env-rebuild |
137 | [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true |
138 | |
139 | # monitors /usr/share/info -> info-rebuild |
140 | [[ ${pathto} = /usr/share/info ]] && export MAGE_INFO_REBUILD=true |
141 | |
142 | install -m "${posix}" -o "${user}" -g "${group}" -d "${MROOT}${pathto}" |
143 | done < ${BUILDDIR}/${pkgname}/.dirs |
144 | |
145 | # very important: unsetting the '§' fieldseperator |
146 | IFS=$'\n' |
147 | } |
148 | |
149 | |
150 | ################################################### |
151 | # function install_files # |
152 | # install_files $PKGNAME # |
153 | ################################################### |
154 | install_files() |
155 | { |
156 | |
157 | local pkgname="$1" |
158 | local pathto |
159 | local posix |
160 | local user |
161 | local group |
162 | local mtime |
163 | local md5sum |
164 | |
165 | local retval |
166 | local counter |
167 | local filename |
168 | local dest_dirname |
169 | local dest_protected |
170 | local IFS |
171 | |
172 | # sanity checks; abort if not given |
173 | [ -z "${pkgname}" ] && die "install_files() \$pkgname not given." |
174 | |
175 | # check needed global vars |
176 | [ -z "${BUILDDIR}" ] && die "install_files() \$BUILDDIR not set." |
177 | |
178 | [ ! -f ${BUILDDIR}/${pkgname}/.files ] && die "install_files() .files not found" |
179 | |
180 | # delete old files |
181 | [ -f ${BUILDDIR}/${pkgname}/.files_fixed ] && rm ${BUILDDIR}/${pkgname}/.files_fixed |
182 | |
183 | # sets fieldseperator to "§" instead of " " |
184 | IFS=§ |
185 | |
186 | while read pathto posix user group mtime md5sum |
187 | do |
188 | [ -z "${pathto}" ] && continue |
189 | |
190 | # final destination dir of file ${pathto} |
191 | dest_dirname="$(dirname "${MROOT}${pathto}")" |
192 | |
193 | ### small hotfix fix ### |
194 | [ ! -d "${dest_dirname}" ] && install -d "${dest_dirname}" |
195 | |
196 | # check if the file is config_protected |
197 | # ${MROOT} will automatically added if set !! |
198 | is_config_protected "${pathto}" |
199 | retval="$?" |
200 | |
201 | # 0 - not protected # |
202 | # 1 - error # |
203 | # 2 - protected # |
204 | # 3 - protected but masked # |
205 | |
206 | case ${retval} in |
207 | # file is not protected - (over)write it |
208 | 0|3) |
209 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}" |
210 | install -m "${posix}" -o "${user}" -g "${group}" \ |
211 | ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \ |
212 | "${MROOT}${pathto}" |
213 | |
214 | # fix mtime and db |
215 | fix_descriptor ${pkgname}/.files \ |
216 | "${pathto}" \ |
217 | "${posix}" \ |
218 | "${user}" \ |
219 | "${group}" \ |
220 | "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
221 | "${MROOT}${pathto}")" \ |
222 | "${md5sum}" |
223 | ;; |
224 | |
225 | # file is protected, write backup file |
226 | 2) |
227 | if [[ ${VERBOSE} = on ]] |
228 | then |
229 | echo -en "${COLRED}" |
230 | echo -n "! prot " |
231 | echo -en "${COLDEFAULT}" |
232 | echo " === FILE: ${MROOT}${pathto}" |
233 | fi |
234 | filename="$(basename "${pathto}")" |
235 | counter=$(count_protected_files "${pathto}") |
236 | dest_protected="${dest_dirname}/._cfg${counter}_${filename}" |
237 | install -m "${posix}" -o "${user}" -g "${group}" \ |
238 | ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \ |
239 | "${dest_protected}" |
240 | |
241 | # fix mtime and db |
242 | fix_descriptor ${pkgname}/.files \ |
243 | "${pathto}" \ |
244 | "${posix}" \ |
245 | "${user}" \ |
246 | "${group}" \ |
247 | "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
248 | "${dest_protected}")" \ |
249 | "${md5sum}" |
250 | |
251 | # update global MAGE_PROTECT_COUNTER |
252 | (( MAGE_PROTECT_COUNTER++ )) |
253 | export MAGE_PROTECT_COUNTER |
254 | ;; |
255 | esac |
256 | done < ${BUILDDIR}/${pkgname}/.files |
257 | |
258 | # now copy the fixed file over the old one |
259 | [ -f ${BUILDDIR}/${pkgname}/.files_fixed ] && \ |
260 | cp ${BUILDDIR}/${pkgname}/.files{_fixed,} |
261 | |
262 | # very important: unsetting the '§' fieldseperator |
263 | IFS=$'\n' |
264 | } |
265 | |
266 | |
267 | ################################################### |
268 | # function install_symlinks # |
269 | # install_symlinks $PKGNAME # |
270 | ################################################### |
271 | install_symlinks() |
272 | { |
273 | local pkgname="$1" |
274 | local pathto |
275 | local posix |
276 | local link |
277 | local mtime |
278 | local IFS |
279 | |
280 | # sanity checks; abort if not given |
281 | [ -z "${pkgname}" ] && die "install_symlinks() \$pkgname not given." |
282 | |
283 | # check needed global vars |
284 | [ -z "${BUILDDIR}" ] && die "install_symlinks() \$BUILDDIR not set." |
285 | |
286 | [ ! -f ${BUILDDIR}/${pkgname}/.symlinks ] && die "install_symlinks() .symlinks not found" |
287 | |
288 | # delete old files |
289 | [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && rm ${BUILDDIR}/${pkgname}/.symlinks_fixed |
290 | |
291 | # sets fieldseperator to "§" instead of " " |
292 | IFS=§ |
293 | |
294 | while read pathto posix link mtime |
295 | do |
296 | [ -z "${pathto}" ] && continue |
297 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}" |
298 | |
299 | ln -snf "${link}" "${MROOT}${pathto}" |
300 | |
301 | # fix mtime and db |
302 | fix_descriptor ${pkgname}/.symlinks \ |
303 | "${pathto}" \ |
304 | "${posix}" \ |
305 | "${link}" \ |
306 | "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
307 | "${MROOT}${pathto}")" |
308 | |
309 | done < ${BUILDDIR}/${pkgname}/.symlinks |
310 | |
311 | # now copy the fixed file over the old one |
312 | [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \ |
313 | cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,} |
314 | |
315 | # very important: unsetting the '§' fieldseperator |
316 | IFS=$'\n' |
317 | } |
318 | |
319 | |
320 | ################################################### |
321 | # function install_blockdevices # |
322 | # install_blockdevices $PKGNAME # |
323 | ################################################### |
324 | install_blockdevices() |
325 | { |
326 | local pkgname="$1" |
327 | local pathto |
328 | local posix |
329 | local IFS |
330 | |
331 | # sanity checks; abort if not given |
332 | [ -z "${pkgname}" ] && die "install_blockdevices() \$pkgname not given." |
333 | |
334 | # check needed global vars |
335 | [ -z "${BUILDDIR}" ] && die "install_blockdevices() \$BUILDDIR not set." |
336 | |
337 | [ ! -f ${BUILDDIR}/${pkgname}/.pipes ] && die "install_blockdevices() .pipes not found" |
338 | |
339 | # sets fieldseperator to "§" instead of " " |
340 | IFS=§ |
341 | |
342 | while read pathto posix |
343 | do |
344 | [ -z "${pathto}" ] && continue |
345 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}" |
346 | |
347 | mkfifo -m "${posix}" "${MROOT}$pathto" |
348 | done < ${BUILDDIR}/${pkgname}/.pipes |
349 | |
350 | # very important: unsetting the '§' fieldseperator |
351 | IFS=$'\n' |
352 | } |
353 | |
354 | |
355 | ################################################### |
356 | # function install_characterdevices # |
357 | # install_characterdevices $PKGNAME # |
358 | ################################################### |
359 | install_characterdevices() |
360 | { |
361 | local pkgname="$1" |
362 | local pathto |
363 | local posix |
364 | local major |
365 | local minor |
366 | local IFS |
367 | |
368 | # sanity checks; abort if not given |
369 | [ -z "${pkgname}" ] && die "install_characterdevices() \$pkgname not given." |
370 | |
371 | # check needed global vars |
372 | [ -z "${BUILDDIR}" ] && die "install_characterdevices() \$BUILDDIR not set." |
373 | |
374 | [ ! -f ${BUILDDIR}/${pkgname}/.char ] && die "install_characterdevices() .char not found" |
375 | |
376 | # sets fieldseperator to "§" instead of " " |
377 | IFS=§ |
378 | |
379 | while read pathto posix major minor |
380 | do |
381 | [ -z "${pathto}" ] && continue |
382 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}" |
383 | |
384 | mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor} |
385 | done < ${BUILDDIR}/${pkgname}/.char |
386 | |
387 | # very important: unsetting the '§' fieldseperator |
388 | IFS=$'\n' |
389 | } |
390 | |
391 | |
392 | ################################################### |
393 | # function build_doinstall # |
394 | # build_doinstall $PKGNAME # |
395 | # NOTE: this is an wrapper do install packages # |
396 | ################################################### |
397 | build_doinstall() |
398 | { |
399 | local pkgname="$1" |
400 | |
401 | # sanity checks; abort if not given |
402 | [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given." |
403 | |
404 | # this is only a wrapper |
405 | |
406 | # NOTE: |
407 | # !! we use § as field seperator !! |
408 | # doing so prevent us to get errors by filenames with spaces |
409 | |
410 | # create a new mtime reference file |
411 | touch ${BUILDDIR}/${pkgname}/.mtime |
412 | |
413 | install_directories ${pkgname} || die "install directories ${pkgname}" |
414 | install_files ${pkgname} || die "install files ${pkgname}" |
415 | install_symlinks ${pkgname} || die "install symlinks ${pkgname}" |
416 | install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}" |
417 | install_characterdevices ${pkgname} || die "install chardevices ${pkgname}" |
418 | } |
419 | |
420 | |
421 | ################################################### |
422 | # function install_database_entry # |
423 | # install_database_entry $PKGNAME $PKGTYPE # |
424 | # PKGTYPE can be "virtual", "sources" or nothing # |
425 | ################################################### |
426 | install_database_entry() |
427 | { |
428 | local pcat |
429 | local pname |
430 | local pver |
431 | local pbuild |
432 | local pkgtype |
433 | local pkgname |
434 | local magefile |
435 | local dbrecorddir |
436 | local provide |
437 | local i |
438 | |
439 | # very basic getops |
440 | for i in $* |
441 | do |
442 | case $1 in |
443 | --pcat|-c) shift; pcat="$1" ;; |
444 | --pname|-n) shift; pname="$1" ;; |
445 | --pver|-v) shift; pver="$1" ;; |
446 | --pbuild|-b) shift; pbuild="$1" ;; |
447 | --pkgname|-a) shift; pkgname="$1" ;; |
448 | --pkgtype|-t) shift; pkgtype="$1" ;; |
449 | esac |
450 | shift |
451 | done |
452 | |
453 | # sanity checks; abort if not given |
454 | [ -z "${pcat}" ] && die "install_database_entry() \$pcat not given." |
455 | [ -z "${pname}" ] && die "install_database_entry() \$pname not given." |
456 | [ -z "${pver}" ] && die "install_database_entry() \$pver not given." |
457 | [ -z "${pbuild}" ] && die "install_database_entry() \$pbuild not given." |
458 | [ -z "${pkgname}" ] && die "install_database_entry() \$pkgname not given." |
459 | |
460 | # check needed global vars |
461 | [ -z "${MAGEDIR}" ] && die "install_database_entry() \$MAGEDIR not set." |
462 | [ -z "${INSTALLDB}" ] && die "install_database_entry() \$INSTALLDB not set." |
463 | |
464 | # set needed vars |
465 | magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage" |
466 | dbrecorddir="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}" |
467 | |
468 | # abort if mage file not exists |
469 | [ ! -f ${magefile} ] && die "install_database_entry() ${magefile} not exist." |
470 | |
471 | # add package to database |
472 | install -d ${dbrecorddir} |
473 | |
474 | # install mage-file to database |
475 | install -m 0644 -o root -g root ${magefile} ${dbrecorddir} |
476 | |
477 | # create fake file descriptors |
478 | # used by virtual and source packages |
479 | for i in .dirs .symlinks .files .pipes .char |
480 | do |
481 | touch ${dbrecorddir}/${i} |
482 | done |
483 | |
484 | # put the category to database |
485 | echo ${pcat} > ${dbrecorddir}/.categorie |
486 | |
487 | # now install PKGTYPE specific files |
488 | case ${pkgtype} in |
489 | virtual) touch ${dbrecorddir}/.virtual ;; |
490 | sources) touch ${dbrecorddir}/.sources ;; |
491 | *) |
492 | # !move! .mtime to database (only mv modifies not the mtime!!) |
493 | mv ${BUILDDIR}/${pkgname}/.mtime ${dbrecorddir}/.mtime |
494 | |
495 | # normal packages needs these files |
496 | local i |
497 | for i in .char .dirs .files .pipes .symlinks |
498 | do |
499 | install -m 0644 ${BUILDDIR}/${pkgname}/${i} \ |
500 | ${dbrecorddir}/${i} |
501 | done |
502 | ;; |
503 | esac |
504 | |
505 | # last but not least register virtuals |
506 | provide="$(get_value_from_magefile PROVIDE ${magefile})" |
507 | if [ -n "${provide}" ] |
508 | then |
509 | for i in ${provide} |
510 | do |
511 | virtuals_add "${i}" "${pcat}/${pname}" |
512 | done |
513 | fi |
514 | } |
515 | |
516 | |
517 | ################################################### |
518 | # function remove_database_entry # |
519 | # remove_database_entry $PKGNAME $PKGTYPE # |
520 | # PKGTYPE can be "virtual", "sources" or nothing # |
521 | ################################################### |
522 | remove_database_entry() |
523 | { |
524 | local pcat |
525 | local pname |
526 | local pver |
527 | local pbuild |
528 | local magefile |
529 | local dbrecorddir |
530 | local provide |
531 | local i |
532 | |
533 | # very basic getops |
534 | for i in $* |
535 | do |
536 | case $1 in |
537 | --pcat|-c) shift; pcat="$1" ;; |
538 | --pname|-n) shift; pname="$1" ;; |
539 | --pver|-v) shift; pver="$1" ;; |
540 | --pbuild|-b) shift; pbuild="$1" ;; |
541 | esac |
542 | shift |
543 | done |
544 | |
545 | # sanity checks; abort if not given |
546 | [ -z "${pcat}" ] && die "remove_database_entry() \$pcat not given." |
547 | [ -z "${pname}" ] && die "remove_database_entry() \$pname not given." |
548 | [ -z "${pver}" ] && die "remove_database_entry() \$pver not given." |
549 | [ -z "${pbuild}" ] && die "remove_database_entry() \$pbuild not given." |
550 | |
551 | # check needed global vars |
552 | [ -z "${INSTALLDB}" ] && die "remove_database_entry() \$INSTALLDB not set." |
553 | |
554 | # set needed vars |
555 | magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" |
556 | dbrecorddir="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}" |
557 | |
558 | # abort if mage file not exists |
559 | [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist." |
560 | |
561 | # remove virtuals only if no other exist |
562 | if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]] |
563 | then |
564 | # first unregister virtuals |
565 | provide="$(get_value_from_magefile PROVIDE ${magefile})" |
566 | if [ -n "${provide}" ] |
567 | then |
568 | for i in ${provide} |
569 | do |
570 | virtuals_del "${i}" "${pcat}/${pname}" |
571 | done |
572 | fi |
573 | fi |
574 | |
575 | # removes database entry |
576 | if [ -d ${dbrecorddir} ] |
577 | then |
578 | rm -rf ${dbrecorddir} |
579 | fi |
580 | } |
581 | |
582 | # get the number of installed packages |
583 | count_installed_pkgs() |
584 | { |
585 | local pcat |
586 | local pname |
587 | local pkg |
588 | local i |
589 | |
590 | # very basic getops |
591 | for i in $* |
592 | do |
593 | case $1 in |
594 | --pcat|-c) shift; pcat="$1" ;; |
595 | --pname|-n) shift; pname="$1" ;; |
596 | esac |
597 | shift |
598 | done |
599 | |
600 | # sanity checks; abort if not given |
601 | [ -z "${pcat}" ] && die "pkg_count() \$pcat not given." |
602 | [ -z "${pname}" ] && die "pkg_count() \$pname not given." |
603 | |
604 | declare -i i=0 |
605 | for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname}) |
606 | do |
607 | (( i++ )) |
608 | #echo "$i ${pkg}" |
609 | done |
610 | |
611 | # return the value |
612 | echo "${i}" |
613 | } |
614 | |
615 | |
616 | ################################################### |
617 | # function compare_mtime # |
618 | # compare_mtime $pcat/$PKGNAME /path/to/file # |
619 | # # |
620 | # returns: # |
621 | # 0=delete me # |
622 | # 1=keep me # |
623 | # # |
624 | # compares mtime of given files in packages # |
625 | ################################################### |
626 | compare_mtime() |
627 | { |
628 | local pfull="$1" |
629 | local pathto="$2" |
630 | local mtime |
631 | local pcat |
632 | local x |
633 | |
634 | mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)" |
635 | |
636 | # if $pathto is a symlink than compare linked binary |
637 | if [ -L "${MROOT}${pathto}" ] |
638 | then |
639 | # readlink -f resolves full path of linked file |
640 | x="$(readlink -f "${MROOT}${pathto}")" |
641 | |
642 | # abort if target does not exists |
643 | # we keep safe here, theoretically the link can removed |
644 | [ ! -e "${x}" ] && return 1 |
645 | |
646 | x=$(stat -c %Y "${x}") |
647 | else |
648 | x=$(stat -c %Y "${MROOT}${pathto}") |
649 | fi |
650 | |
651 | [[ ${mtime} = ${x} ]] && return 0 |
652 | |
653 | # echo "keep me : ${pathto}" |
654 | return 1 |
655 | } |
656 | |
657 | |
658 | ################################################### |
659 | # function remove_symlinks # |
660 | # remove_symlinks $PKGNAME # |
661 | ################################################### |
662 | remove_symlinks() |
663 | { |
664 | local pathto |
665 | local posix |
666 | local link |
667 | local mtime |
668 | local IFS |
669 | local retval |
670 | local pcat |
671 | local pname |
672 | local pver |
673 | local pbuild |
674 | local i |
675 | local pfull |
676 | |
677 | IFS=$'\n' |
678 | |
679 | # very basic getops |
680 | for i in $* |
681 | do |
682 | case $1 in |
683 | --pcat|-c) shift; pcat="$1" ;; |
684 | --pname|-n) shift; pname="$1" ;; |
685 | --pver|-v) shift; pver="$1" ;; |
686 | --pbuild|-b) shift; pbuild="$1" ;; |
687 | esac |
688 | shift |
689 | done |
690 | |
691 | # sanity checks; abort if not given |
692 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." |
693 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." |
694 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." |
695 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." |
696 | pfull="${pcat}/${pname}-${pver}-${pbuild}" |
697 | |
698 | # check needed global vars |
699 | [ -z "${BUILDDIR}" ] && die "remove_symlinks() \$BUILDDIR not set." |
700 | |
701 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.symlinks ] && die "remove_symlinks() .symlinks not found" |
702 | |
703 | # sets fieldseperator to "§" instead of " " |
704 | IFS=§ |
705 | |
706 | while read pathto posix link mtime |
707 | do |
708 | [ -z "${pathto}" ] && continue |
709 | if [ ! -L "${MROOT}${pathto}" ] |
710 | then |
711 | [[ ${VERBOSE} = on ]] && \ |
712 | echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}" |
713 | continue |
714 | fi |
715 | |
716 | # *no* ${MROOT}, will be set internal |
717 | compare_mtime "${pfull}" "${pathto}" |
718 | retval=$? |
719 | # 0=delete me # |
720 | # 1=keep me # |
721 | case ${retval} in |
722 | 0) |
723 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}" |
724 | rm "${MROOT}${pathto}" |
725 | ;; |
726 | |
727 | 1) |
728 | [[ ${VERBOSE} = on ]] && \ |
729 | echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}" |
730 | ;; |
731 | esac |
732 | done < ${MROOT}${INSTALLDB}/${pfull}/.symlinks |
733 | |
734 | # very important: unsetting the '§' fieldseperator |
735 | IFS=$'\n' |
736 | } |
737 | |
738 | |
739 | ################################################### |
740 | # function remove_files # |
741 | # remove_files $PKGNAME # |
742 | ################################################### |
743 | remove_files() |
744 | { |
745 | local pathto |
746 | local posix |
747 | local user |
748 | local group |
749 | local mtime |
750 | local md5sum |
751 | local IFS |
752 | local retval |
753 | local pcat |
754 | local pname |
755 | local pver |
756 | local pbuild |
757 | local i |
758 | local pfull |
759 | |
760 | IFS=$'\n' |
761 | |
762 | # very basic getops |
763 | for i in $* |
764 | do |
765 | case $1 in |
766 | --pcat|-c) shift; pcat="$1" ;; |
767 | --pname|-n) shift; pname="$1" ;; |
768 | --pver|-v) shift; pver="$1" ;; |
769 | --pbuild|-b) shift; pbuild="$1" ;; |
770 | esac |
771 | shift |
772 | done |
773 | |
774 | # sanity checks; abort if not given |
775 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." |
776 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." |
777 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." |
778 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." |
779 | pfull="${pcat}/${pname}-${pver}-${pbuild}" |
780 | |
781 | # check needed global vars |
782 | [ -z "${BUILDDIR}" ] && die "remove_files() \$BUILDDIR not set." |
783 | |
784 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.files ] && die "remove_files() .files not found" |
785 | |
786 | # sets fieldseperator to "§" instead of " " |
787 | IFS=§ |
788 | |
789 | while read pathto posix user group mtime md5sum |
790 | do |
791 | [ -z "${pathto}" ] && continue |
792 | |
793 | if [ ! -e "${MROOT}${pathto}" ] |
794 | then |
795 | [[ ${VERBOSE} = on ]] && \ |
796 | echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}" |
797 | continue |
798 | fi |
799 | |
800 | # *no* ${MROOT}, will be set internal |
801 | compare_mtime "${pfull}" "${pathto}" |
802 | retval=$? |
803 | # 0=delete me # |
804 | # 1=keep me # |
805 | case ${retval} in |
806 | 0) |
807 | # check if the file is config_protected |
808 | # ${MROOT} will automatically added if set !! |
809 | is_config_protected "${pathto}" |
810 | retval="$?" |
811 | |
812 | # 0 - not protected # |
813 | # 1 - error # |
814 | # 2 - protected # |
815 | # 3 - protected but masked # |
816 | |
817 | case ${retval} in |
818 | # file is not protected - delete it |
819 | 0|3) |
820 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}" |
821 | rm "${MROOT}${pathto}" |
822 | ;; |
823 | |
824 | # file is protected, do not delete |
825 | 2) |
826 | if [[ ${VERBOSE} = on ]] |
827 | then |
828 | echo -en "${COLRED}" |
829 | echo -n "! prot " |
830 | echo -en "${COLDEFAULT}" |
831 | echo " === FILE: ${MROOT}${pathto}" |
832 | fi |
833 | ;; |
834 | esac |
835 | ;; |
836 | 1) |
837 | [[ ${VERBOSE} = on ]] && \ |
838 | echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}" |
839 | ;; |
840 | esac |
841 | done < ${MROOT}${INSTALLDB}/${pfull}/.files |
842 | |
843 | # very important: unsetting the '§' fieldseperator |
844 | IFS=$'\n' |
845 | } |
846 | |
847 | |
848 | ################################################### |
849 | # function remove_blockdevices # |
850 | # remove_blockdevices $PKGNAME # |
851 | ################################################### |
852 | remove_blockdevices() |
853 | { |
854 | local pathto |
855 | local posix |
856 | local IFS |
857 | local pcat |
858 | local pname |
859 | local pver |
860 | local pbuild |
861 | local i |
862 | local pfull |
863 | |
864 | IFS=$'\n' |
865 | |
866 | # very basic getops |
867 | for i in $* |
868 | do |
869 | case $1 in |
870 | --pcat|-c) shift; pcat="$1" ;; |
871 | --pname|-n) shift; pname="$1" ;; |
872 | --pver|-v) shift; pver="$1" ;; |
873 | --pbuild|-b) shift; pbuild="$1" ;; |
874 | esac |
875 | shift |
876 | done |
877 | |
878 | # sanity checks; abort if not given |
879 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." |
880 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." |
881 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." |
882 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." |
883 | pfull="${pcat}/${pname}-${pver}-${pbuild}" |
884 | |
885 | # check needed global vars |
886 | [ -z "${BUILDDIR}" ] && die "remove_blockdevices() \$BUILDDIR not set." |
887 | |
888 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.pipes ] && die "remove_blockdevices() .pipes not found" |
889 | |
890 | # sets fieldseperator to "§" instead of " " |
891 | IFS=§ |
892 | |
893 | while read pathto posix |
894 | do |
895 | [ -z "${pathto}" ] && continue |
896 | |
897 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}" |
898 | rm "${MROOT}${pathto}" |
899 | done < ${MROOT}${INSTALLDB}/${pfull}/.pipes |
900 | |
901 | # very important: unsetting the '§' fieldseperator |
902 | IFS=$'\n' |
903 | } |
904 | |
905 | |
906 | ################################################### |
907 | # function remove_characterdevices # |
908 | # remove_characterdevices $PKGNAME # |
909 | ################################################### |
910 | remove_characterdevices() |
911 | { |
912 | local pathto |
913 | local posix |
914 | local IFS |
915 | local pcat |
916 | local pname |
917 | local pver |
918 | local pbuild |
919 | local i |
920 | local pfull |
921 | |
922 | IFS=$'\n' |
923 | |
924 | # very basic getops |
925 | for i in $* |
926 | do |
927 | case $1 in |
928 | --pcat|-c) shift; pcat="$1" ;; |
929 | --pname|-n) shift; pname="$1" ;; |
930 | --pver|-v) shift; pver="$1" ;; |
931 | --pbuild|-b) shift; pbuild="$1" ;; |
932 | esac |
933 | shift |
934 | done |
935 | |
936 | # sanity checks; abort if not given |
937 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." |
938 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." |
939 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." |
940 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." |
941 | pfull="${pcat}/${pname}-${pver}-${pbuild}" |
942 | |
943 | # check needed global vars |
944 | [ -z "${BUILDDIR}" ] && die "remove_characterdevices() \$BUILDDIR not set." |
945 | |
946 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_characterdevices() .char not found" |
947 | |
948 | # sets fieldseperator to "§" instead of " " |
949 | IFS=§ |
950 | |
951 | while read pathto posix |
952 | do |
953 | [ -z "${pathto}" ] && continue |
954 | |
955 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}" |
956 | rm "${MROOT}${pathto}" |
957 | done < ${MROOT}${INSTALLDB}/${pfull}/.char |
958 | |
959 | # very important: unsetting the '§' fieldseperator |
960 | IFS=$'\n' |
961 | } |
962 | |
963 | |
964 | ################################################### |
965 | # function remove_direcories # |
966 | # remove_direcories $PKGNAME # |
967 | ################################################### |
968 | remove_directories() |
969 | { |
970 | local pathto |
971 | local posix |
972 | local IFS |
973 | local pcat |
974 | local pname |
975 | local pver |
976 | local pbuild |
977 | local i |
978 | local pfull |
979 | |
980 | IFS=$'\n' |
981 | |
982 | # very basic getops |
983 | for i in $* |
984 | do |
985 | case $1 in |
986 | --pcat|-c) shift; pcat="$1" ;; |
987 | --pname|-n) shift; pname="$1" ;; |
988 | --pver|-v) shift; pver="$1" ;; |
989 | --pbuild|-b) shift; pbuild="$1" ;; |
990 | esac |
991 | shift |
992 | done |
993 | |
994 | # sanity checks; abort if not given |
995 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." |
996 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." |
997 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." |
998 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." |
999 | pfull="${pcat}/${pname}-${pver}-${pbuild}" |
1000 | |
1001 | # check needed global vars |
1002 | [ -z "${BUILDDIR}" ] && die "remove_directories() \$BUILDDIR not set." |
1003 | |
1004 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found" |
1005 | |
1006 | # sets fieldseperator to "§" instead of " " |
1007 | IFS=§ |
1008 | |
1009 | # reversed order is mandatory ! |
1010 | tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix |
1011 | do |
1012 | [ -z "${pathto}" ] && continue |
1013 | |
1014 | if [ ! -d "${MROOT}${pathto}" ] |
1015 | then |
1016 | [[ ${VERBOSE} = on ]] && \ |
1017 | echo -e "${COLRED}! exist${COLDEFAULT} === DIR: ${MROOT}${pathto}" |
1018 | continue |
1019 | fi |
1020 | |
1021 | # exclude .keep directories |
1022 | if [ -f "${MROOT}${pathto}/.keep" ] |
1023 | then |
1024 | [[ ${VERBOSE} = on ]] && \ |
1025 | echo -e "${COLRED}! .keep${COLDEFAULT} === DIR: ${MROOT}${pathto}" |
1026 | continue |
1027 | fi |
1028 | |
1029 | # monitors /etc/env.d -> env-rebuild |
1030 | [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true |
1031 | |
1032 | # monitors /usr/share/info -> info-rebuild |
1033 | [[ ${pathto} = /usr/share/info ]] && export MAGE_INFO_REBUILD=true |
1034 | |
1035 | if rmdir "${MROOT}${pathto}" &> /dev/null |
1036 | then |
1037 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR: ${MROOT}${pathto}" |
1038 | else |
1039 | [[ ${VERBOSE} = on ]] && \ |
1040 | echo -e "${COLRED}! empty${COLDEFAULT} === DIR: ${MROOT}${pathto}" |
1041 | fi |
1042 | done |
1043 | |
1044 | # very important: unsetting the '§' fieldseperator |
1045 | IFS=$'\n' |
1046 | } |
1047 | |
1048 | |
1049 | ################################################### |
1050 | # function build_douninstall # |
1051 | # build_douninstall $PKGNAME # |
1052 | # NOTE: this is an wrapper do remove packages # |
1053 | ################################################### |
1054 | build_douninstall() |
1055 | { |
1056 | local pcat |
1057 | local pname |
1058 | local pver |
1059 | local pbuild |
1060 | local i |
1061 | |
1062 | # very basic getops |
1063 | for i in $* |
1064 | do |
1065 | case $1 in |
1066 | --pcat|-c) shift; pcat="$1" ;; |
1067 | --pname|-n) shift; pname="$1" ;; |
1068 | --pver|-v) shift; pver="$1" ;; |
1069 | --pbuild|-b) shift; pbuild="$1" ;; |
1070 | esac |
1071 | shift |
1072 | done |
1073 | |
1074 | # sanity checks; abort if not given |
1075 | [ -z "${pcat}" ] && die "build_douninstall() \$pcat not given." |
1076 | [ -z "${pname}" ] && die "build_douninstall() \$pname not given." |
1077 | [ -z "${pver}" ] && die "build_douninstall() \$pver not given." |
1078 | [ -z "${pbuild}" ] && die "build_douninstall() \$pbuild not given." |
1079 | |
1080 | # this is only a wrapper |
1081 | |
1082 | # NOTE: |
1083 | # !! we use § as field seperator !! |
1084 | # doing so prevent us to get errors by filenames with spaces |
1085 | |
1086 | for i in symlinks files blockdevices characterdevices directories |
1087 | do |
1088 | remove_${i} \ |
1089 | --pcat "${pcat}" \ |
1090 | --pname "${pname}" \ |
1091 | --pver "${pver}" \ |
1092 | --pbuild "${pbuild}" \ |
1093 | || die "remove ${i} ${pcat}/${pname}-${pver}-${pbuild}" |
1094 | done |
1095 | } |
1096 | |
1097 | # fetch_packages /path/to/mage/file1 /path/to/mage/file2 |
1098 | fetch_packages() |
1099 | { |
1100 | local list="$@" |
1101 | local pkg |
1102 | local mirr |
1103 | local magefile |
1104 | local md5file |
1105 | local opt |
1106 | local count_current |
1107 | local count_total |
1108 | |
1109 | [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc." |
1110 | |
1111 | # get count of total packages |
1112 | declare -i count_current=0 |
1113 | declare -i count_total=0 |
1114 | |
1115 | for i in ${list}; do (( count_total++ )); done |
1116 | |
1117 | for magefile in ${list} |
1118 | do |
1119 | pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" |
1120 | pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
1121 | |
1122 | (( count_current++ )) |
1123 | xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]" |
1124 | |
1125 | # abort on virtual pkg |
1126 | if [[ ${pkgtype} = virtual ]] |
1127 | then |
1128 | echo -ne " ${COLBLUE}---${COLDEFAULT}" |
1129 | echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
1130 | continue |
1131 | fi |
1132 | |
1133 | # abort on sources pkg |
1134 | if [[ ${pkgtype} = sources ]] |
1135 | then |
1136 | echo -ne " ${COLBLUE}---${COLDEFAULT}" |
1137 | echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
1138 | continue |
1139 | fi |
1140 | |
1141 | # abort if already exist |
1142 | if [ -f ${PKGDIR}/${pkg} ] |
1143 | then |
1144 | echo -ne " ${COLBLUE}***${COLDEFAULT}" |
1145 | echo " fetch complete (${count_current}/${count_total}): ${pkg} ... " |
1146 | continue |
1147 | fi |
1148 | |
1149 | for mirr in ${MIRRORS} |
1150 | do |
1151 | echo -ne " ${COLBLUE}***${COLDEFAULT}" |
1152 | #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... " |
1153 | echo -e " fetching (${count_current}/${count_total}): ${pkg} ... " |
1154 | [[ ${VERBOSE} = off ]] && opt="--quiet" |
1155 | wget \ |
1156 | --passive-ftp \ |
1157 | --tries 3 \ |
1158 | --continue \ |
1159 | --progress bar \ |
1160 | --directory-prefix=${PKGDIR} \ |
1161 | ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg} |
1162 | if [[ $? = 0 ]] |
1163 | then |
1164 | break |
1165 | else |
1166 | continue |
1167 | fi |
1168 | done |
1169 | |
1170 | if [ ! -f ${PKGDIR}/${pkg} ] |
1171 | then |
1172 | die "Could not download ${pkg}" |
1173 | fi |
1174 | done |
1175 | |
1176 | # add a crlf for a better view |
1177 | if [ ${count_total} -gt 1 ]; then echo; fi |
1178 | } |
1179 | |
1180 | syncmage() |
1181 | { |
1182 | if [ -z "${RSYNC}" ] |
1183 | then |
1184 | die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc." |
1185 | fi |
1186 | |
1187 | local i |
1188 | for i in ${RSYNC} |
1189 | do |
1190 | rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR} |
1191 | if [[ $? = 0 ]] |
1192 | then |
1193 | break |
1194 | else |
1195 | continue |
1196 | fi |
1197 | done |
1198 | |
1199 | # clean up backup files (foo~) |
1200 | find ${MAGEDIR} -name *~ -exec rm '{}' ';' |
1201 | |
1202 | # check if an newer mage version is available |
1203 | is_newer_mage_version_available |
1204 | } |
1205 | |
1206 | cleanpkg() |
1207 | { |
1208 | if [ -d "${PKGDIR}" ] |
1209 | then |
1210 | echo -n "Removing downloaded packages... " |
1211 | rm -rf ${PKGDIR}/* |
1212 | echo "done." |
1213 | fi |
1214 | } |
1215 | |
1216 | xtitle() |
1217 | { |
1218 | if [[ ${TERM} = xterm ]] |
1219 | then |
1220 | echo -ne "\033]0;Mage: $1\007" |
1221 | fi |
1222 | return 0 |
1223 | } |
1224 | |
1225 | |
1226 | xtitleclean() |
1227 | { |
1228 | if [[ ${TERM} = xterm ]] |
1229 | then |
1230 | echo -ne "\033]0;\007" |
1231 | fi |
1232 | return 0 |
1233 | } |
1234 | |
1235 | |
1236 | # cuts full pathnames or versioniezed names down to basename |
1237 | choppkgname() |
1238 | { |
1239 | #we want this only if full name was used |
1240 | if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ] |
1241 | then |
1242 | #cuts ARCH and PBUILD |
1243 | #ARCH comes from /etc/mage.rc |
1244 | MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g") |
1245 | |
1246 | #cuts version number |
1247 | MAGENAME=$(basename ${MAGENAME%-*} .mage) |
1248 | fi |
1249 | } |
1250 | |
1251 | # get_categorie $PNAME, returns CATEGORIE |
1252 | # $1=pname |
1253 | # ret 0=ok, 1=not_found |
1254 | pname2pcat() |
1255 | { |
1256 | local pname="$1" |
1257 | local repo="$2" |
1258 | local pcat |
1259 | local categorie |
1260 | |
1261 | for pcat in ${MAGEDIR}/* |
1262 | do |
1263 | if [ -d ${pcat}/${pname} ] |
1264 | then |
1265 | categorie=$(basename ${pcat}) |
1266 | fi |
1267 | done |
1268 | |
1269 | echo "${categorie}" |
1270 | } |
1271 | |
1272 | # check_stable_package /path/to/foo.mage |
1273 | # returns 0=stable 1=unstable |
1274 | check_stable_package() |
1275 | { |
1276 | # first check if this magefile is not blacklisted |
1277 | blacklisted "$1" || return 1 |
1278 | |
1279 | local STATE |
1280 | STATE="$(get_value_from_magefile STATE "$1")" |
1281 | |
1282 | # state testing |
1283 | if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]] |
1284 | then |
1285 | case ${STATE} in |
1286 | testing|stable) return 0 ;; |
1287 | *) return 1 ;; |
1288 | esac |
1289 | fi |
1290 | |
1291 | # state unstable |
1292 | if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]] |
1293 | then |
1294 | case ${STATE} in |
1295 | unstable|testing|stable) return 0 ;; |
1296 | *) return 1 ;; |
1297 | esac |
1298 | fi |
1299 | |
1300 | # no use_state given = stable |
1301 | case ${STATE} in |
1302 | stable) return 0 ;; |
1303 | *) return 1 ;; |
1304 | esac |
1305 | } |
1306 | |
1307 | |
1308 | # get_highest_magefile ${PCAT} ${PNAME} |
1309 | # fake at moment returns only stable pkgs (must set to be one) |
1310 | # return $HIGHEST_MAGEFILE |
1311 | get_highest_magefile() |
1312 | { |
1313 | local HIGHEST_MAGEFILE |
1314 | local PCAT="$1" |
1315 | local PNAME="$2" |
1316 | local magefile |
1317 | |
1318 | for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*) |
1319 | do |
1320 | # we exclude subdirs (for stuff like a md5sum dir) |
1321 | [ -d ${magefile} ] && continue |
1322 | if check_stable_package ${magefile} |
1323 | then |
1324 | HIGHEST_MAGEFILE=${magefile} |
1325 | #for debug only |
1326 | [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" |
1327 | fi |
1328 | done |
1329 | |
1330 | # do not so anything |
1331 | # # stop here if HIGHEST_MAGEFILE is zero |
1332 | # # this package must be unstable or old |
1333 | # if [ -z "${HIGHEST_MAGEFILE}" ] |
1334 | # then |
1335 | # echo |
1336 | # echo -n "All packages named " |
1337 | # echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT} |
1338 | # echo -n " are marked " |
1339 | # echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT} |
1340 | # echo "." |
1341 | # echo "You need to declare USE_UNSTABLE=true to install this." |
1342 | # echo |
1343 | # echo "Example:" |
1344 | # echo " USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}" |
1345 | # echo |
1346 | # echo "Be warned that these packages are not stable and may cause serious problems." |
1347 | # echo "You should know what you are doing, so don't complain about any damage." |
1348 | # echo |
1349 | # return 1 |
1350 | # fi |
1351 | |
1352 | echo "${HIGHEST_MAGEFILE}" |
1353 | return 0 |
1354 | } |
1355 | |
1356 | |
1357 | ################################################### |
1358 | # function is_config_protected # |
1359 | # is_config_protected /path/to/file # |
1360 | # # |
1361 | # returns: # |
1362 | # 0 - not protected # |
1363 | # 1 - error # |
1364 | # 2 - protected # |
1365 | # 3 - protected but masked # |
1366 | # # |
1367 | ################################################### |
1368 | is_config_protected() |
1369 | { |
1370 | local EXPFILE |
1371 | local TEST |
1372 | local PROTECTED |
1373 | local IFS |
1374 | |
1375 | EXPFILE="${MROOT}$1" |
1376 | |
1377 | # file does not exist; it can be written |
1378 | [ ! -e ${EXPFILE} ] && return 0 |
1379 | |
1380 | # to be safe; it may be '§' |
1381 | IFS=' ' |
1382 | |
1383 | # check ob in config protect |
1384 | for i in ${CONFIG_PROTECT} |
1385 | do |
1386 | # ersetzen von $i nur wenn am anfang der variable |
1387 | TEST="${EXPFILE/#${MROOT}${i}/Protected}" |
1388 | if [ "${TEST}" != "${EXPFILE}" ] |
1389 | then |
1390 | # setzen das es protected ist |
1391 | PROTECTED=TRUE |
1392 | |
1393 | # check ob nicht doch maskiert |
1394 | for x in ${CONFIG_PROTECT_MASK} |
1395 | do |
1396 | TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}" |
1397 | if [ "${TEST}" != "${EXPFILE}" ] |
1398 | then |
1399 | PROTECTED=MASKED |
1400 | fi |
1401 | done |
1402 | fi |
1403 | done |
1404 | |
1405 | unset IFS |
1406 | |
1407 | case ${PROTECTED} in |
1408 | TRUE) |
1409 | #echo "I'm protected" |
1410 | return 2 |
1411 | ;; |
1412 | MASKED) |
1413 | #echo "I'm protected, but masked - delete me" |
1414 | return 3 |
1415 | ;; |
1416 | *) |
1417 | #echo "delete me" |
1418 | return 0 |
1419 | ;; |
1420 | esac |
1421 | } |
1422 | |
1423 | |
1424 | ################################################### |
1425 | # function count_protected_files # |
1426 | # count_protected_files /path/to/file # |
1427 | # # |
1428 | # note: prints number of protected files # |
1429 | # exp: 0012 # |
1430 | ################################################### |
1431 | count_protected_files() |
1432 | { |
1433 | ${MLIBDIR}/writeprotected "$1" |
1434 | } |
1435 | |
1436 | # call with |
1437 | # 'get_uninstall_candidates (--pcat cat --protected pcat/pfull) --pname PNAME' |
1438 | # returns /path/to/magefile(s) |
1439 | get_uninstall_candidates() |
1440 | { |
1441 | local search_pname |
1442 | local pkg |
1443 | local pcat |
1444 | local pname |
1445 | local pver |
1446 | local pbuild |
1447 | local list |
1448 | local pcatdir |
1449 | local protected |
1450 | |
1451 | # very basic getops |
1452 | for i in $* |
1453 | do |
1454 | case $1 in |
1455 | --pcat|-c) shift; pcatdir="$1" ;; |
1456 | --pname|-n) shift; search_pname="$1" ;; |
1457 | --protected|-p) shift; protected="$1" ;; |
1458 | esac |
1459 | shift |
1460 | done |
1461 | |
1462 | # it's not good to complain here about empty pnames; better to continue later anyway |
1463 | # # sanity checks; abort if not given |
1464 | # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given." |
1465 | |
1466 | |
1467 | # check needed global vars |
1468 | [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set." |
1469 | |
1470 | # set pcatdir to '*' if empty |
1471 | [ -z "${pcatdir}" ] && pcatdir='*' |
1472 | |
1473 | for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/* |
1474 | do |
1475 | # abort if not a dir |
1476 | [ ! -d ${pkg} ] && continue |
1477 | |
1478 | pname="$(magename2pname ${pkg})" |
1479 | |
1480 | if [[ ${search_pname} = ${pname} ]] |
1481 | then |
1482 | pcat="$(magename2pcat ${pkg} installdb)" |
1483 | pver="$(magename2pver ${pkg})" |
1484 | pbuild="$(magename2pbuild ${pkg})" |
1485 | |
1486 | # exclude proteced |
1487 | [[ ${protected} = ${pcat}/${pname}-${pver}-${pbuild} ]] && continue |
1488 | |
1489 | list="${list} ${pcat}/${pname}-${pver}-${pbuild}" |
1490 | fi |
1491 | done |
1492 | |
1493 | echo "${list}" |
1494 | } |
1495 | |
1496 | # reads virtualdb file |
1497 | #$1 = virtualname; $2 commands: showpkgs, showline |
1498 | #return 0 == installed -> shows installed pkg as well |
1499 | #return 1 == not installed |
1500 | virtuals_read() |
1501 | { |
1502 | local virtualname="$1" |
1503 | local command="$2" |
1504 | local virtline |
1505 | local line x i |
1506 | |
1507 | # parse file to get virtual_name line |
1508 | IFS=$'\n' |
1509 | for line in $(< ${MROOT}${VIRTUALDB_FILE}) |
1510 | do |
1511 | IFS=$' ' |
1512 | for x in ${line} |
1513 | do |
1514 | if [[ ${x} = ${virtualname} ]] |
1515 | then |
1516 | virtline="${line}" |
1517 | [[ ${command} = showline ]] && echo "${line}" |
1518 | fi |
1519 | done |
1520 | IFS=$'\n' |
1521 | done |
1522 | |
1523 | unset IFS |
1524 | |
1525 | # now read the packages linked to VIRTUAL_NAME and output them |
1526 | if [ -n "${virtline}" ] |
1527 | then |
1528 | if [[ ${command} = showpkgs ]] |
1529 | then |
1530 | declare -i x=0 |
1531 | for i in ${virtline} |
1532 | do |
1533 | if [ ${x} -ge 1 ] |
1534 | then |
1535 | echo "${i}" |
1536 | fi |
1537 | ((x++)) |
1538 | done |
1539 | fi |
1540 | return 0 |
1541 | fi |
1542 | return 1 |
1543 | } |
1544 | |
1545 | |
1546 | #add pkg to virtualdb |
1547 | # $1 == virtualname $2= pkgname |
1548 | # retvals: 0=ok,added; 1=error; 3=pkg already in virtual |
1549 | virtuals_add() |
1550 | { |
1551 | local virtualname="$1" |
1552 | local pkgname="$2" |
1553 | local oldline |
1554 | local line i |
1555 | local installed_file |
1556 | local OLDIFS |
1557 | |
1558 | if virtuals_read ${virtualname} |
1559 | then |
1560 | # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already |
1561 | for i in $(virtuals_read ${virtualname} showpkgs) |
1562 | do |
1563 | if [[ ${i} = ${pkgname} ]] |
1564 | then |
1565 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1566 | echo "${pkgname} already linked as ${virtualname} ..." |
1567 | #return 3 |
1568 | return 0 |
1569 | fi |
1570 | done |
1571 | |
1572 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
1573 | echo "updating ${virtualname} entry with ${pkgname} ..." |
1574 | oldline="$(virtuals_read ${virtualname} showline)" |
1575 | |
1576 | # make a backup |
1577 | mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old |
1578 | |
1579 | OLDIFS="${IFS}" |
1580 | IFS=$'\n' |
1581 | for line in $(< ${MROOT}${VIRTUALDB_FILE}.old) |
1582 | do |
1583 | # if the right line, append ${pkgname}, else do nothing |
1584 | if [[ ${line} = ${oldline} ]] |
1585 | then |
1586 | echo "${line} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE} |
1587 | else |
1588 | echo "${line}" >> ${MROOT}${VIRTUALDB_FILE} |
1589 | fi |
1590 | done |
1591 | # unset IFS |
1592 | IFS="${OLDIFS}" |
1593 | else |
1594 | echo -ne "${COLBLUE} >>> ${COLDEFAULT}" |
1595 | echo "register ${pkgname} as ${virtualname} ..." |
1596 | echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE} |
1597 | fi |
1598 | |
1599 | return 0 |
1600 | } |
1601 | |
1602 | #deletes pakages from virtual database |
1603 | #$1 virtualname; $2 pkgname |
1604 | virtuals_del() { |
1605 | |
1606 | local virtualname="$1" |
1607 | local pkgname="$2" |
1608 | local oldline |
1609 | local method |
1610 | local line i x |
1611 | local pkg_installed |
1612 | local OLDIFS |
1613 | |
1614 | # first check if exists |
1615 | if virtuals_read ${virtualname} |
1616 | then |
1617 | # get method -> delall or update and check if ${PKG_NAME} exists in ${VIRTUAL_NAME} |
1618 | declare -i x=0 |
1619 | for i in $(virtuals_read ${virtualname} showpkgs) |
1620 | do |
1621 | if [[ ${i} = ${pkgname} ]] |
1622 | then |
1623 | pkg_installed=true |
1624 | fi |
1625 | ((x++)) |
1626 | done |
1627 | |
1628 | # abort if not installed |
1629 | if [[ ${pkg_installed} != true ]] |
1630 | then |
1631 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1632 | echo "${pkgname} does not exists in ${virtualname}." |
1633 | return 0 |
1634 | fi |
1635 | |
1636 | if [ ${x} -ge 2 ] |
1637 | then |
1638 | method=update |
1639 | else |
1640 | method=delall |
1641 | fi |
1642 | |
1643 | # get the complete line |
1644 | oldline="$(virtuals_read ${virtualname} showline)" |
1645 | |
1646 | # make a backup of the db |
1647 | mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old |
1648 | |
1649 | # parse virtualdb |
1650 | OLDIFS="${IFS}" |
1651 | IFS=$'\n' |
1652 | for line in $(< ${VIRTUALDB_FILE}.old) |
1653 | do |
1654 | if [[ ${line} = ${oldline} ]] |
1655 | then |
1656 | #delall or update? |
1657 | case ${method} in |
1658 | update) |
1659 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
1660 | echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..." |
1661 | # del PKG_NAME from line |
1662 | echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE} |
1663 | ;; |
1664 | delall) |
1665 | echo -ne "${COLBLUE} <<< ${COLDEFAULT}" |
1666 | echo "Deleting ${virtualname} in virtual database ..." |
1667 | # continue; do not write anything |
1668 | continue |
1669 | ;; |
1670 | esac |
1671 | else |
1672 | echo "${line}" >> ${VIRTUALDB_FILE} |
1673 | fi |
1674 | done |
1675 | # unset IFS |
1676 | IFS="${OLDIFS}" |
1677 | else |
1678 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1679 | echo "${virtualname} does not exists in virtual database." |
1680 | fi |
1681 | } |
1682 | |
1683 | # gets real pkgname from virtuals.default |
1684 | #$1=VIRTUAL_NAME; returns PKG_NAME |
1685 | default_virtualname_to_pkgname() |
1686 | { |
1687 | local VIRTUAL_NAME PKG_NAME db_virtualname db_pkgname |
1688 | |
1689 | VIRTUAL_NAME=$1 |
1690 | |
1691 | while read db_virtualname db_pkgname |
1692 | do |
1693 | if [ "${db_virtualname}" == "${VIRTUAL_NAME}" ] |
1694 | then |
1695 | PKG_NAME="${db_pkgname}" |
1696 | fi |
1697 | done << EOF |
1698 | $(< ${VIRTUALDB_DEFAULTS}) |
1699 | EOF |
1700 | |
1701 | if [ -n "${PKG_NAME}" ] |
1702 | then |
1703 | echo "${PKG_NAME}" |
1704 | fi |
1705 | } |
1706 | |
1707 | minclude() |
1708 | { |
1709 | local i |
1710 | |
1711 | if [[ -n $@ ]] |
1712 | then |
1713 | for i in $@ |
1714 | do |
1715 | [[ ${MAGEDEBUG} = on ]] && \ |
1716 | echo "--- Including ${MAGEDIR}/include/${i}.minc" |
1717 | source ${MAGEDIR}/include/${i}.minc |
1718 | done |
1719 | [[ ${MAGEDEBUG} = on ]] && echo |
1720 | fi |
1721 | } |
1722 | |
1723 | sminclude() |
1724 | { |
1725 | local i |
1726 | |
1727 | if [ -n "$@" ] |
1728 | then |
1729 | for i in $@ |
1730 | do |
1731 | echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
1732 | source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
1733 | done |
1734 | echo |
1735 | fi |
1736 | } |
1737 | |
1738 | # checks if an newer mage version is available |
1739 | is_newer_mage_version_available() |
1740 | { |
1741 | local newest_mage |
1742 | local installed_mage |
1743 | |
1744 | newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)" |
1745 | installed_mage="$(magequery -n mage | cut -d' ' -f5)" |
1746 | |
1747 | if [[ ${newest_mage} > ${installed_mage} ]] |
1748 | then |
1749 | echo |
1750 | echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT} |
1751 | echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT} |
1752 | echo "It is recommened to install this newer version" |
1753 | echo "or your current system installation may break." |
1754 | echo |
1755 | echo -en "Please update mage by running " |
1756 | echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT} |
1757 | echo |
1758 | fi |
1759 | } |
1760 | |
1761 | |
1762 | # returns pname from pkgname |
1763 | # pkgname2pname $PKGNAME |
1764 | pkgname2pname() |
1765 | { |
1766 | local pname |
1767 | |
1768 | pname="${1%-*-*-*}" |
1769 | echo "${pname}" |
1770 | } |
1771 | |
1772 | # returns pver from pkgname |
1773 | # pkgname2pver $PKGNAME |
1774 | pkgname2pver() |
1775 | { |
1776 | local i pver |
1777 | |
1778 | i="${1/$(pkgname2pname $1)-/}" |
1779 | pver="${i%-*-*}" |
1780 | echo "${pver}" |
1781 | } |
1782 | |
1783 | # returns pbuild from pkgname |
1784 | # pkgname2pbuild $PKGNAME |
1785 | pkgname2pbuild() |
1786 | { |
1787 | local pbuild |
1788 | |
1789 | pbuild="${1##*-}" |
1790 | echo "${pbuild}" |
1791 | } |
1792 | |
1793 | # returns parch from pkgname |
1794 | # pkgname2parch $PKGNAME |
1795 | pkgname2parch() |
1796 | { |
1797 | local i x parch |
1798 | |
1799 | i="${1%-*-*}-" |
1800 | x="${1%-*}" |
1801 | parch="${x/${i}/}" |
1802 | echo "${parch}" |
1803 | } |
1804 | |
1805 | # returns pname from magename |
1806 | # magename2pname /PATH/TO/MAGE/FILE |
1807 | magename2pname() |
1808 | { |
1809 | local i pname |
1810 | |
1811 | i="$(basename $1 .mage)" |
1812 | pname="${i%-*-*}" |
1813 | echo "${pname}" |
1814 | } |
1815 | |
1816 | # returns pver from magename |
1817 | # magename2pver /PATH/TO/MAGE/FILE |
1818 | magename2pver() |
1819 | { |
1820 | local i pver |
1821 | |
1822 | i="$(basename $1 .mage)" |
1823 | i="${i/$(magename2pname $1)-/}" |
1824 | pver="${i%-*}" |
1825 | echo "${pver}" |
1826 | } |
1827 | |
1828 | # returns pbuild from magename |
1829 | # magename2pbuild /PATH/TO/MAGE/FILE |
1830 | magename2pbuild() |
1831 | { |
1832 | local i pbuild |
1833 | |
1834 | i="$(basename $1 .mage)" |
1835 | pbuild="${i##*-}" |
1836 | echo "${pbuild}" |
1837 | } |
1838 | |
1839 | # returns pcat from magename |
1840 | # magename2pcat /PATH/TO/MAGE/FILE |
1841 | magename2pcat() |
1842 | { |
1843 | local i pcat |
1844 | |
1845 | if [[ ${2} = installdb ]] |
1846 | then |
1847 | # go 1 dir back |
1848 | i="${1%/*}" |
1849 | else |
1850 | # go 2 dirs back |
1851 | i="${1%/*/*}" |
1852 | fi |
1853 | |
1854 | # get basename |
1855 | pcat="${i##*/}" |
1856 | echo "${pcat}" |
1857 | } |
1858 | |
1859 | # returns pcat from DEPEND (without operand ! PCAT/PNAME-VERSION) |
1860 | # dep2pcat DEPEND |
1861 | dep2pcat() |
1862 | { |
1863 | local pcat |
1864 | |
1865 | pcat="${1%/*}" |
1866 | echo "${pcat}" |
1867 | } |
1868 | |
1869 | # returns pname from DEPEND (without operand ! PCAT/PNAME-VERSION) |
1870 | # $2=virtual is used to resolv VDEPEND from virtual packages |
1871 | # dep2pcat DEPEND (virtual) |
1872 | dep2pname() |
1873 | { |
1874 | local pname |
1875 | |
1876 | pname="${1##*/}" |
1877 | |
1878 | # cut version only if not virtual or it will cut the name |
1879 | if [[ $(dep2pcat $1) != virtual ]] && \ |
1880 | [[ $2 != virtual ]] |
1881 | then |
1882 | pname="${pname%-*}" |
1883 | fi |
1884 | |
1885 | echo "${pname}" |
1886 | } |
1887 | |
1888 | dep2highest_magefile() |
1889 | { |
1890 | local pcat |
1891 | local pname |
1892 | local magefile |
1893 | local installed_virtuals |
1894 | |
1895 | pcat="$(dep2pcat $1)" |
1896 | pname="$(dep2pname $1)" |
1897 | |
1898 | if [[ ${pcat} = virtual ]] |
1899 | then |
1900 | # first check if virtual is already installed |
1901 | installed_virtuals="$(virtuals_read ${pcat}/${pname} showpkgs)" |
1902 | if [ -n "${installed_virtuals}" ] |
1903 | then |
1904 | for vpkg in ${installed_virtuals} |
1905 | do |
1906 | realpkgname="${vpkg}" |
1907 | virtualpkgname="${pcat}/${pname}" |
1908 | pcat="$(dep2pcat ${realpkgname})" |
1909 | pname="$(dep2pname ${realpkgname} virtual)" |
1910 | done |
1911 | else |
1912 | # choose one from virtualdb defaults (virtuals.defaults) |
1913 | realpkgname="$(default_virtualname_to_pkgname ${pcat}/${pname})" |
1914 | virtualpkgname="${pcat}/${pname}" |
1915 | pcat="$(dep2pcat ${realpkgname})" |
1916 | pname="$(dep2pname ${realpkgname} virtual)" |
1917 | fi |
1918 | fi |
1919 | |
1920 | magefile="$(get_highest_magefile ${pcat} ${pname})" |
1921 | echo "${magefile}" |
1922 | } |
1923 | |
1924 | # is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} |
1925 | is_installed() |
1926 | { |
1927 | local fullpkgname="$1" |
1928 | |
1929 | # return 0 if installed |
1930 | [ -d ${MROOT}${INSTALLDB}/${fullpkgname} ] && return 0 |
1931 | |
1932 | return 1 |
1933 | } |
1934 | |
1935 | install_packages() |
1936 | { |
1937 | local list="$@" |
1938 | local pkg |
1939 | local pcat |
1940 | local pname |
1941 | local pver |
1942 | local pbuild |
1943 | local total_pkgs |
1944 | local current_pkg |
1945 | local src_install |
1946 | local uninstall_list |
1947 | |
1948 | # check for --src-install |
1949 | if [[ $1 = --src-install ]] |
1950 | then |
1951 | # remove --src-install from list |
1952 | list=${list/--src-install/} |
1953 | # enable src-install |
1954 | src_install="--src-install" |
1955 | fi |
1956 | |
1957 | # reset MAGE_PROTECT_COUNTER |
1958 | declare -i MAGE_PROTECT_COUNTER=0 |
1959 | export MAGE_PROTECT_COUNTER |
1960 | |
1961 | # get count of total packages |
1962 | declare -i total_pkgs=0 |
1963 | declare -i current_pkg=0 |
1964 | for i in ${list}; do (( total_pkgs++ )); done |
1965 | |
1966 | echo |
1967 | |
1968 | if [[ -n ${MROOT} ]] |
1969 | then |
1970 | echo -ne ${COLRED} |
1971 | echo "!! installing in MROOT=${MROOT}" |
1972 | echo -ne ${COLDEFAULT} |
1973 | echo |
1974 | fi |
1975 | |
1976 | for pkg in ${list} |
1977 | do |
1978 | (( current_pkg++ )) |
1979 | pcat=$(magename2pcat ${pkg}) |
1980 | pname=$(magename2pname ${pkg}) |
1981 | pver=$(magename2pver ${pkg}) |
1982 | pbuild=$(magename2pbuild ${pkg}) |
1983 | |
1984 | mage_install \ |
1985 | --pcat ${pcat} \ |
1986 | --pname ${pname} \ |
1987 | --pver ${pver} \ |
1988 | --pbuild ${pbuild} \ |
1989 | --count-total ${total_pkgs} \ |
1990 | --count-current ${current_pkg} \ |
1991 | ${src_install} |
1992 | |
1993 | # check for allready installed packages and remove them |
1994 | # except the package we have installed |
1995 | uninstall_list="$(get_uninstall_candidates \ |
1996 | --pcat "${pcat}" \ |
1997 | --pname "${pname}" \ |
1998 | --protected ${pcat}/${pname}-${pver}-${pbuild})" |
1999 | |
2000 | # uninstall all packges in uninstall_list if not empty |
2001 | if [ -n "${uninstall_list}" ] |
2002 | then |
2003 | echo |
2004 | uninstall_packages ${uninstall_list} \ |
2005 | || die "install_packges() uninstalling not-needed." |
2006 | fi |
2007 | |
2008 | # crlf for better view in VERBOSE mode |
2009 | #if [[ ${VERBOSE} = on ]]; then echo; fi |
2010 | echo |
2011 | done |
2012 | |
2013 | #echo "DEBUG MAGE_PROTECT_COUNTER=${MAGE_PROTECT_COUNTER}" |
2014 | show_etc_update_mesg |
2015 | } |
2016 | |
2017 | # get_value_from_magefile VARIABLE |
2018 | # returns the content of this VAR |
2019 | get_value_from_magefile() |
2020 | { |
2021 | local var="$1" |
2022 | local magefile="$2" |
2023 | local value |
2024 | |
2025 | [[ -z ${var} ]] && return 1 |
2026 | [[ -z ${magefile} ]] && return 1 |
2027 | |
2028 | # local all possible vars of a mage file |
2029 | # to prevent bad issues |
2030 | local PKGNAME |
2031 | local STATE |
2032 | local DESCRIPTION |
2033 | local HOMEPAGE |
2034 | local DEPEND |
2035 | local SDEPEND |
2036 | local PROVIDE |
2037 | local PKGTYPE |
2038 | local preinstall |
2039 | local postinstall |
2040 | local preremove |
2041 | local postremove |
2042 | |
2043 | # sanity checks |
2044 | [ -f ${magefile} ] && source ${magefile} || \ |
2045 | die "get_value_from_magefile: ${magefile} not found." |
2046 | [ -z "${var}" ] && die "get_value_from_magefile: \$var not given." |
2047 | |
2048 | source ${magefile} |
2049 | eval value=\$$(echo ${var}) |
2050 | echo "${value}" |
2051 | |
2052 | # unset these functions |
2053 | unset -f preinstall |
2054 | unset -f postinstall |
2055 | unset -f preremove |
2056 | unset -f postremove |
2057 | } |
2058 | |
2059 | mage_install() |
2060 | { |
2061 | # local all possible vars of a mage file |
2062 | # to prevent bad issues |
2063 | local PKGNAME |
2064 | local STATE |
2065 | local DESCRIPTION |
2066 | local HOMEPAGE |
2067 | local DEPEND |
2068 | local SDEPEND |
2069 | local PROVIDE |
2070 | local PKGTYPE |
2071 | local preinstall |
2072 | local postinstall |
2073 | local preremove |
2074 | local postremove |
2075 | |
2076 | local pcat |
2077 | local pname |
2078 | local pver |
2079 | local pbuild |
2080 | local count_total |
2081 | local count_current |
2082 | local magefile |
2083 | local src_install |
2084 | |
2085 | # very basic getops |
2086 | for i in $* |
2087 | do |
2088 | case $1 in |
2089 | --pcat|-c) shift; pcat="$1" ;; |
2090 | --pname|-n) shift; pname="$1" ;; |
2091 | --pver|-v) shift; pver="$1" ;; |
2092 | --pbuild|-b) shift; pbuild="$1" ;; |
2093 | --count-total) shift; count_total="$1" ;; |
2094 | --count-current) shift; count_current="$1" ;; |
2095 | --src-install|-s) shift; src_install=true ;; |
2096 | esac |
2097 | shift |
2098 | done |
2099 | |
2100 | # sanity checks; abort if not given |
2101 | [ -z "${pcat}" ] && die "mage_install() \$pcat not given." |
2102 | [ -z "${pname}" ] && die "mage_install() \$pname not given." |
2103 | [ -z "${pver}" ] && die "mage_install() \$pver not given." |
2104 | [ -z "${pbuild}" ] && die "mage_install() \$pbuild not given." |
2105 | |
2106 | # check needed global vars |
2107 | [ -z "${MAGEDIR}" ] && die "mage_install() \$MAGEDIR not set." |
2108 | [ -z "${INSTALLDB}" ] && die "mage_install() \$INSTALLDB not set." |
2109 | [ -z "${BUILDDIR}" ] && die "mage_install() \$BUILDDIR not set." |
2110 | |
2111 | xtitle "[ (${count_current}/${count_total}) Installing ${pcat}/${pname}-${pver}-${pbuild} ]" |
2112 | echo -ne "${COLBLUE} >>> ${COLDEFAULT}" |
2113 | echo -n "installing (${count_current}/${count_total}): " |
2114 | echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
2115 | echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}" |
2116 | |
2117 | magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage" |
2118 | source ${magefile} |
2119 | |
2120 | # abort on sources if no srcinstall |
2121 | if [[ ${PKGTYPE} = sources ]] && [[ ${src_install} != true ]] |
2122 | then |
2123 | echo |
2124 | echo -e "This Package is a Source Package." |
2125 | echo |
2126 | echo -e "Only 'srcinstall' works with this type of packages" |
2127 | echo -en "If you have done a srcinstall before, " |
2128 | echo -e "you will find the files in /usr/src." |
2129 | echo |
2130 | exit 1 |
2131 | fi |
2132 | |
2133 | ## preinstall scripts |
2134 | if [ -n "$(typeset -f preinstall)" ] |
2135 | then |
2136 | echo -e " ${COLBLUE}***${COLDEFAULT} running preinstall ... " |
2137 | preinstall |
2138 | unset preinstall |
2139 | fi |
2140 | |
2141 | if [[ ${src_install} = true ]] |
2142 | then |
2143 | local smage2file |
2144 | # check needed global vars |
2145 | [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not set." |
2146 | [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not set." |
2147 | [ -z "${BINDIR}" ] && die "\$BINDIR not set." |
2148 | |
2149 | # build the package first |
2150 | if [[ ${MAGEDEBUG} = on ]] |
2151 | then |
2152 | echo M:${pname} |
2153 | echo V:${pver} |
2154 | echo B:${pbuild} |
2155 | fi |
2156 | |
2157 | smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2 |
2158 | if [ -f "${smage2file}" ] |
2159 | then |
2160 | echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... " |
2161 | smage2 ${smage2file} || die "compile failed" |
2162 | else |
2163 | echo |
2164 | echo "$(basename ${SMAGEFILE}) not found." |
2165 | echo "update your smage-tree and try it again." |
2166 | echo |
2167 | die |
2168 | fi |
2169 | fi |
2170 | |
2171 | if [[ ${PKGTYPE} != virtual ]] && \ |
2172 | [[ ${PKGTYPE} != sources ]] |
2173 | then |
2174 | echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... " |
2175 | build_doinstall ${PKGNAME} |
2176 | fi |
2177 | |
2178 | ## postinstall scripts |
2179 | if [ -n "$(typeset -f postinstall)" ] |
2180 | then |
2181 | echo -e " ${COLBLUE}***${COLDEFAULT} running postinstall ... " |
2182 | postinstall |
2183 | unset postinstall |
2184 | fi |
2185 | |
2186 | # install a database entry |
2187 | install_database_entry \ |
2188 | --pcat "${pcat}" \ |
2189 | --pname "${pname}" \ |
2190 | --pver "${pver}" \ |
2191 | --pbuild "${pbuild}" \ |
2192 | --pkgname "${PKGNAME}" \ |
2193 | --pkgtype "${PKGTYPE}" \ |
2194 | || die "error in mage_install() running install_database_entry()." |
2195 | |
2196 | # remove the package dir now |
2197 | if [ -d ${BUILDDIR}/${PKGNAME} ] |
2198 | then |
2199 | rm -rf ${BUILDDIR}/${PKGNAME} |
2200 | fi |
2201 | |
2202 | # rebuilds toplevel info node |
2203 | if [[ ${MAGE_INFO_REBUILD} = true ]] |
2204 | then |
2205 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2206 | echo -n "rebuilding top-level info node ... " |
2207 | ${MLIBDIR}/mkinfodir ${MROOT}/usr/share/info \ |
2208 | > ${MROOT}/usr/share/info/dir && \ |
2209 | echo "done." || echo "failure." |
2210 | unset MAGE_INFO_REBUILD |
2211 | fi |
2212 | |
2213 | # rebuilds the enviroment with the content of /etc/env.d |
2214 | if [[ ${MAGE_ENV_REBUILD} = true ]] |
2215 | then |
2216 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2217 | echo -n "rebuilding environment ... " |
2218 | ${MLIBDIR}/env-rebuild.sh > /dev/null && \ |
2219 | echo "done." || echo "failure." |
2220 | unset MAGE_ENV_REBUILD |
2221 | fi |
2222 | |
2223 | xtitleclean |
2224 | |
2225 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2226 | echo -n "package " |
2227 | # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
2228 | # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " |
2229 | echo "successfully installed." |
2230 | |
2231 | # unset these functions |
2232 | unset -f preinstall |
2233 | unset -f postinstall |
2234 | unset -f preremove |
2235 | unset -f postremove |
2236 | } |
2237 | |
2238 | md5sum_packages() |
2239 | { |
2240 | local list="$@" |
2241 | local magefile |
2242 | local pcat |
2243 | local pname |
2244 | local pkgname |
2245 | local pkgfile |
2246 | local pkgtype |
2247 | local count_current |
2248 | local count_total |
2249 | |
2250 | # get count of total packages |
2251 | declare -i count_current=0 |
2252 | declare -i count_total=0 |
2253 | |
2254 | for i in ${list}; do (( count_total++ )); done |
2255 | |
2256 | for magefile in ${list} |
2257 | do |
2258 | pcat=$(magename2pcat ${magefile}) |
2259 | pname=$(magename2pname ${magefile}) |
2260 | pkgname="$(get_value_from_magefile PKGNAME ${magefile})" |
2261 | md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" |
2262 | pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" |
2263 | pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
2264 | |
2265 | (( count_current++ )) |
2266 | xtitle "[ (${count_current}/${count_total}) MD5SUM: ${pkgfile} ]" |
2267 | |
2268 | # abort on virtual pkg |
2269 | if [[ ${pkgtype} = virtual ]] |
2270 | then |
2271 | echo -ne " ${COLBLUE}---${COLDEFAULT}" |
2272 | echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " |
2273 | continue |
2274 | fi |
2275 | |
2276 | # abort on sources pkg |
2277 | if [[ ${pkgtype} = sources ]] |
2278 | then |
2279 | echo -ne " ${COLBLUE}---${COLDEFAULT}" |
2280 | echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " |
2281 | continue |
2282 | fi |
2283 | |
2284 | if [ -f "${md5file}" ] |
2285 | then |
2286 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2287 | echo -ne "checking md5sum (${count_current}/${count_total}): " |
2288 | ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed" |
2289 | else |
2290 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2291 | echo -e "!! no md5sum file found for ${pkgfile} :(" |
2292 | fi |
2293 | done |
2294 | |
2295 | # add a crlf for a better view |
2296 | if [ ${count_total} -gt 1 ]; then echo; fi |
2297 | } |
2298 | |
2299 | ## uninstall_packages ulist |
2300 | uninstall_packages() |
2301 | { |
2302 | local list="$@" |
2303 | local pcat |
2304 | local pname |
2305 | local pver |
2306 | local pbuild |
2307 | local can_pcat |
2308 | local can_pname |
2309 | local can_ver_list |
2310 | |
2311 | if [[ -n ${MROOT} ]] |
2312 | then |
2313 | echo -ne ${COLRED} |
2314 | echo "!! uninstalling from MROOT=${MROOT}" |
2315 | echo -ne ${COLDEFAULT} |
2316 | echo |
2317 | fi |
2318 | |
2319 | # generate a candidates list |
2320 | for pkg in ${list} |
2321 | do |
2322 | pcat=$(dep2pcat ${pkg}) |
2323 | pname=$(magename2pname ${pkg}) |
2324 | pver=$(magename2pver ${pkg}) |
2325 | pbuild=$(magename2pbuild ${pkg}) |
2326 | can_pcat="${pcat}" |
2327 | can_pname="${pname}" |
2328 | |
2329 | if [ -z "${can_ver_list}" ] |
2330 | then |
2331 | can_ver_list=" ${pver}-${pbuild}" |
2332 | else |
2333 | can_ver_list="${can_ver_list}, ${pver}-${pbuild}" |
2334 | fi |
2335 | done |
2336 | |
2337 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2338 | echo "following candidate(s) will be removed:" |
2339 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2340 | echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}" |
2341 | echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}" |
2342 | echo |
2343 | if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ] |
2344 | then |
2345 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2346 | echo "( Press [CTRL+C] to abort )" |
2347 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2348 | echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..." |
2349 | for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--)) |
2350 | do |
2351 | echo -ne "${COLRED} ${i}${COLDEFAULT}" |
2352 | sleep 1 |
2353 | done |
2354 | echo |
2355 | echo |
2356 | fi |
2357 | |
2358 | for pkg in ${list} |
2359 | do |
2360 | pcat=$(dep2pcat ${pkg}) |
2361 | pname=$(magename2pname ${pkg}) |
2362 | pver=$(magename2pver ${pkg}) |
2363 | pbuild=$(magename2pbuild ${pkg}) |
2364 | |
2365 | mage_uninstall \ |
2366 | --pcat ${pcat} \ |
2367 | --pname ${pname} \ |
2368 | --pver ${pver} \ |
2369 | --pbuild ${pbuild} \ |
2370 | --count-total ${total_pkgs} \ |
2371 | --count-current ${current_pkg} \ |
2372 | ${src_install} |
2373 | |
2374 | # crlf for better view in VERBOSE mode |
2375 | #if [[ ${VERBOSE} = on ]]; then echo; fi |
2376 | echo |
2377 | done |
2378 | } |
2379 | |
2380 | mage_uninstall() |
2381 | { |
2382 | # local all possible vars of a mage file |
2383 | # to prevent bad issues |
2384 | local PKGNAME |
2385 | local STATE |
2386 | local DESCRIPTION |
2387 | local HOMEPAGE |
2388 | local DEPEND |
2389 | local SDEPEND |
2390 | local PROVIDE |
2391 | local PKGTYPE |
2392 | local preinstall |
2393 | local postinstall |
2394 | local preremove |
2395 | local postremove |
2396 | |
2397 | local pcat |
2398 | local pname |
2399 | local pver |
2400 | local pbuild |
2401 | local magefile |
2402 | local i |
2403 | |
2404 | # very basic getops |
2405 | for i in $* |
2406 | do |
2407 | case $1 in |
2408 | --pcat|-c) shift; pcat="$1" ;; |
2409 | --pname|-n) shift; pname="$1" ;; |
2410 | --pver|-v) shift; pver="$1" ;; |
2411 | --pbuild|-b) shift; pbuild="$1" ;; |
2412 | esac |
2413 | shift |
2414 | done |
2415 | |
2416 | # sanity checks; abort if not given |
2417 | [ -z "${pcat}" ] && die "mage_uninstall() \$pcat not given." |
2418 | [ -z "${pname}" ] && die "mage_uninstall() \$pname not given." |
2419 | [ -z "${pver}" ] && die "mage_uninstall() \$pver not given." |
2420 | [ -z "${pbuild}" ] && die "mage_uninstall() \$pbuild not given." |
2421 | |
2422 | # check needed global vars |
2423 | [ -z "${MAGEDIR}" ] && die "mage_uninstall() \$MAGEDIR not set." |
2424 | [ -z "${INSTALLDB}" ] && die "mage_uninstall() \$INSTALLDB not set." |
2425 | [ -z "${BUILDDIR}" ] && die "mage_uninstall() \$BUILDDIR not set." |
2426 | |
2427 | xtitle "[ (${count_current}/${count_total}) Removing ${pcat}/${pname}-${pver}-${pbuild} ]" |
2428 | echo -ne "${COLBLUE} <<< ${COLDEFAULT}" |
2429 | echo -n "removing: " |
2430 | echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
2431 | echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}" |
2432 | |
2433 | magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" |
2434 | source ${magefile} |
2435 | |
2436 | ## preremove scripts |
2437 | if [ -n "$(typeset -f preremove)" ] |
2438 | then |
2439 | echo -e " ${COLBLUE}***${COLDEFAULT} running preremove ... " |
2440 | preremove |
2441 | unset preremove |
2442 | fi |
2443 | |
2444 | # runs uninstall |
2445 | build_douninstall \ |
2446 | --pcat "${pcat}" \ |
2447 | --pname "${pname}" \ |
2448 | --pver "${pver}" \ |
2449 | --pbuild "${pbuild}" |
2450 | |
2451 | ## postremove scripts |
2452 | if [ -n "$(typeset -f postremove)" ] |
2453 | then |
2454 | echo -e " ${COLBLUE}***${COLDEFAULT} running postremove ... " |
2455 | postremove |
2456 | unset postremove |
2457 | fi |
2458 | |
2459 | # removes the database entry |
2460 | remove_database_entry \ |
2461 | --pcat "${pcat}" \ |
2462 | --pname "${pname}" \ |
2463 | --pver "${pver}" \ |
2464 | --pbuild "${pbuild}" \ |
2465 | || die "error in mage_uninstall() running remove_database_entry()." |
2466 | |
2467 | # rebuilds toplevel info node |
2468 | if [[ ${MAGE_INFO_REBUILD} = true ]] |
2469 | then |
2470 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2471 | echo -n "rebuilding top-level info node ... " |
2472 | ${MLIBDIR}/mkinfodir ${MROOT}/usr/share/info \ |
2473 | > ${MROOT}/usr/share/info/dir && \ |
2474 | echo "done." || echo "failure." |
2475 | unset MAGE_INFO_REBUILD |
2476 | fi |
2477 | |
2478 | # rebuilds the enviroment with the content of /etc/env.d |
2479 | if [[ ${MAGE_ENV_REBUILD} = true ]] |
2480 | then |
2481 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2482 | echo -n "rebuilding environment ... " |
2483 | ${MLIBDIR}/env-rebuild.sh > /dev/null && \ |
2484 | echo "done." || echo "failure." |
2485 | unset MAGE_ENV_REBUILD |
2486 | fi |
2487 | |
2488 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2489 | echo -n "package " |
2490 | # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
2491 | # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " |
2492 | echo "successfully removed." |
2493 | |
2494 | # unset these functions |
2495 | unset -f preinstall |
2496 | unset -f postinstall |
2497 | unset -f preremove |
2498 | unset -f postremove |
2499 | } |
2500 | |
2501 | show_etc_update_mesg() { |
2502 | [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0 |
2503 | |
2504 | echo |
2505 | echo -ne "${COLRED}" |
2506 | echo "Important:" |
2507 | echo -ne ${COLDEFAULT} |
2508 | echo "${MAGE_PROTECT_COUNTER} protected file(s) were installed." |
2509 | echo |
2510 | echo "Please run 'etc-update' to update your configuration files." |
2511 | echo |
2512 | } |
2513 | |
2514 | pkgsearch() |
2515 | { |
2516 | local string="$1" |
2517 | local result |
2518 | local pkg |
2519 | local pcat |
2520 | local pname |
2521 | local magefile |
2522 | local pver |
2523 | local pbuild |
2524 | local state |
2525 | local descriptiom |
2526 | local homepage |
2527 | local i |
2528 | local all_installed |
2529 | local ipver |
2530 | local ipbuild |
2531 | |
2532 | # only names no versions |
2533 | result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')" |
2534 | #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)" |
2535 | |
2536 | # nothing found |
2537 | [[ -z ${result} ]] && die "No package found containing '${string}' in the name." |
2538 | |
2539 | for pkg in ${result} |
2540 | do |
2541 | # dirty, but does the job |
2542 | pcat="$(magename2pcat ${pkg}/foo)" |
2543 | pname="$(magename2pname ${pkg}-foo-foo)" |
2544 | |
2545 | # get highest version available |
2546 | magefile=$(get_highest_magefile ${pcat} ${pname}) |
2547 | |
2548 | # now get all needed infos to print a nice output |
2549 | pver="$(magename2pver ${magefile})" |
2550 | pbuild="$(magename2pbuild ${magefile})" |
2551 | state="$(get_value_from_magefile STATE ${magefile})" |
2552 | description="$(get_value_from_magefile DESCRIPTION ${magefile})" |
2553 | homepage="$(get_value_from_magefile HOMEPAGE ${magefile})" |
2554 | |
2555 | # all installed |
2556 | for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat}) |
2557 | do |
2558 | ipver="$(magename2pver ${i})" |
2559 | ipbuild="$(magename2pbuild ${i})" |
2560 | |
2561 | if [[ -z ${all_installed} ]] |
2562 | then |
2563 | all_installed="${ipver}-${ipbuild}" |
2564 | else |
2565 | all_installed="${all_installed} ${ipver}-${ipbuild}" |
2566 | fi |
2567 | done |
2568 | [[ -z ${all_installed} ]] && all_installed="none" |
2569 | |
2570 | case ${state} in |
2571 | stable) state=${COLGREEN}"[s] ";; |
2572 | testing) state=${COLYELLOW}"[t] ";; |
2573 | unstable) state=${COLRED}"[u] ";; |
2574 | old) state=${COLGRAY}"[o] ";; |
2575 | esac |
2576 | |
2577 | echo -e "${state}${pcat}/${pname}"${COLDEFAULT} |
2578 | echo " Latest available: ${pver}-${pbuild}" |
2579 | echo " Installed versions: ${all_installed}" |
2580 | echo " Description: ${description}" |
2581 | echo " Homepage: ${homepage}" |
2582 | echo |
2583 | |
2584 | unset pcat |
2585 | unset pname |
2586 | unset magefile |
2587 | unset pver |
2588 | unset pbuild |
2589 | unset state |
2590 | unset descriptiom |
2591 | unset homepage |
2592 | unset all_installed |
2593 | unset ipver |
2594 | unset ipbuild |
2595 | done |
2596 | } |
2597 | |
2598 | export_inherits() |
2599 | { |
2600 | local include="$1" |
2601 | shift |
2602 | |
2603 | while [ "$1" ] |
2604 | do |
2605 | local functions="$1" |
2606 | |
2607 | # sanity checks |
2608 | [ -z "${include}" ] && die "export_inherits(): \$include not given." |
2609 | [ -z "${functions}" ] && die "export_inherits(): \$functions not given." |
2610 | |
2611 | eval "${functions}() { ${include}_${functions} ; }" |
2612 | |
2613 | # debug |
2614 | [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}" |
2615 | |
2616 | shift |
2617 | done |
2618 | } |
2619 | |
2620 | mlibdir() |
2621 | { |
2622 | local libdir=lib |
2623 | [[ ${ARCH} = x86_64 ]] && libdir=lib64 |
2624 | |
2625 | echo "${libdir}" |
2626 | } |
2627 | |
2628 | ## blacklisted ${magefile} |
2629 | blacklisted() |
2630 | { |
2631 | [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable |
2632 | |
2633 | # compat |
2634 | [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable |
2635 | [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing |
2636 | |
2637 | local EXCLUDED="${MROOT}/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}" |
2638 | |
2639 | # return 0 if the list not exist; nothin is masked |
2640 | [[ ! -f ${EXCLUDED} ]] && return 0 |
2641 | |
2642 | local MAGEFILE="$1" |
2643 | |
2644 | local PCAT="$(magename2pcat ${MAGEFILE})" |
2645 | local PNAME="$(magename2pname ${MAGEFILE})" |
2646 | local PVER="$(magename2pver ${MAGEFILE})" |
2647 | local PBUILD="$(magename2pbuild ${MAGEFILE})" |
2648 | |
2649 | local EXPCAT EXPNAME EXPVER EXPBUILD |
2650 | while read EXPCAT EXPNAME EXPVER EXPBUILD |
2651 | do |
2652 | # ignore spaces and comments |
2653 | case "${EXPCAT}" in |
2654 | \#*|"") continue ;; |
2655 | esac |
2656 | |
2657 | # exclude full pver |
2658 | if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] && |
2659 | [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] && |
2660 | [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] && |
2661 | [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]] |
2662 | then |
2663 | [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1 |
2664 | fi |
2665 | |
2666 | # exclude pcat/pname only |
2667 | if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] && |
2668 | [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] && |
2669 | [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]] |
2670 | then |
2671 | [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1 |
2672 | fi |
2673 | done << EOF |
2674 | $( cat ${EXCLUDED}; echo) |
2675 | EOF |
2676 | |
2677 | return 0 |
2678 | } |
2679 |