Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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