Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1289 - (show annotations) (download) (as text)
Thu May 12 21:29:31 2011 UTC (12 years, 11 months ago) by niro
File MIME type: application/x-sh
File size: 73148 byte(s)
-fix config protect: register ignored file in database with fixed mtime
-fixed some whitespaces
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
1383 # try to get the md5 marked as latest on the server
1384 latest_md5="mage-latest.md5"
1385
1386 # try to get the tarball marked as latest on the server
1387 latest_tarball="mage-latest.tar.bz2"
1388
1389 for mirr in ${MIRRORS}
1390 do
1391 # path without distribution
1392 mymirr="${mirr%/*}"
1393
1394 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1395 echo "fetching latest md5 from ${mymirr} ..."
1396 [[ ${VERBOSE} = off ]] && opt="--quiet"
1397 wget \
1398 ${WGET_FETCH_OPTIONS} \
1399 --directory-prefix=${temp} \
1400 ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1401
1402 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1403 echo "fetching latest tarball from ${mymirr} ..."
1404 wget \
1405 ${WGET_FETCH_OPTIONS} \
1406 --directory-prefix=${temp} \
1407 ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1408 if [[ $? = 0 ]]
1409 then
1410 break
1411 else
1412 continue
1413 fi
1414 done
1415
1416 if [[ -f ${temp}/${latest_tarball} ]]
1417 then
1418 # check md5
1419 if [[ ! -f ${temp}/${latest_md5} ]]
1420 then
1421 die "md5 is missing ... aborting"
1422 else
1423 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1424 echo -n "checking md5sum... "
1425 ( cd ${temp}; md5sum -c ${latest_md5} ) || die "md5 for ${latest_tarball} failed"
1426 fi
1427
1428 if [[ -d ${MAGEDIR} ]]
1429 then
1430 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1431 echo "cleaning old mage-tree ${MAGEDIR}..."
1432 rm -rf ${MAGEDIR}
1433 fi
1434
1435 if need_busybox_support tar
1436 then
1437 tar_opts="xjf"
1438 else
1439 tar_opts="xjmf"
1440 fi
1441
1442 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1443 echo "updating mage-tree from tarball ..."
1444 # unpack in dirname of MAGEDIR, as the tarball has already the mage
1445 tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1446
1447 if [[ -d ${temp} ]]
1448 then
1449 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1450 echo "cleaning temp-files ..."
1451 rm -rf ${temp}
1452 fi
1453
1454 # check if a newer mage version is available
1455 is_newer_mage_version_available
1456 else
1457 die "Could not fetch the latest tarball ... aborting"
1458 fi
1459 }
1460
1461 cleanpkg()
1462 {
1463 if [ -d "${PKGDIR}" ]
1464 then
1465 echo -n "Removing downloaded packages... "
1466 rm -rf ${PKGDIR}/*
1467 echo "done."
1468 fi
1469 }
1470
1471 xtitle()
1472 {
1473 if [[ ${TERM} = xterm ]]
1474 then
1475 echo -ne "\033]0;Mage: $1\007"
1476 fi
1477 return 0
1478 }
1479
1480
1481 xtitleclean()
1482 {
1483 if [[ ${TERM} = xterm ]]
1484 then
1485 echo -ne "\033]0;\007"
1486 fi
1487 return 0
1488 }
1489
1490
1491 # cuts full pathnames or versioniezed names down to basename
1492 choppkgname()
1493 {
1494 #we want this only if full name was used
1495 if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1496 then
1497 #cuts ARCH and PBUILD
1498 #ARCH comes from ${MAGERC}
1499 MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")
1500
1501 #cuts version number
1502 MAGENAME=$(basename ${MAGENAME%-*} .mage)
1503 fi
1504 }
1505
1506 # get_categorie $PNAME, returns CATEGORIE
1507 # $1=pname
1508 # ret 0=ok, 1=not_found
1509 pname2pcat()
1510 {
1511 local pname="$1"
1512 local repo="$2"
1513 local pcat
1514 local categorie
1515
1516 for pcat in ${MAGEDIR}/*
1517 do
1518 if [ -d ${pcat}/${pname} ]
1519 then
1520 categorie=$(basename ${pcat})
1521 fi
1522 done
1523
1524 echo "${categorie}"
1525 }
1526
1527 # check_stable_package /path/to/foo.mage
1528 # returns 0=stable 1=unstable
1529 check_stable_package()
1530 {
1531 # first check if this magefile is not blacklisted
1532 blacklisted "$1" || return 1
1533
1534 local STATE
1535 STATE="$(get_value_from_magefile STATE "$1")"
1536
1537 # state testing
1538 if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1539 then
1540 case ${STATE} in
1541 testing|stable) return 0 ;;
1542 *) return 1 ;;
1543 esac
1544 fi
1545
1546 # state unstable
1547 if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1548 then
1549 case ${STATE} in
1550 unstable|testing|stable) return 0 ;;
1551 *) return 1 ;;
1552 esac
1553 fi
1554
1555 # no use_state given = stable
1556 case ${STATE} in
1557 stable) return 0 ;;
1558 *) return 1 ;;
1559 esac
1560 }
1561
1562
1563 # get_highest_magefile ${PCAT} ${PNAME}
1564 # fake at moment returns only stable pkgs (must set to be one)
1565 # return $HIGHEST_MAGEFILE
1566 get_highest_magefile()
1567 {
1568 local HIGHEST_MAGEFILE
1569 local PCAT="$1"
1570 local PNAME="$2"
1571 local magefile
1572
1573 # do not list the content of a directory, only the name (-d)
1574 for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/*)
1575 do
1576 [[ -z ${magefile} ]] && continue
1577 # we exclude subdirs (for stuff like a md5sum dir)
1578 [[ -d ${magefile} ]] && continue
1579 if check_stable_package ${magefile}
1580 then
1581 HIGHEST_MAGEFILE=${magefile}
1582 #for debug only
1583 [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"
1584 fi
1585 done
1586
1587 # do not so anything
1588 # # stop here if HIGHEST_MAGEFILE is zero
1589 # # this package must be unstable or old
1590 # if [ -z "${HIGHEST_MAGEFILE}" ]
1591 # then
1592 # echo
1593 # echo -n "All packages named "
1594 # echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}
1595 # echo -n " are marked "
1596 # echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}
1597 # echo "."
1598 # echo "You need to declare USE_UNSTABLE=true to install this."
1599 # echo
1600 # echo "Example:"
1601 # echo " USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"
1602 # echo
1603 # echo "Be warned that these packages are not stable and may cause serious problems."
1604 # echo "You should know what you are doing, so don't complain about any damage."
1605 # echo
1606 # return 1
1607 # fi
1608
1609 echo "${HIGHEST_MAGEFILE}"
1610 return 0
1611 }
1612
1613
1614 ###################################################
1615 # function is_config_protected #
1616 # is_config_protected /path/to/file #
1617 # #
1618 # returns: #
1619 # 0 - not protected #
1620 # 1 - error #
1621 # 2 - protected #
1622 # 3 - protected but masked #
1623 # 4 - protected but ignored #
1624 # #
1625 ###################################################
1626 is_config_protected()
1627 {
1628 local EXPFILE
1629 local TEST
1630 local PROTECTED
1631 local IFS
1632 local i
1633 local x
1634
1635 EXPFILE="${MROOT}$1"
1636
1637 # file does not exist; it can be written
1638 [[ ! -e ${EXPFILE} ]] && return 0
1639
1640 # to be safe; it may be '§'
1641 IFS=' '
1642
1643 # check if config protected
1644 for i in ${CONFIG_PROTECT}
1645 do
1646 # only replace $i in the beginning of the variable
1647 TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1648 if [[ ${TEST} != ${EXPFILE} ]]
1649 then
1650 # file is config proteced
1651 PROTECTED=TRUE
1652
1653 # check if not masked
1654 for x in ${CONFIG_PROTECT_MASK}
1655 do
1656 TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1657 if [[ ${TEST} != ${EXPFILE} ]]
1658 then
1659 PROTECTED=MASKED
1660 fi
1661 done
1662
1663 # check if not ignored
1664 for x in ${CONFIG_PROTECT_IGNORE}
1665 do
1666 TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1667 if [[ ${TEST} != ${EXPFILE} ]]
1668 then
1669 PROTECTED=IGNORED
1670 fi
1671 done
1672 fi
1673 done
1674
1675 unset IFS
1676
1677 case ${PROTECTED} in
1678 TRUE)
1679 #echo "I'm protected"
1680 return 2
1681 ;;
1682 MASKED)
1683 #echo "I'm protected, but masked - delete me"
1684 return 3
1685 ;;
1686 IGNORED)
1687 #echo "I'm protected, but ignored - keep me, del update"
1688 return 4
1689 ;;
1690 *)
1691 #echo "delete me"
1692 return 0
1693 ;;
1694 esac
1695 }
1696
1697
1698 ###################################################
1699 # function count_protected_files #
1700 # count_protected_files /path/to/file #
1701 # #
1702 # note: prints number of protected files #
1703 # exp: 0012 #
1704 ###################################################
1705 count_protected_files()
1706 {
1707 local file="$1"
1708 local dirname="${file%/*}"
1709 local filename="${file##*/}"
1710 local count
1711 local output
1712 local i
1713
1714 declare -i count=0
1715
1716 # check if there are already protected files
1717 for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |
1718 sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1719 sort -t'%' -k3 -k2 | cut -f1 -d'%')
1720 do
1721 count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")
1722 done
1723 (( count ++ ))
1724
1725 # fill output up with zeros
1726 for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1727 output="${output}${count}"
1728
1729 echo "${output}"
1730 }
1731
1732 # call with
1733 # 'get_uninstall_candidates (--pcat cat --protected pcat/pfull) --pname PNAME'
1734 # returns /path/to/magefile(s)
1735 get_uninstall_candidates()
1736 {
1737 local search_pname
1738 local pkg
1739 local pcat
1740 local pname
1741 local pver
1742 local pbuild
1743 local list
1744 local pcatdir
1745 local protected
1746 local i
1747
1748 # very basic getops
1749 for i in $*
1750 do
1751 case $1 in
1752 --pcat|-c) shift; pcatdir="$1" ;;
1753 --pname|-n) shift; search_pname="$1" ;;
1754 --protected|-p) shift; protected="$1" ;;
1755 esac
1756 shift
1757 done
1758
1759 # it's not good to complain here about empty pnames; better to continue later anyway
1760 # # sanity checks; abort if not given
1761 # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1762
1763
1764 # check needed global vars
1765 [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1766
1767 # set pcatdir to '*' if empty
1768 [ -z "${pcatdir}" ] && pcatdir='*'
1769
1770 for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1771 do
1772 # abort if not a dir
1773 [ ! -d ${pkg} ] && continue
1774
1775 pname="$(magename2pname ${pkg})"
1776
1777 if [[ ${search_pname} = ${pname} ]]
1778 then
1779 pcat="$(magename2pcat ${pkg} installdb)"
1780 pver="$(magename2pver ${pkg})"
1781 pbuild="$(magename2pbuild ${pkg})"
1782
1783 # exclude proteced
1784 [[ ${protected} = ${pcat}/${pname}-${pver}-${pbuild} ]] && continue
1785
1786 list="${list} ${pcat}/${pname}-${pver}-${pbuild}"
1787 fi
1788 done
1789
1790 echo "${list}"
1791 }
1792
1793 # reads virtualdb file
1794 #$1 = virtualname; $2 commands: showpkgs, showline
1795 #return 0 == installed -> shows installed pkg as well
1796 #return 1 == not installed
1797 virtuals_read()
1798 {
1799 local virtualname="$1"
1800 local command="$2"
1801 local virtline
1802 local line x i
1803
1804 # parse file to get virtual_name line
1805 IFS=$'\n'
1806 for line in $(< ${MROOT}${VIRTUALDB_FILE})
1807 do
1808 IFS=$' '
1809 for x in ${line}
1810 do
1811 if [[ ${x} = ${virtualname} ]]
1812 then
1813 virtline="${line}"
1814 [[ ${command} = showline ]] && echo "${line}"
1815 fi
1816 done
1817 IFS=$'\n'
1818 done
1819
1820 unset IFS
1821
1822 # now read the packages linked to VIRTUAL_NAME and output them
1823 if [ -n "${virtline}" ]
1824 then
1825 if [[ ${command} = showpkgs ]]
1826 then
1827 declare -i x=0
1828 for i in ${virtline}
1829 do
1830 if [ ${x} -ge 1 ]
1831 then
1832 echo "${i}"
1833 fi
1834 ((x++))
1835 done
1836 fi
1837 return 0
1838 fi
1839 return 1
1840 }
1841
1842
1843 #add pkg to virtualdb
1844 # $1 == virtualname $2= pkgname
1845 # retvals: 0=ok,added; 1=error; 3=pkg already in virtual
1846 virtuals_add()
1847 {
1848 local virtualname="$1"
1849 local pkgname="$2"
1850 local oldline
1851 local line i
1852 local installed_file
1853 local OLDIFS
1854
1855 if virtuals_read ${virtualname}
1856 then
1857 # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1858 for i in $(virtuals_read ${virtualname} showpkgs)
1859 do
1860 if [[ ${i} = ${pkgname} ]]
1861 then
1862 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1863 echo "${pkgname} already linked as ${virtualname} ..."
1864 #return 3
1865 return 0
1866 fi
1867 done
1868
1869 echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1870 echo "updating ${virtualname} entry with ${pkgname} ..."
1871 oldline="$(virtuals_read ${virtualname} showline)"
1872
1873 # make a backup
1874 mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
1875
1876 OLDIFS="${IFS}"
1877 IFS=$'\n'
1878 for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
1879 do
1880 # if the right line, append ${pkgname}, else do nothing
1881 if [[ ${line} = ${oldline} ]]
1882 then
1883 echo "${line} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1884 else
1885 echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
1886 fi
1887 done
1888 # unset IFS
1889 IFS="${OLDIFS}"
1890 else
1891 echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
1892 echo "register ${pkgname} as ${virtualname} ..."
1893 echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1894 fi
1895
1896 return 0
1897 }
1898
1899 #deletes pakages from virtual database
1900 #$1 virtualname; $2 pkgname
1901 virtuals_del()
1902 {
1903
1904 local virtualname="$1"
1905 local pkgname="$2"
1906 local oldline
1907 local method
1908 local line i x
1909 local pkg_installed
1910 local OLDIFS
1911
1912 # first check if exists
1913 if virtuals_read ${virtualname}
1914 then
1915 # get method -> delall or update and check if ${PKG_NAME} exists in ${VIRTUAL_NAME}
1916 declare -i x=0
1917 for i in $(virtuals_read ${virtualname} showpkgs)
1918 do
1919 if [[ ${i} = ${pkgname} ]]
1920 then
1921 pkg_installed=true
1922 fi
1923 ((x++))
1924 done
1925
1926 # abort if not installed
1927 if [[ ${pkg_installed} != true ]]
1928 then
1929 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1930 echo "${pkgname} does not exists in ${virtualname}."
1931 return 0
1932 fi
1933
1934 if [ ${x} -ge 2 ]
1935 then
1936 method=update
1937 else
1938 method=delall
1939 fi
1940
1941 # get the complete line
1942 oldline="$(virtuals_read ${virtualname} showline)"
1943
1944 # make a backup of the db
1945 mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1946
1947 # parse virtualdb
1948 OLDIFS="${IFS}"
1949 IFS=$'\n'
1950 for line in $(< ${VIRTUALDB_FILE}.old)
1951 do
1952 if [[ ${line} = ${oldline} ]]
1953 then
1954 #delall or update?
1955 case ${method} in
1956 update)
1957 echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1958 echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
1959 # del PKG_NAME from line
1960 echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
1961 ;;
1962 delall)
1963 echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
1964 echo "Deleting ${virtualname} in virtual database ..."
1965 # continue; do not write anything
1966 continue
1967 ;;
1968 esac
1969 else
1970 echo "${line}" >> ${VIRTUALDB_FILE}
1971 fi
1972 done
1973 # unset IFS
1974 IFS="${OLDIFS}"
1975 else
1976 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1977 echo "${virtualname} does not exists in virtual database."
1978 fi
1979 }
1980
1981 # gets real pkgname from virtuals.default
1982 #$1=VIRTUAL_NAME; returns PKG_NAME
1983 default_virtualname_to_pkgname()
1984 {
1985 local VIRTUAL_NAME PKG_NAME db_virtualname db_pkgname
1986
1987 VIRTUAL_NAME=$1
1988
1989 while read db_virtualname db_pkgname
1990 do
1991 if [ "${db_virtualname}" == "${VIRTUAL_NAME}" ]
1992 then
1993 PKG_NAME="${db_pkgname}"
1994 fi
1995 done << EOF
1996 $(< ${VIRTUALDB_DEFAULTS})
1997 EOF
1998
1999 if [ -n "${PKG_NAME}" ]
2000 then
2001 echo "${PKG_NAME}"
2002 fi
2003 }
2004
2005 minclude()
2006 {
2007 local i
2008
2009 if [[ -n $* ]]
2010 then
2011 for i in $*
2012 do
2013 [[ ${MAGEDEBUG} = on ]] && \
2014 echo "--- Including ${MAGEDIR}/include/${i}.minc"
2015 source ${MAGEDIR}/include/${i}.minc
2016 done
2017 [[ ${MAGEDEBUG} = on ]] && echo
2018 fi
2019 }
2020
2021 sminclude()
2022 {
2023 local i
2024
2025 if [[ -n $* ]]
2026 then
2027 for i in $*
2028 do
2029 echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2030 source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2031 done
2032 echo
2033 fi
2034 }
2035
2036 # checks if an newer mage version is available
2037 is_newer_mage_version_available()
2038 {
2039 local newest_mage
2040 local installed_mage
2041
2042 newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
2043 installed_mage="$(magequery -n mage | cut -d' ' -f5)"
2044
2045 if [[ ${newest_mage} > ${installed_mage} ]]
2046 then
2047 echo
2048 echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2049 echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2050 echo "It is recommened to install this newer version"
2051 echo "or your current system installation may break."
2052 echo
2053 echo -en "Please update mage by running "
2054 echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
2055 echo
2056 fi
2057 }
2058
2059
2060 # returns pname from pkgname
2061 # pkgname2pname $PKGNAME
2062 pkgname2pname()
2063 {
2064 local pname
2065
2066 pname="${1%-*-*-*}"
2067 echo "${pname}"
2068 }
2069
2070 # returns pver from pkgname
2071 # pkgname2pver $PKGNAME
2072 pkgname2pver()
2073 {
2074 local i pver
2075
2076 i="${1/$(pkgname2pname $1)-/}"
2077 pver="${i%-*-*}"
2078 echo "${pver}"
2079 }
2080
2081 # returns pbuild from pkgname
2082 # pkgname2pbuild $PKGNAME
2083 pkgname2pbuild()
2084 {
2085 local pbuild
2086
2087 pbuild="${1##*-}"
2088 echo "${pbuild}"
2089 }
2090
2091 # returns parch from pkgname
2092 # pkgname2parch $PKGNAME
2093 pkgname2parch()
2094 {
2095 local i x parch
2096
2097 i="${1%-*-*}-"
2098 x="${1%-*}"
2099 parch="${x/${i}/}"
2100 echo "${parch}"
2101 }
2102
2103 # returns pname from magename
2104 # magename2pname /PATH/TO/MAGE/FILE
2105 magename2pname()
2106 {
2107 local i pname
2108
2109 i="$(basename $1 .mage)"
2110 pname="${i%-*-*}"
2111 echo "${pname}"
2112 }
2113
2114 # returns pver from magename
2115 # magename2pver /PATH/TO/MAGE/FILE
2116 magename2pver()
2117 {
2118 local i pver
2119
2120 i="$(basename $1 .mage)"
2121 i="${i/$(magename2pname $1)-/}"
2122 pver="${i%-*}"
2123 echo "${pver}"
2124 }
2125
2126 # returns pbuild from magename
2127 # magename2pbuild /PATH/TO/MAGE/FILE
2128 magename2pbuild()
2129 {
2130 local i pbuild
2131
2132 i="$(basename $1 .mage)"
2133 pbuild="${i##*-}"
2134 echo "${pbuild}"
2135 }
2136
2137 # returns pcat from magename
2138 # magename2pcat /PATH/TO/MAGE/FILE
2139 magename2pcat()
2140 {
2141 local i pcat
2142
2143 if [[ ${2} = installdb ]]
2144 then
2145 # go 1 dir back
2146 i="${1%/*}"
2147 else
2148 # go 2 dirs back
2149 i="${1%/*/*}"
2150 fi
2151
2152 # get basename
2153 pcat="${i##*/}"
2154 echo "${pcat}"
2155 }
2156
2157 # returns pcat from DEPEND (without operand ! PCAT/PNAME-VERSION)
2158 # dep2pcat DEPEND
2159 dep2pcat()
2160 {
2161 local pcat
2162
2163 pcat="${1%/*}"
2164 echo "${pcat}"
2165 }
2166
2167 # returns pname from DEPEND (without operand ! PCAT/PNAME-VERSION)
2168 # $2=virtual is used to resolv VDEPEND from virtual packages
2169 # dep2pcat DEPEND (virtual)
2170 dep2pname()
2171 {
2172 local pname
2173
2174 pname="${1##*/}"
2175
2176 # cut version only if not virtual or it will cut the name
2177 if [[ $(dep2pcat $1) != virtual ]] && \
2178 [[ $2 != virtual ]]
2179 then
2180 pname="${pname%-*}"
2181 fi
2182
2183 echo "${pname}"
2184 }
2185
2186 dep2highest_magefile()
2187 {
2188 local pcat
2189 local pname
2190 local magefile
2191 local installed_virtuals
2192
2193 pcat="$(dep2pcat $1)"
2194 pname="$(dep2pname $1)"
2195
2196 if [[ ${pcat} = virtual ]]
2197 then
2198 # first check if virtual is already installed
2199 installed_virtuals="$(virtuals_read ${pcat}/${pname} showpkgs)"
2200 if [ -n "${installed_virtuals}" ]
2201 then
2202 for vpkg in ${installed_virtuals}
2203 do
2204 realpkgname="${vpkg}"
2205 virtualpkgname="${pcat}/${pname}"
2206 pcat="$(dep2pcat ${realpkgname})"
2207 pname="$(dep2pname ${realpkgname} virtual)"
2208 done
2209 else
2210 # choose one from virtualdb defaults (virtuals.defaults)
2211 realpkgname="$(default_virtualname_to_pkgname ${pcat}/${pname})"
2212 virtualpkgname="${pcat}/${pname}"
2213 pcat="$(dep2pcat ${realpkgname})"
2214 pname="$(dep2pname ${realpkgname} virtual)"
2215 fi
2216 fi
2217
2218 magefile="$(get_highest_magefile ${pcat} ${pname})"
2219 echo "${magefile}"
2220 }
2221
2222 # is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}
2223 is_installed()
2224 {
2225 local fullpkgname="$1"
2226
2227 # return 0 if installed
2228 [ -d ${MROOT}${INSTALLDB}/${fullpkgname} ] && return 0
2229
2230 return 1
2231 }
2232
2233 install_packages()
2234 {
2235 local list="$@"
2236 local pkg
2237 local pcat
2238 local pname
2239 local pver
2240 local pbuild
2241 local total_pkgs
2242 local current_pkg
2243 local src_install
2244 local uninstall_list
2245
2246 # check for --src-install
2247 if [[ $1 = --src-install ]]
2248 then
2249 # remove --src-install from list
2250 list=${list/--src-install/}
2251 # enable src-install
2252 src_install="--src-install"
2253 fi
2254
2255 # reset MAGE_PROTECT_COUNTER
2256 declare -i MAGE_PROTECT_COUNTER=0
2257 export MAGE_PROTECT_COUNTER
2258
2259 # get count of total packages
2260 declare -i total_pkgs=0
2261 declare -i current_pkg=0
2262 for i in ${list}; do (( total_pkgs++ )); done
2263
2264 echo
2265
2266 if [[ -n ${MROOT} ]]
2267 then
2268 echo -ne ${COLRED}
2269 echo "!! installing in MROOT=${MROOT}"
2270 echo -ne ${COLDEFAULT}
2271 echo
2272 fi
2273
2274 for pkg in ${list}
2275 do
2276 (( current_pkg++ ))
2277 pcat=$(magename2pcat ${pkg})
2278 pname=$(magename2pname ${pkg})
2279 pver=$(magename2pver ${pkg})
2280 pbuild=$(magename2pbuild ${pkg})
2281
2282 mage_install \
2283 --pcat ${pcat} \
2284 --pname ${pname} \
2285 --pver ${pver} \
2286 --pbuild ${pbuild} \
2287 --count-total ${total_pkgs} \
2288 --count-current ${current_pkg} \
2289 ${src_install}
2290
2291 # check for allready installed packages and remove them
2292 # except the package we have installed
2293 uninstall_list="$(get_uninstall_candidates \
2294 --pcat "${pcat}" \
2295 --pname "${pname}" \
2296 --protected ${pcat}/${pname}-${pver}-${pbuild})"
2297
2298 # uninstall all packges in uninstall_list if not empty
2299 if [ -n "${uninstall_list}" ]
2300 then
2301 echo
2302 uninstall_packages ${uninstall_list} \
2303 || die "install_packges() uninstalling not-needed."
2304 fi
2305
2306 # crlf for better view in VERBOSE mode
2307 #if [[ ${VERBOSE} = on ]]; then echo; fi
2308 echo
2309 done
2310
2311 #echo "DEBUG MAGE_PROTECT_COUNTER=${MAGE_PROTECT_COUNTER}"
2312 show_etc_update_mesg
2313 }
2314
2315 # get_value_from_magefile VARIABLE
2316 # returns the content of this VAR
2317 get_value_from_magefile()
2318 {
2319 local var="$1"
2320 local magefile="$2"
2321 local value
2322
2323 [[ -z ${var} ]] && return 1
2324 [[ -z ${magefile} ]] && return 1
2325
2326 # local all possible vars of a mage file
2327 # to prevent bad issues
2328 local PKGNAME
2329 local STATE
2330 local DESCRIPTION
2331 local HOMEPAGE
2332 local DEPEND
2333 local SDEPEND
2334 local PROVIDE
2335 local PKGTYPE
2336 local MAGE_TARGETS
2337 local SPLIT_PACKAGE_BASE
2338 local preinstall
2339 local postinstall
2340 local preremove
2341 local postremove
2342
2343 # sanity checks
2344 [ -f ${magefile} ] && source ${magefile} || \
2345 die "get_value_from_magefile: ${magefile} not found."
2346 [ -z "${var}" ] && die "get_value_from_magefile: \$var not given."
2347
2348 source ${magefile}
2349 eval value=\$$(echo ${var})
2350 echo "${value}"
2351
2352 # unset these functions
2353 unset -f preinstall
2354 unset -f postinstall
2355 unset -f preremove
2356 unset -f postremove
2357 }
2358
2359 mage_install()
2360 {
2361 # local all possible vars of a mage file
2362 # to prevent bad issues
2363 local PKGNAME
2364 local STATE
2365 local DESCRIPTION
2366 local HOMEPAGE
2367 local DEPEND
2368 local SDEPEND
2369 local PROVIDE
2370 local PKGTYPE
2371 local preinstall
2372 local postinstall
2373 local preremove
2374 local postremove
2375
2376 local pcat
2377 local pname
2378 local pver
2379 local pbuild
2380 local count_total
2381 local count_current
2382 local magefile
2383 local src_install
2384 local i
2385
2386 # very basic getops
2387 for i in $*
2388 do
2389 case $1 in
2390 --pcat|-c) shift; pcat="$1" ;;
2391 --pname|-n) shift; pname="$1" ;;
2392 --pver|-v) shift; pver="$1" ;;
2393 --pbuild|-b) shift; pbuild="$1" ;;
2394 --count-total) shift; count_total="$1" ;;
2395 --count-current) shift; count_current="$1" ;;
2396 --src-install|-s) shift; src_install=true ;;
2397 esac
2398 shift
2399 done
2400
2401 # sanity checks; abort if not given
2402 [ -z "${pcat}" ] && die "mage_install() \$pcat not given."
2403 [ -z "${pname}" ] && die "mage_install() \$pname not given."
2404 [ -z "${pver}" ] && die "mage_install() \$pver not given."
2405 [ -z "${pbuild}" ] && die "mage_install() \$pbuild not given."
2406
2407 # check needed global vars
2408 [ -z "${MAGEDIR}" ] && die "mage_install() \$MAGEDIR not set."
2409 [ -z "${INSTALLDB}" ] && die "mage_install() \$INSTALLDB not set."
2410 [ -z "${BUILDDIR}" ] && die "mage_install() \$BUILDDIR not set."
2411
2412 xtitle "[ (${count_current}/${count_total}) Installing ${pcat}/${pname}-${pver}-${pbuild} ]"
2413 echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
2414 echo -n "installing (${count_current}/${count_total}): "
2415 echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2416 echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2417
2418 magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage"
2419 source ${magefile}
2420
2421 # abort on sources if no srcinstall
2422 if [[ ${PKGTYPE} = sources ]] && [[ ${src_install} != true ]]
2423 then
2424 echo
2425 echo -e "This Package is a Source Package."
2426 echo
2427 echo -e "Only 'srcinstall' works with this type of packages"
2428 echo -en "If you have done a srcinstall before, "
2429 echo -e "you will find the files in /usr/src."
2430 echo
2431 exit 1
2432 fi
2433
2434 ## preinstall scripts
2435 if [ -n "$(typeset -f preinstall)" ]
2436 then
2437 echo -e " ${COLBLUE}***${COLDEFAULT} running preinstall ... "
2438 preinstall
2439 unset preinstall
2440 fi
2441
2442 if [[ ${src_install} = true ]]
2443 then
2444 local smage2file
2445 # check needed global vars
2446 [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not set."
2447 [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not set."
2448 [ -z "${BINDIR}" ] && die "\$BINDIR not set."
2449
2450 # build the package first
2451 if [[ ${MAGEDEBUG} = on ]]
2452 then
2453 echo M:${pname}
2454 echo V:${pver}
2455 echo B:${pbuild}
2456 fi
2457
2458 if [[ -n ${MAGE_TARGETS} ]]
2459 then
2460 # basic svn compat
2461 if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2462 then
2463 for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2464 do
2465 smage2file="${i}"
2466 done
2467 else
2468 smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2469 fi
2470
2471 elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2472 then
2473 # basic svn compat
2474 if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2475 then
2476 for i in ${SMAGESCRIPTSDIR}/trunk/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2477 do
2478 smage2file="${i}"
2479 done
2480 else
2481 smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2482 fi
2483
2484 else
2485 # basic svn compat
2486 if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2487 then
2488 for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2489 do
2490 smage2file="${i}"
2491 done
2492 else
2493 smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2494 fi
2495 fi
2496
2497 if [ -f "${smage2file}" ]
2498 then
2499 echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2500 smage2 ${smage2file} || die "compile failed"
2501 else
2502 echo
2503 echo "$(basename ${SMAGEFILE}) not found."
2504 echo "update your smage-tree and try it again."
2505 echo
2506 die
2507 fi
2508 fi
2509
2510 if [[ ${PKGTYPE} != virtual ]] && \
2511 [[ ${PKGTYPE} != sources ]]
2512 then
2513 echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
2514 build_doinstall ${PKGNAME}
2515 fi
2516
2517 ## postinstall scripts
2518 if [ -n "$(typeset -f postinstall)" ]
2519 then
2520 echo -e " ${COLBLUE}***${COLDEFAULT} running postinstall ... "
2521 postinstall
2522 unset postinstall
2523 fi
2524
2525 # install a database entry
2526 install_database_entry \
2527 --pcat "${pcat}" \
2528 --pname "${pname}" \
2529 --pver "${pver}" \
2530 --pbuild "${pbuild}" \
2531 --pkgname "${PKGNAME}" \
2532 --pkgtype "${PKGTYPE}" \
2533 || die "error in mage_install() running install_database_entry()."
2534
2535 # remove the package dir now
2536 if [ -d ${BUILDDIR}/${PKGNAME} ]
2537 then
2538 rm -rf ${BUILDDIR}/${PKGNAME}
2539 fi
2540
2541 # rebuilds toplevel info node
2542 if [[ ${MAGE_INFO_REBUILD} = true ]]
2543 then
2544 echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2545 echo -n "rebuilding top-level info node ... "
2546 ${MLIBDIR}/mkinfodir ${MROOT}/usr/share/info \
2547 > ${MROOT}/usr/share/info/dir && \
2548 echo "done." || echo "failure."
2549 unset MAGE_INFO_REBUILD
2550 fi
2551
2552 # rebuilds the enviroment with the content of /etc/env.d
2553 if [[ ${MAGE_ENV_REBUILD} = true ]]
2554 then
2555 echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2556 echo -n "rebuilding environment ... "
2557 ${MLIBDIR}/env-rebuild.sh > /dev/null && \
2558 echo "done." || echo "failure."
2559 unset MAGE_ENV_REBUILD
2560 fi
2561
2562 xtitleclean
2563
2564 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2565 echo -n "package "
2566 # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2567 # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2568 echo "successfully installed."
2569
2570 # unset these functions
2571 unset -f preinstall
2572 unset -f postinstall
2573 unset -f preremove
2574 unset -f postremove
2575 }
2576
2577 md5sum_packages()
2578 {
2579 local list="$@"
2580 local magefile
2581 local pcat
2582 local pname
2583 local pkgname
2584 local pkgfile
2585 local pkgtype
2586 local count_current
2587 local count_total
2588
2589 # get count of total packages
2590 declare -i count_current=0
2591 declare -i count_total=0
2592
2593 for i in ${list}; do (( count_total++ )); done
2594
2595 for magefile in ${list}
2596 do
2597 pcat=$(magename2pcat ${magefile})
2598 pname=$(magename2pname ${magefile})
2599 pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2600 md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2601 pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"
2602 pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2603
2604 (( count_current++ ))
2605 xtitle "[ (${count_current}/${count_total}) MD5SUM: ${pkgfile} ]"
2606
2607 # abort on virtual pkg
2608 if [[ ${pkgtype} = virtual ]]
2609 then
2610 echo -ne " ${COLBLUE}---${COLDEFAULT}"
2611 echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "
2612 continue
2613 fi
2614
2615 # abort on sources pkg
2616 if [[ ${pkgtype} = sources ]]
2617 then
2618 echo -ne " ${COLBLUE}---${COLDEFAULT}"
2619 echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "
2620 continue
2621 fi
2622
2623 if [ -f "${md5file}" ]
2624 then
2625 echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2626 echo -ne "checking md5sum (${count_current}/${count_total}): "
2627 ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed"
2628 else
2629 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2630 echo -e "!! no md5sum file found for ${pkgfile} :("
2631 fi
2632 done
2633
2634 # add a crlf for a better view
2635 if [ ${count_total} -gt 1 ]; then echo; fi
2636 }
2637
2638 ## uninstall_packages ulist
2639 uninstall_packages()
2640 {
2641 local list="$@"
2642 local pcat
2643 local pname
2644 local pver
2645 local pbuild
2646 local can_pcat
2647 local can_pname
2648 local can_ver_list
2649
2650 if [[ -n ${MROOT} ]]
2651 then
2652 echo -ne ${COLRED}
2653 echo "!! uninstalling from MROOT=${MROOT}"
2654 echo -ne ${COLDEFAULT}
2655 echo
2656 fi
2657
2658 # generate a candidates list
2659 for pkg in ${list}
2660 do
2661 pcat=$(dep2pcat ${pkg})
2662 pname=$(magename2pname ${pkg})
2663 pver=$(magename2pver ${pkg})
2664 pbuild=$(magename2pbuild ${pkg})
2665 can_pcat="${pcat}"
2666 can_pname="${pname}"
2667
2668 if [ -z "${can_ver_list}" ]
2669 then
2670 can_ver_list=" ${pver}-${pbuild}"
2671 else
2672 can_ver_list="${can_ver_list}, ${pver}-${pbuild}"
2673 fi
2674 done
2675
2676 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2677 echo "following candidate(s) will be removed:"
2678 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2679 echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}"
2680 echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"
2681 echo
2682 if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ]
2683 then
2684 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2685 echo "( Press [CTRL+C] to abort )"
2686 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2687 echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."
2688 for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))
2689 do
2690 echo -ne "${COLRED} ${i}${COLDEFAULT}"
2691 sleep 1
2692 done
2693 echo
2694 echo
2695 fi
2696
2697 for pkg in ${list}
2698 do
2699 pcat=$(dep2pcat ${pkg})
2700 pname=$(magename2pname ${pkg})
2701 pver=$(magename2pver ${pkg})
2702 pbuild=$(magename2pbuild ${pkg})
2703
2704 mage_uninstall \
2705 --pcat ${pcat} \
2706 --pname ${pname} \
2707 --pver ${pver} \
2708 --pbuild ${pbuild} \
2709 --count-total ${total_pkgs} \
2710 --count-current ${current_pkg} \
2711 ${src_install}
2712
2713 # crlf for better view in VERBOSE mode
2714 #if [[ ${VERBOSE} = on ]]; then echo; fi
2715 echo
2716 done
2717 }
2718
2719 mage_uninstall()
2720 {
2721 # local all possible vars of a mage file
2722 # to prevent bad issues
2723 local PKGNAME
2724 local STATE
2725 local DESCRIPTION
2726 local HOMEPAGE
2727 local DEPEND
2728 local SDEPEND
2729 local PROVIDE
2730 local PKGTYPE
2731 local preinstall
2732 local postinstall
2733 local preremove
2734 local postremove
2735
2736 local pcat
2737 local pname
2738 local pver
2739 local pbuild
2740 local magefile
2741 local i
2742
2743 # very basic getops
2744 for i in $*
2745 do
2746 case $1 in
2747 --pcat|-c) shift; pcat="$1" ;;
2748 --pname|-n) shift; pname="$1" ;;
2749 --pver|-v) shift; pver="$1" ;;
2750 --pbuild|-b) shift; pbuild="$1" ;;
2751 esac
2752 shift
2753 done
2754
2755 # sanity checks; abort if not given
2756 [ -z "${pcat}" ] && die "mage_uninstall() \$pcat not given."
2757 [ -z "${pname}" ] && die "mage_uninstall() \$pname not given."
2758 [ -z "${pver}" ] && die "mage_uninstall() \$pver not given."
2759 [ -z "${pbuild}" ] && die "mage_uninstall() \$pbuild not given."
2760
2761 # check needed global vars
2762 [ -z "${MAGEDIR}" ] && die "mage_uninstall() \$MAGEDIR not set."
2763 [ -z "${INSTALLDB}" ] && die "mage_uninstall() \$INSTALLDB not set."
2764 [ -z "${BUILDDIR}" ] && die "mage_uninstall() \$BUILDDIR not set."
2765
2766 xtitle "[ (${count_current}/${count_total}) Removing ${pcat}/${pname}-${pver}-${pbuild} ]"
2767 echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2768 echo -n "removing: "
2769 echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2770 echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2771
2772 magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2773 source ${magefile}
2774
2775 ## preremove scripts
2776 if [ -n "$(typeset -f preremove)" ]
2777 then
2778 echo -e " ${COLBLUE}***${COLDEFAULT} running preremove ... "
2779 preremove
2780 unset preremove
2781 fi
2782
2783 # runs uninstall
2784 build_douninstall \
2785 --pcat "${pcat}" \
2786 --pname "${pname}" \
2787 --pver "${pver}" \
2788 --pbuild "${pbuild}"
2789
2790 ## postremove scripts
2791 if [ -n "$(typeset -f postremove)" ]
2792 then
2793 echo -e " ${COLBLUE}***${COLDEFAULT} running postremove ... "
2794 postremove
2795 unset postremove
2796 fi
2797
2798 # removes the database entry
2799 remove_database_entry \
2800 --pcat "${pcat}" \
2801 --pname "${pname}" \
2802 --pver "${pver}" \
2803 --pbuild "${pbuild}" \
2804 || die "error in mage_uninstall() running remove_database_entry()."
2805
2806 # rebuilds toplevel info node
2807 if [[ ${MAGE_INFO_REBUILD} = true ]]
2808 then
2809 echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2810 echo -n "rebuilding top-level info node ... "
2811 ${MLIBDIR}/mkinfodir ${MROOT}/usr/share/info \
2812 > ${MROOT}/usr/share/info/dir && \
2813 echo "done." || echo "failure."
2814 unset MAGE_INFO_REBUILD
2815 fi
2816
2817 # rebuilds the enviroment with the content of /etc/env.d
2818 if [[ ${MAGE_ENV_REBUILD} = true ]]
2819 then
2820 echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2821 echo -n "rebuilding environment ... "
2822 ${MLIBDIR}/env-rebuild.sh > /dev/null && \
2823 echo "done." || echo "failure."
2824 unset MAGE_ENV_REBUILD
2825 fi
2826
2827 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2828 echo -n "package "
2829 # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2830 # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2831 echo "successfully removed."
2832
2833 # unset these functions
2834 unset -f preinstall
2835 unset -f postinstall
2836 unset -f preremove
2837 unset -f postremove
2838 }
2839
2840 show_etc_update_mesg()
2841 {
2842 [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
2843
2844 echo
2845 echo -ne "${COLRED}"
2846 echo "Important:"
2847 echo -ne ${COLDEFAULT}
2848 echo "${MAGE_PROTECT_COUNTER} protected file(s) were installed."
2849 echo
2850 echo "Please run 'etc-update' to update your configuration files."
2851 echo
2852 }
2853
2854 pkgsearch()
2855 {
2856 local string="$1"
2857 local result
2858 local pkg
2859 local pcat
2860 local pname
2861 local magefile
2862 local pver
2863 local pbuild
2864 local state
2865 local descriptiom
2866 local homepage
2867 local i
2868 local all_installed
2869 local ipver
2870 local ipbuild
2871 local latest_available
2872 local depsfull
2873 local sdepsfull
2874 local deps
2875 local sdeps
2876 local dep
2877 local sign
2878
2879 # only names no versions
2880 result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
2881 #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
2882
2883 # nothing found
2884 [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
2885
2886 for pkg in ${result}
2887 do
2888 # dirty, but does the job
2889 pcat="$(magename2pcat ${pkg}/foo)"
2890 pname="$(magename2pname ${pkg}-foo-foo)"
2891
2892 # get highest version available
2893 magefile=$(get_highest_magefile ${pcat} ${pname})
2894
2895 if [[ ! -z ${magefile} ]]
2896 then
2897 # now get all needed infos to print a nice output
2898 pver="$(magename2pver ${magefile})"
2899 pbuild="$(magename2pbuild ${magefile})"
2900 state="$(get_value_from_magefile STATE ${magefile})"
2901 description="$(get_value_from_magefile DESCRIPTION ${magefile})"
2902 homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
2903
2904 # all installed
2905 for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
2906 do
2907 ipver="$(magename2pver ${i})"
2908 ipbuild="$(magename2pbuild ${i})"
2909
2910 if [[ -z ${all_installed} ]]
2911 then
2912 all_installed="${ipver}-${ipbuild}"
2913 else
2914 all_installed="${all_installed} ${ipver}-${ipbuild}"
2915 fi
2916 done
2917 [[ -z ${all_installed} ]] && all_installed="none"
2918
2919 case ${state} in
2920 stable) state=${COLGREEN}"[s] ";;
2921 testing) state=${COLYELLOW}"[t] ";;
2922 unstable) state=${COLRED}"[u] ";;
2923 old) state=${COLGRAY}"[o] ";;
2924 esac
2925
2926 latest_available="${pver}-${pbuild}"
2927 else
2928 # package is masked
2929 state="${COLRED}[m] "
2930 latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
2931 fi
2932
2933 depsfull="$(get_value_from_magefile DEPEND ${magefile})"
2934 sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
2935
2936 while read sign dep
2937 do
2938 case ${dep} in
2939 "") continue;;
2940 esac
2941
2942 deps="${deps} $(basename ${dep%-*})"
2943 done << EOF
2944 ${depsfull}
2945 EOF
2946
2947 while read sign dep
2948 do
2949 case ${dep} in
2950 "") continue;;
2951 esac
2952
2953 sdeps="${sdeps} $(basename ${dep%-*})"
2954 done << EOF
2955 ${sdepsfull}
2956 EOF
2957
2958 echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
2959 echo -e " Latest available: ${latest_available}"
2960 echo " Installed versions: ${all_installed}"
2961 echo " Description: ${description}"
2962 echo " Homepage: ${homepage}"
2963 echo " Depends: ${deps}"
2964 echo " SDepends: ${sdeps}"
2965 echo
2966
2967 unset pcat
2968 unset pname
2969 unset magefile
2970 unset pver
2971 unset pbuild
2972 unset state
2973 unset descriptiom
2974 unset homepage
2975 unset all_installed
2976 unset ipver
2977 unset ipbuild
2978 unset depsfull
2979 unset sdepsfull
2980 unset deps
2981 unset sdeps
2982 unset dep
2983 unset sign
2984 done
2985 }
2986
2987 export_inherits()
2988 {
2989 local include="$1"
2990 shift
2991
2992 while [ "$1" ]
2993 do
2994 local functions="$1"
2995
2996 # sanity checks
2997 [ -z "${include}" ] && die "export_inherits(): \$include not given."
2998 [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
2999
3000 eval "${functions}() { ${include}_${functions} ; }"
3001
3002 # debug
3003 [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
3004
3005 shift
3006 done
3007 }
3008
3009 mlibdir()
3010 {
3011 local libdir=lib
3012 [[ ${ARCH} = x86_64 ]] && libdir=lib64
3013
3014 echo "${libdir}"
3015 }
3016
3017 ## blacklisted ${magefile}
3018 blacklisted()
3019 {
3020 [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
3021
3022 # compat
3023 [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3024 [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3025
3026 # support both types for the moment
3027 if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3028 then
3029 local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3030 else
3031 local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3032 fi
3033
3034 # return 0 if the list not exist; nothin is masked
3035 [[ ! -f ${EXCLUDED} ]] && return 0
3036
3037 local MAGEFILE="$1"
3038
3039 local PCAT="$(magename2pcat ${MAGEFILE})"
3040 local PNAME="$(magename2pname ${MAGEFILE})"
3041 local PVER="$(magename2pver ${MAGEFILE})"
3042 local PBUILD="$(magename2pbuild ${MAGEFILE})"
3043
3044 local EXPCAT EXPNAME EXPVER EXPBUILD
3045 while read EXPCAT EXPNAME EXPVER EXPBUILD
3046 do
3047 # ignore spaces and comments
3048 case "${EXPCAT}" in
3049 \#*|"") continue ;;
3050 esac
3051
3052 # exclude full pver
3053 if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3054 [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3055 [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3056 [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3057 then
3058 [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3059 fi
3060
3061 # exclude pcat/pname only
3062 if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3063 [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3064 [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3065 then
3066 [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3067 fi
3068 done << EOF
3069 $( cat ${EXCLUDED}; echo)
3070 EOF
3071
3072 return 0
3073 }
3074
3075 # need_busybox_support ${cmd}
3076 # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3077 need_busybox_support()
3078 {
3079 local cmd
3080 cmd="$1"
3081
3082 if [[ -x /bin/busybox ]]
3083 then
3084 if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]
3085 then
3086 # needs busybox support
3087 return 0
3088 else
3089 # no busybox
3090 return 1
3091 fi
3092 fi
3093 }
3094
3095 # busybox_filter_wget_options ${wget_opts}
3096 busybox_filter_wget_options()
3097 {
3098 local opts="$@"
3099 local i
3100 local fixed_opts
3101
3102 if need_busybox_support wget
3103 then
3104 for i in ${opts}
3105 do
3106 # show only the allowed ones
3107 case ${i} in
3108 -c|--continue) fixed_opts+=" -c" ;;
3109 -s|--spider) fixed_opts+=" -s" ;;
3110 -q|--quiet) fixed_opts+=" -q" ;;
3111 -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3112 --header) shift; fixed_opts+=" --header $1" ;;
3113 -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3114 -P) shift; fixed_opts+=" -P $1" ;;
3115 --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3116 -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3117 # simply drop all other opts
3118 *) continue ;;
3119 esac
3120 done
3121
3122 echo "${fixed_opts}"
3123 else
3124 echo "${opts}"
3125 fi
3126 }