Magellan Linux

Contents of /trunk/mage/usr/lib/mage/mage4.functions.sh

Parent Directory Parent Directory | Revision Log Revision Log


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