Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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