Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 226 - (show annotations) (download) (as text)
Fri Sep 9 16:35:46 2005 UTC (18 years, 7 months ago) by niro
File MIME type: application/x-sh
File size: 56350 byte(s)
complete rewrite

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