Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 240 - (show annotations) (download) (as text)
Sun Sep 11 19:47:08 2005 UTC (18 years, 7 months ago) by niro
File MIME type: application/x-sh
File size: 58376 byte(s)
fixed some uninstall issues

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.3 2005-09-11 19:47:08 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 # sets fieldseperator to "§" instead of " "
936 IFS=§
937
938 # reversed order is mandatory !
939 tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix
940 do
941 [ -z "${pathto}" ] && continue
942
943 if [ ! -d "${MROOT}${pathto}" ]
944 then
945 [[ ${VERBOSE} = on ]] && \
946 echo -e "${COLRED}! exist${COLDEFAULT} === DIR: ${MROOT}${pathto}"
947 continue
948 fi
949
950 # exclude .keep directories
951 if [ -f "${MROOT}${pathto}/.keep" ]
952 then
953 [[ ${VERBOSE} = on ]] && \
954 echo -e "${COLRED}! .keep${COLDEFAULT} === DIR: ${MROOT}${pathto}"
955 continue
956 fi
957
958 # monitors /etc/env.d -> env-rebuild
959 [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
960
961 # monitors /usr/share/info -> info-rebuild
962 [[ ${pathto} = /usr/share/info ]] && export MAGE_INFO_REBUILD=true
963
964 if rmdir "${MROOT}${pathto}" &> /dev/null
965 then
966 [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR: ${MROOT}${pathto}"
967 else
968 [[ ${VERBOSE} = on ]] && \
969 echo -e "${COLRED}! empty${COLDEFAULT} === DIR: ${MROOT}${pathto}"
970 fi
971 done
972
973 # very important: unsetting the '§' fieldseperator
974 IFS=$'\n'
975 }
976
977
978 ###################################################
979 # function build_douninstall #
980 # build_douninstall $PKGNAME #
981 # NOTE: this is an wrapper do remove packages #
982 ###################################################
983 build_douninstall()
984 {
985 local pcat
986 local pname
987 local pver
988 local pbuild
989 local i
990
991 # very basic getops
992 for i in $*
993 do
994 case $1 in
995 --pcat|-c) shift; pcat="$1" ;;
996 --pname|-n) shift; pname="$1" ;;
997 --pver|-v) shift; pver="$1" ;;
998 --pbuild|-b) shift; pbuild="$1" ;;
999 esac
1000 shift
1001 done
1002
1003 # sanity checks; abort if not given
1004 [ -z "${pcat}" ] && die "build_douninstall() \$pcat not given."
1005 [ -z "${pname}" ] && die "build_douninstall() \$pname not given."
1006 [ -z "${pver}" ] && die "build_douninstall() \$pver not given."
1007 [ -z "${pbuild}" ] && die "build_douninstall() \$pbuild not given."
1008
1009 # this is only a wrapper
1010
1011 # NOTE:
1012 # !! we use § as field seperator !!
1013 # doing so prevent us to get errors by filenames with spaces
1014
1015 for i in symlinks files blockdevices characterdevices directories
1016 do
1017 remove_${i} \
1018 --pcat "${pcat}" \
1019 --pname "${pname}" \
1020 --pver "${pver}" \
1021 --pbuild "${pbuild}" \
1022 || die "remove ${i} ${pcat}/${pname}-${pver}-${pbuild}"
1023 done
1024 }
1025
1026 # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1027 fetch_packages()
1028 {
1029 local list="$@"
1030 local pkg
1031 local mirr
1032 local magefile
1033 local md5file
1034 local opt
1035 local count_current
1036 local count_total
1037
1038 [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc."
1039
1040 # get count of total packages
1041 declare -i count_current=0
1042 declare -i count_total=0
1043
1044 for i in ${list}; do (( count_total++ )); done
1045
1046 for magefile in ${list}
1047 do
1048 pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"
1049 pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1050
1051 (( count_current++ ))
1052 xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"
1053
1054 # abort on virtual pkg
1055 if [[ ${pkgtype} = virtual ]]
1056 then
1057 echo -ne " ${COLBLUE}---${COLDEFAULT}"
1058 echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "
1059 continue
1060 fi
1061
1062 # abort on sources pkg
1063 if [[ ${pkgtype} = sources ]]
1064 then
1065 echo -ne " ${COLBLUE}---${COLDEFAULT}"
1066 echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "
1067 continue
1068 fi
1069
1070 # abort if already exist
1071 if [ -f ${PKGDIR}/${pkg} ]
1072 then
1073 echo -ne " ${COLBLUE}***${COLDEFAULT}"
1074 echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "
1075 continue
1076 fi
1077
1078 for mirr in ${MIRRORS}
1079 do
1080 echo -ne " ${COLBLUE}***${COLDEFAULT}"
1081 #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... "
1082 echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1083 [[ ${VERBOSE} = off ]] && opt="--quiet"
1084 wget \
1085 --passive-ftp \
1086 --tries 3 \
1087 --continue \
1088 --progress bar \
1089 --directory-prefix=${PKGDIR} \
1090 ${opt} ${mirr}/packages/${pkg}
1091 if [[ $? = 0 ]]
1092 then
1093 break
1094 else
1095 continue
1096 fi
1097 done
1098
1099 if [ ! -f ${PKGDIR}/${pkg} ]
1100 then
1101 die "Could not download ${pkg}"
1102 fi
1103 done
1104
1105 # add a crlf for a better view
1106 if [ ${count_total} -gt 1 ]; then echo; fi
1107 }
1108
1109 syncmage()
1110 {
1111 if [ -z "${RSYNC}" ]
1112 then
1113 die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."
1114 fi
1115
1116 local i
1117 for i in ${RSYNC}
1118 do
1119 rsync \
1120 --recursive \
1121 --links \
1122 --perms \
1123 --times \
1124 --devices \
1125 --timeout=600 \
1126 --verbose \
1127 --compress \
1128 --progress \
1129 --stats \
1130 --delete \
1131 --delete-after \
1132 ${i} ${MAGEDIR}
1133 if [[ $? = 0 ]]
1134 then
1135 break
1136 else
1137 continue
1138 fi
1139 done
1140
1141 # clean up backup files (foo~)
1142 find ${MAGEDIR} -name *~ -exec rm '{}' ';'
1143
1144 # check if an newer mage version is available
1145 is_newer_mage_version_available
1146 }
1147
1148 cleanpkg()
1149 {
1150 if [ -d "${PKGDIR}" ]
1151 then
1152 echo -n "Removing downloaded packages... "
1153 rm -rf ${PKGDIR}/*
1154 echo "done."
1155 fi
1156 }
1157
1158 xtitle()
1159 {
1160 if [[ ${TERM} = xterm ]]
1161 then
1162 echo -ne "\033]0;Mage: $1\007"
1163 fi
1164 return 0
1165 }
1166
1167
1168 xtitleclean()
1169 {
1170 if [[ ${TERM} = xterm ]]
1171 then
1172 echo -ne "\033]0;\007"
1173 fi
1174 return 0
1175 }
1176
1177
1178 # cuts full pathnames or versioniezed names down to basename
1179 choppkgname()
1180 {
1181 #we want this only if full name was used
1182 if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1183 then
1184 #cuts ARCH and PBUILD
1185 #ARCH comes from /etc/mage.rc
1186 MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")
1187
1188 #cuts version number
1189 MAGENAME=$(basename ${MAGENAME%-*} .mage)
1190 fi
1191 }
1192
1193 # get_categorie $PNAME, returns CATEGORIE
1194 # $1=pname
1195 # ret 0=ok, 1=not_found
1196 pname2pcat()
1197 {
1198 local pname="$1"
1199 local repo="$2"
1200 local pcat
1201 local categorie
1202
1203 for pcat in ${MAGEDIR}/*
1204 do
1205 if [ -d ${pcat}/${pname} ]
1206 then
1207 categorie=$(basename ${pcat})
1208 fi
1209 done
1210
1211 echo "${categorie}"
1212 }
1213
1214 # check_stable_package /path/to/foo.mage
1215 # returns 0=stable 1=unstable
1216 check_stable_package()
1217 {
1218 local STATE
1219 STATE="$(get_value_from_magefile STATE "$1")"
1220
1221 # state testing
1222 if [[ ${USE_TESTING} = true ]]
1223 then
1224 case ${STATE} in
1225 testing|stable) return 0 ;;
1226 *) return 1 ;;
1227 esac
1228 fi
1229
1230 # state unstable
1231 if [[ ${USE_UNSTABLE} = true ]]
1232 then
1233 case ${STATE} in
1234 unstable|testing|stable) return 0 ;;
1235 *) return 1 ;;
1236 esac
1237 fi
1238
1239 # no use_state given = stable
1240 case ${STATE} in
1241 stable) return 0 ;;
1242 *) return 1 ;;
1243 esac
1244 }
1245
1246
1247 # get_highest_magefile ${PCAT} ${PNAME}
1248 # fake at moment returns only stable pkgs (must set to be one)
1249 # return $HIGHEST_MAGEFILE
1250 get_highest_magefile()
1251 {
1252 local HIGHEST_MAGEFILE
1253 local PCAT="$1"
1254 local PNAME="$2"
1255 local magefile
1256
1257 for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)
1258 do
1259 # we exclude subdirs (for stuff like a md5sum dir)
1260 [ -d ${magefile} ] && continue
1261 if check_stable_package ${magefile}
1262 then
1263 HIGHEST_MAGEFILE=${magefile}
1264 #for debug only
1265 [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"
1266 fi
1267 done
1268
1269 # stop here if HIGHEST_MAGEFILE is zero
1270 # this package must be unstable or old
1271 if [ -z "${HIGHEST_MAGEFILE}" ]
1272 then
1273 echo
1274 echo -n "All packages named "
1275 echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}
1276 echo -n " are marked "
1277 echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}
1278 echo "."
1279 echo "You need to declare USE_UNSTABLE=true to install this."
1280 echo
1281 echo "Example:"
1282 echo " USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"
1283 echo
1284 echo "Be warned that these packages are not stable and may cause serious problems."
1285 echo "You should know what you are doing, so don't complain about any damage."
1286 echo
1287 return 1
1288 fi
1289
1290 echo "${HIGHEST_MAGEFILE}"
1291 return 0
1292 }
1293
1294
1295 ###################################################
1296 # function is_config_protected #
1297 # is_config_protected /path/to/file #
1298 # #
1299 # returns: #
1300 # 0 - not protected #
1301 # 1 - error #
1302 # 2 - protected #
1303 # 3 - protected but masked #
1304 # #
1305 ###################################################
1306 is_config_protected()
1307 {
1308 local EXPFILE
1309 local TEST
1310 local PROTECTED
1311 local IFS
1312
1313 EXPFILE="${MROOT}$1"
1314
1315 # file does not exist; it can be written
1316 [ ! -e ${EXPFILE} ] && return 0
1317
1318 # to be safe; it may be '§'
1319 IFS=' '
1320
1321 # check ob in config protect
1322 for i in ${CONFIG_PROTECT}
1323 do
1324 # ersetzen von $i nur wenn am anfang der variable
1325 TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1326 if [ "${TEST}" != "${EXPFILE}" ]
1327 then
1328 # setzen das es protected ist
1329 PROTECTED=TRUE
1330
1331 # check ob nicht doch maskiert
1332 for x in ${CONFIG_PROTECT_MASK}
1333 do
1334 TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1335 if [ "${TEST}" != "${EXPFILE}" ]
1336 then
1337 PROTECTED=MASKED
1338 fi
1339 done
1340 fi
1341 done
1342
1343 unset IFS
1344
1345 case ${PROTECTED} in
1346 TRUE)
1347 #echo "I'm protected"
1348 return 2
1349 ;;
1350 MASKED)
1351 #echo "I'm protected, but masked - delete me"
1352 return 3
1353 ;;
1354 *)
1355 #echo "delete me"
1356 return 0
1357 ;;
1358 esac
1359 }
1360
1361
1362 ###################################################
1363 # function count_protected_files #
1364 # count_protected_files /path/to/file #
1365 # #
1366 # note: prints number of protected files #
1367 # exp: 0012 #
1368 ###################################################
1369 count_protected_files()
1370 {
1371 ${MLIBDIR}/writeprotected "$1"
1372 }
1373
1374 # call with
1375 # 'get_uninstall_candidates (--pcat cat --protected pcat/pfull) --pname PNAME'
1376 # returns /path/to/magefile(s)
1377 get_uninstall_candidates()
1378 {
1379 local search_pname
1380 local pkg
1381 local pcat
1382 local pname
1383 local pver
1384 local pbuild
1385 local list
1386 local pcatdir
1387 local protected
1388
1389 # very basic getops
1390 for i in $*
1391 do
1392 case $1 in
1393 --pcat|-c) shift; pcatdir="$1" ;;
1394 --pname|-n) shift; search_pname="$1" ;;
1395 --protected|-p) shift; protected="$1" ;;
1396 esac
1397 shift
1398 done
1399
1400 # sanity checks; abort if not given
1401 [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1402
1403
1404 # check needed global vars
1405 [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1406
1407 # set pcatdir to '*' if empty
1408 [ -z "${pcatdir}" ] && pcatdir=*
1409
1410 for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1411 do
1412 # abort if not a dir
1413 [ ! -d ${pkg} ] && continue
1414
1415 pname="$(magename2pname ${pkg})"
1416
1417 if [[ ${search_pname} = ${pname} ]]
1418 then
1419 pcat="$(magename2pcat ${pkg} installdb)"
1420 pver="$(magename2pver ${pkg})"
1421 pbuild="$(magename2pbuild ${pkg})"
1422
1423 # exclude proteced
1424 [[ ${protected} = ${pcat}/${pname}-${pver}-${pbuild} ]] && continue
1425
1426 list="${list} ${pcat}/${pname}-${pver}-${pbuild}"
1427 fi
1428 done
1429
1430 echo "${list}"
1431 }
1432
1433 # reads virtualdb file
1434 #$1 = virtualname; $2 commands: showpkgs, showline
1435 #return 0 == installed -> shows installed pkg as well
1436 #return 1 == not installed
1437 virtuals_read()
1438 {
1439 local virtualname="$1"
1440 local command="$2"
1441 local virtline
1442 local line x i
1443
1444 # parse file to get virtual_name line
1445 IFS=$'\n'
1446 for line in $(< ${MROOT}${VIRTUALDB_FILE})
1447 do
1448 IFS=$' '
1449 for x in ${line}
1450 do
1451 if [[ ${x} = ${virtualname} ]]
1452 then
1453 virtline="${line}"
1454 [[ ${command} = showline ]] && echo "${line}"
1455 fi
1456 done
1457 IFS=$'\n'
1458 done
1459
1460 unset IFS
1461
1462 # now read the packages linked to VIRTUAL_NAME and output them
1463 if [ -n "${virtline}" ]
1464 then
1465 if [[ ${command} = showpkgs ]]
1466 then
1467 declare -i x=0
1468 for i in ${virtline}
1469 do
1470 if [ ${x} -ge 1 ]
1471 then
1472 echo "${i}"
1473 fi
1474 ((x++))
1475 done
1476 fi
1477 return 0
1478 fi
1479 return 1
1480 }
1481
1482
1483 #add pkg to virtualdb
1484 # $1 == virtualname $2= pkgname
1485 # retvals: 0=ok,added; 1=error; 3=pkg already in virtual
1486 virtuals_add()
1487 {
1488 local virtualname="$1"
1489 local pkgname="$2"
1490 local oldline
1491 local line i
1492 local installed_file
1493
1494 if virtuals_read ${virtualname}
1495 then
1496 # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1497 for i in $(virtuals_read ${virtualname} showpkgs)
1498 do
1499 if [[ ${i} = ${pkgname} ]]
1500 then
1501 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1502 echo "${pkgname} already linked as ${virtualname} ..."
1503 #return 3
1504 return 0
1505 fi
1506 done
1507
1508 echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1509 echo "updating ${virtualname} entry with ${pkgname} ..."
1510 oldline="$(virtuals_read ${virtualname} showline)"
1511
1512 # make a backup
1513 mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
1514
1515 IFS=$'\n'
1516 for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
1517 do
1518 # if the right line, append ${pkgname}, else do nothing
1519 if [[ ${line} = ${oldline} ]]
1520 then
1521 echo "${line} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1522 else
1523 echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
1524 fi
1525 done
1526
1527 #unset IFS
1528 else
1529 echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1530 echo "register ${pkgname} as ${virtualname} ..."
1531 echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1532 fi
1533
1534 return 0
1535 }
1536
1537 #deletes pakages from virtual database
1538 #$1 virtualname; $2 pkgname
1539 virtuals_del() {
1540
1541 local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED
1542
1543 VIRTUAL_NAME=$1
1544 PKG_NAME=$2
1545
1546 #first check if exists
1547 if virtuals_read ${VIRTUAL_NAME}
1548 then
1549 #get method -> delall or update and check if ${PKG_NAME} exists in ${VIRTUAL_NAME}
1550 declare -i x=0
1551 for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)
1552 do
1553 if [ "${i}" == "${PKG_NAME}" ]
1554 then
1555 PKG_INSTALLED=true
1556 fi
1557 ((x++))
1558 done
1559
1560 #abort if not installed
1561 if [ "${PKG_INSTALLED}" != "true" ]
1562 then
1563 echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."
1564 return 0
1565 fi
1566
1567 if [ ${x} -ge 2 ]
1568 then
1569 METHOD=update
1570 else
1571 METHOD=delall
1572 fi
1573
1574 #get the complete line
1575 OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"
1576
1577 #make a backup
1578 mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1579
1580 #parse virtualdb
1581 IFS=$'\n'
1582 for line in $(< ${VIRTUALDB_FILE}.old)
1583 do
1584 if [ "${line}" == "${OLD_LINE}" ]
1585 then
1586 #delall or update?
1587 case ${METHOD} in
1588 update)
1589 echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."
1590 #del PKG_NAME from line
1591 echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}
1592 ;;
1593 delall)
1594 echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."
1595 #continue; do not write anything
1596 continue
1597 ;;
1598 esac
1599 else
1600 echo "${line}" >> ${VIRTUALDB_FILE}
1601 fi
1602 done
1603 unset IFS
1604 else
1605 echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."
1606 fi
1607 }
1608
1609 # gets real pkgname from virtuals.default
1610 #$1=VIRTUAL_NAME; returns PKG_NAME
1611 default_virtualname_to_pkgname()
1612 {
1613 local VIRTUAL_NAME PKG_NAME db_virtualname db_pkgname
1614
1615 VIRTUAL_NAME=$1
1616
1617 while read db_virtualname db_pkgname
1618 do
1619 if [ "${db_virtualname}" == "${VIRTUAL_NAME}" ]
1620 then
1621 PKG_NAME="${db_pkgname}"
1622 fi
1623 done << EOF
1624 $(< ${VIRTUALDB_DEFAULTS})
1625 EOF
1626
1627 if [ -n "${PKG_NAME}" ]
1628 then
1629 echo "${PKG_NAME}"
1630 fi
1631 }
1632
1633 minclude()
1634 {
1635 local i
1636
1637 if [ -n "$@" ]
1638 then
1639 for i in $@
1640 do
1641 [[ ${MAGEDEBUG} = on ]] && \
1642 echo "--- Including ${MAGEDIR}/include/${i}.minc"
1643 source ${MAGEDIR}/include/${i}.minc
1644 done
1645 [[ ${MAGEDEBUG} = on ]] && echo
1646 fi
1647 }
1648
1649 sminclude()
1650 {
1651 local i
1652
1653 if [ -n "$@" ]
1654 then
1655 for i in $@
1656 do
1657 echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
1658 source ${SMAGESCRIPTSDIR}/include/${i}.sminc
1659 done
1660 echo
1661 fi
1662 }
1663
1664 # checks if an newer mage version is available
1665 is_newer_mage_version_available()
1666 {
1667 local newest_mage
1668 local installed_mage
1669
1670 newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"
1671 installed_mage="$(magequery -n mage | cut -d' ' -f5)"
1672
1673 if [[ ${newest_mage} > ${installed_mage} ]]
1674 then
1675 echo
1676 echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
1677 echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
1678 echo "It is recommened to install this newer version"
1679 echo "or your current system installation may brake."
1680 echo
1681 echo -en "Please update mage by running "
1682 echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
1683 echo
1684 fi
1685 }
1686
1687
1688 # returns pname from pkgname
1689 # pkgname2pname $PKGNAME
1690 pkgname2pname()
1691 {
1692 local pname
1693
1694 pname="${1%-*-*-*}"
1695 echo "${pname}"
1696 }
1697
1698 # returns pver from pkgname
1699 # pkgname2pver $PKGNAME
1700 pkgname2pver()
1701 {
1702 local i pver
1703
1704 i="${1/$(pkgname2pname $1)-/}"
1705 pver="${i%-*-*}"
1706 echo "${pver}"
1707 }
1708
1709 # returns pbuild from pkgname
1710 # pkgname2pbuild $PKGNAME
1711 pkgname2pbuild()
1712 {
1713 local pbuild
1714
1715 pbuild="${1##*-}"
1716 echo "${pbuild}"
1717 }
1718
1719 # returns parch from pkgname
1720 # pkgname2parch $PKGNAME
1721 pkgname2parch()
1722 {
1723 local i x parch
1724
1725 i="${1%-*-*}-"
1726 x="${1%-*}"
1727 parch="${x/${i}/}"
1728 echo "${parch}"
1729 }
1730
1731 # returns pname from magename
1732 # magename2pname /PATH/TO/MAGE/FILE
1733 magename2pname()
1734 {
1735 local i pname
1736
1737 i="$(basename $1 .mage)"
1738 pname="${i%-*-*}"
1739 echo "${pname}"
1740 }
1741
1742 # returns pver from magename
1743 # magename2pver /PATH/TO/MAGE/FILE
1744 magename2pver()
1745 {
1746 local i pver
1747
1748 i="$(basename $1 .mage)"
1749 i="${i/$(magename2pname $1)-/}"
1750 pver="${i%-*}"
1751 echo "${pver}"
1752 }
1753
1754 # returns pbuild from magename
1755 # magename2pbuild /PATH/TO/MAGE/FILE
1756 magename2pbuild()
1757 {
1758 local i pbuild
1759
1760 i="$(basename $1 .mage)"
1761 pbuild="${i##*-}"
1762 echo "${pbuild}"
1763 }
1764
1765 # returns pcat from magename
1766 # magename2pcat /PATH/TO/MAGE/FILE
1767 magename2pcat()
1768 {
1769 local i pcat
1770
1771 if [[ ${2} = installdb ]]
1772 then
1773 # go 1 dir back
1774 i="${1%/*}"
1775 else
1776 # go 2 dirs back
1777 i="${1%/*/*}"
1778 fi
1779
1780 # get basename
1781 pcat="${i##*/}"
1782 echo "${pcat}"
1783 }
1784
1785 # returns pcat from DEPEND (without operand ! PCAT/PNAME-VERSION)
1786 # dep2pcat DEPEND
1787 dep2pcat()
1788 {
1789 local pcat
1790
1791 pcat="${1%/*}"
1792 echo "${pcat}"
1793 }
1794
1795 # returns pname from DEPEND (without operand ! PCAT/PNAME-VERSION)
1796 # $2=virtual is used to resolv VDEPEND from virtual packages
1797 # dep2pcat DEPEND (virtual)
1798 dep2pname()
1799 {
1800 local pname
1801
1802 pname="${1##*/}"
1803
1804 # cut version only if not virtual or it will cut the name
1805 if [[ $(dep2pcat $1) != virtual ]] && \
1806 [[ $2 != virtual ]]
1807 then
1808 pname="${pname%-*}"
1809 fi
1810
1811 echo "${pname}"
1812 }
1813
1814 dep2highest_magefile()
1815 {
1816 local pcat
1817 local pname
1818 local magefile
1819 local installed_virtuals
1820
1821 pcat="$(dep2pcat $1)"
1822 pname="$(dep2pname $1)"
1823
1824 if [[ ${pcat} = virtual ]]
1825 then
1826 # first check if virtual is already installed
1827 installed_virtuals="$(virtuals_read ${pcat}/${pname} showpkgs)"
1828 if [ -n "${installed_virtuals}" ]
1829 then
1830 for vpkg in ${installed_virtuals}
1831 do
1832 realpkgname="${vpkg}"
1833 virtualpkgname="${pcat}/${pname}"
1834 pcat="$(dep2pcat ${realpkgname})"
1835 pname="$(dep2pname ${realpkgname} virtual)"
1836 done
1837 else
1838 # choose one from virtualdb defaults (virtuals.defaults)
1839 realpkgname="$(default_virtualname_to_pkgname ${pcat}/${pname})"
1840 virtualpkgname="${pcat}/${pname}"
1841 pcat="$(dep2pcat ${realpkgname})"
1842 pname="$(dep2pname ${realpkgname} virtual)"
1843 fi
1844 fi
1845
1846 magefile="$(get_highest_magefile ${pcat} ${pname})"
1847 echo "${magefile}"
1848 }
1849
1850 # is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}
1851 is_installed()
1852 {
1853 local fullpkgname="$1"
1854
1855 # return 0 if installed
1856 [ -d ${MROOT}${INSTALLDB}/${fullpkgname} ] && return 0
1857
1858 return 1
1859 }
1860
1861 install_packages()
1862 {
1863 local list="$@"
1864 local pkg
1865 local pcat
1866 local pname
1867 local pver
1868 local pbuild
1869 local total_pkgs
1870 local current_pkg
1871 local src_install
1872 local uninstall_list
1873
1874 # check for --src-install
1875 if [[ $1 = --src-install ]]
1876 then
1877 # remove --src-install from list
1878 list=${list/--src-install/}
1879 # enable src-install
1880 src_install="--src-install"
1881 fi
1882
1883 # reset MAGE_PROTECT_COUNTER
1884 declare -i MAGE_PROTECT_COUNTER=0
1885 export MAGE_PROTECT_COUNTER
1886
1887 # get count of total packages
1888 declare -i total_pkgs=0
1889 declare -i current_pkg=0
1890 for i in ${list}; do (( total_pkgs++ )); done
1891
1892 echo
1893
1894 if [[ -n ${MROOT} ]]
1895 then
1896 echo -ne ${COLRED}
1897 echo "!! installing in MROOT=${MROOT}"
1898 echo -ne ${COLDEFAULT}
1899 echo
1900 fi
1901
1902 for pkg in ${list}
1903 do
1904 (( current_pkg++ ))
1905 pcat=$(magename2pcat ${pkg})
1906 pname=$(magename2pname ${pkg})
1907 pver=$(magename2pver ${pkg})
1908 pbuild=$(magename2pbuild ${pkg})
1909
1910 mage_install \
1911 --pcat ${pcat} \
1912 --pname ${pname} \
1913 --pver ${pver} \
1914 --pbuild ${pbuild} \
1915 --count-total ${total_pkgs} \
1916 --count-current ${current_pkg} \
1917 ${src_install}
1918
1919 # check for allready installed packages and remove them
1920 # except the package we have installed
1921 uninstall_list="$(get_uninstall_candidates \
1922 --pcat "${pcat}" \
1923 --pname "${pname}" \
1924 --protected ${pcat}/${pname}-${pver}-${pbuild})"
1925
1926 # uninstall all packges in uninstall_list if not empty
1927 if [ -n "${uninstall_list}" ]
1928 then
1929 echo
1930 uninstall_packages ${uninstall_list} \
1931 || die "install_packges() uninstalling not-needed."
1932 fi
1933
1934 # crlf for better view in VERBOSE mode
1935 #if [[ ${VERBOSE} = on ]]; then echo; fi
1936 echo
1937 done
1938
1939 #echo "DEBUG MAGE_PROTECT_COUNTER=${MAGE_PROTECT_COUNTER}"
1940 show_etc_update_mesg
1941 }
1942
1943 # get_value_from_magefile VARIABLE
1944 # returns the content of this VAR
1945 get_value_from_magefile()
1946 {
1947 local var="$1"
1948 local magefile="$2"
1949 local value
1950
1951 # local all possible vars of a mage file
1952 # to prevent bad issues
1953 local PKGNAME
1954 local STATE
1955 local DESCRIPTION
1956 local HOMEPAGE
1957 local DEPEND
1958 local SDEPEND
1959 local PROVIDE
1960 local PKGTYPE
1961 local preinstall
1962 local postinstall
1963
1964 # sanity checks
1965 [ -f ${magefile} ] && source ${magefile} || \
1966 die "get_value_from_magefile: ${magefile} not found."
1967 [ -z "${var}" ] && die "get_value_from_magefile: \$var not given."
1968
1969 source ${magefile}
1970 eval value=\$$(echo ${var})
1971 echo "${value}"
1972 }
1973
1974 mage_install()
1975 {
1976 # local all possible vars of a mage file
1977 # to prevent bad issues
1978 local PKGNAME
1979 local STATE
1980 local DESCRIPTION
1981 local HOMEPAGE
1982 local DEPEND
1983 local SDEPEND
1984 local PROVIDE
1985 local PKGTYPE
1986 local preinstall
1987 local postinstall
1988
1989 local pcat
1990 local pname
1991 local pver
1992 local pbuild
1993 local count_total
1994 local count_current
1995 local magefile
1996 local src_install
1997
1998 # very basic getops
1999 for i in $*
2000 do
2001 case $1 in
2002 --pcat|-c) shift; pcat="$1" ;;
2003 --pname|-n) shift; pname="$1" ;;
2004 --pver|-v) shift; pver="$1" ;;
2005 --pbuild|-b) shift; pbuild="$1" ;;
2006 --count-total) shift; count_total="$1" ;;
2007 --count-current) shift; count_current="$1" ;;
2008 --src-install|-s) shift; src_install=true ;;
2009 esac
2010 shift
2011 done
2012
2013 # sanity checks; abort if not given
2014 [ -z "${pcat}" ] && die "mage_install() \$pcat not given."
2015 [ -z "${pname}" ] && die "mage_install() \$pname not given."
2016 [ -z "${pver}" ] && die "mage_install() \$pver not given."
2017 [ -z "${pbuild}" ] && die "mage_install() \$pbuild not given."
2018
2019 # check needed global vars
2020 [ -z "${MAGEDIR}" ] && die "mage_install() \$MAGEDIR not set."
2021 [ -z "${INSTALLDB}" ] && die "mage_install() \$INSTALLDB not set."
2022 [ -z "${BUILDDIR}" ] && die "mage_install() \$BUILDDIR not set."
2023
2024 xtitle "[ (${count_current}/${count_total}) Installing ${pcat}/${pname}-${pver}-${pbuild} ]"
2025 echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
2026 echo -n "installing (${count_current}/${count_total}): "
2027 echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2028 echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2029
2030 magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage"
2031 source ${magefile}
2032
2033 # abort on sources if no srcinstall
2034 if [[ ${PKGTYPE} = sources ]] && [[ ${src_install} != true ]]
2035 then
2036 echo
2037 echo -e "This Package is a Source Package."
2038 echo
2039 echo -e "Only 'srcinstall' works with this type of packages"
2040 echo -en "If you have done a srcinstall before, "
2041 echo -e "you will find the files in /usr/src."
2042 echo
2043 exit 1
2044 fi
2045
2046 ## preinstall scripts
2047 if [ -n "$(typeset -f preinstall)" ]
2048 then
2049 echo -e " ${COLBLUE}***${COLDEFAULT} running preinstall ... "
2050 preinstall
2051 unset preinstall
2052 fi
2053
2054 if [[ ${src_install} = true ]]
2055 then
2056 local smage2file
2057 # check needed global vars
2058 [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not set."
2059 [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not set."
2060 [ -z "${BINDIR}" ] && die "\$BINDIR not set."
2061
2062 # build the package first
2063 if [[ ${MAGEDEBUG} = on ]]
2064 then
2065 echo M:${pname}
2066 echo V:${pver}
2067 echo B:${pbuild}
2068 fi
2069
2070 smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2071 if [ -f "${smage2file}" ]
2072 then
2073 smage2 ${smage2file} || die "compile failed"
2074 else
2075 echo
2076 echo "$(basename ${SMAGEFILE}) not found."
2077 echo "update your smage-tree and try it again."
2078 echo
2079 die
2080 fi
2081 fi
2082
2083 if [[ ${PKGTYPE} != virtual ]] && \
2084 [[ ${PKGTYPE} != sources ]]
2085 then
2086 # show a verbose message on src-install
2087 if [[ ${src_install} = true ]]
2088 then
2089 echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2090 echo -ne "merging files: "
2091 echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2092 echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2093 fi
2094 build_doinstall ${PKGNAME}
2095 fi
2096
2097 ## postinstall scripts
2098 if [ -n "$(typeset -f postinstall)" ]
2099 then
2100 echo -e " ${COLBLUE}***${COLDEFAULT} running postinstall ... "
2101 postinstall
2102 unset postinstall
2103 fi
2104
2105 # install a database entry
2106 install_database_entry \
2107 --pcat "${pcat}" \
2108 --pname "${pname}" \
2109 --pver "${pver}" \
2110 --pbuild "${pbuild}" \
2111 --pkgname "${PKGNAME}" \
2112 --pkgtype "${PKGTYPE}" \
2113 || die "error in mage_install() running install_database_entry()."
2114
2115 # remove the package dir now
2116 if [ -d ${BUILDDIR}/${PKGNAME} ]
2117 then
2118 rm -rf ${BUILDDIR}/${PKGNAME}
2119 fi
2120
2121 # rebuilds toplevel info node
2122 if [[ ${MAGE_INFO_REBUILD} = true ]]
2123 then
2124 echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2125 echo -n "rebuilding top-level info node ... "
2126 ${MLIBDIR}/mkinfodir ${MROOT}/usr/share/info \
2127 > ${MROOT}/usr/share/info/dir && \
2128 echo "done." || echo "failure."
2129 unset MAGE_INFO_REBUILD
2130 fi
2131
2132 # rebuilds the enviroment with the content of /etc/env.d
2133 if [[ ${MAGE_ENV_REBUILD} = true ]]
2134 then
2135 echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2136 echo -n "rebuilding environment ... "
2137 ${MLIBDIR}/env-rebuild.sh > /dev/null && \
2138 echo "done." || echo "failure."
2139 unset MAGE_ENV_REBUILD
2140 fi
2141
2142 xtitleclean
2143
2144 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2145 echo -n "package "
2146 # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2147 # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2148 echo "successfully installed."
2149 }
2150
2151 md5sum_packages()
2152 {
2153 local list="$@"
2154 local magefile
2155 local pcat
2156 local pname
2157 local pkgname
2158 local pkgfile
2159 local pkgtype
2160 local count_current
2161 local count_total
2162
2163 # get count of total packages
2164 declare -i count_current=0
2165 declare -i count_total=0
2166
2167 for i in ${list}; do (( count_total++ )); done
2168
2169 for magefile in ${list}
2170 do
2171 pcat=$(magename2pcat ${magefile})
2172 pname=$(magename2pname ${magefile})
2173 pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2174 md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2175 pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"
2176 pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2177
2178 (( count_current++ ))
2179 xtitle "[ (${count_current}/${count_total}) MD5SUM: ${pkgfile} ]"
2180
2181 # abort on virtual pkg
2182 if [[ ${pkgtype} = virtual ]]
2183 then
2184 echo -ne " ${COLBLUE}---${COLDEFAULT}"
2185 echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "
2186 continue
2187 fi
2188
2189 # abort on sources pkg
2190 if [[ ${pkgtype} = sources ]]
2191 then
2192 echo -ne " ${COLBLUE}---${COLDEFAULT}"
2193 echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "
2194 continue
2195 fi
2196
2197 if [ -f "${md5file}" ]
2198 then
2199 echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2200 echo -ne "checking md5sum (${count_current}/${count_total}): "
2201 ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"
2202 else
2203 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2204 echo -e "!! no md5sum file found for ${pkgfile} :("
2205 fi
2206 done
2207
2208 # add a crlf for a better view
2209 if [ ${count_total} -gt 1 ]; then echo; fi
2210 }
2211
2212 ## uninstall_packages ulist
2213 uninstall_packages()
2214 {
2215 local list="$@"
2216 local pcat
2217 local pname
2218 local pver
2219 local pbuild
2220 local can_pcat
2221 local can_pname
2222 local can_ver_list
2223
2224 if [[ -n ${MROOT} ]]
2225 then
2226 echo -ne ${COLRED}
2227 echo "!! uninstalling from MROOT=${MROOT}"
2228 echo -ne ${COLDEFAULT}
2229 echo
2230 fi
2231
2232 # generate a candidates list
2233 for pkg in ${list}
2234 do
2235 pcat=$(dep2pcat ${pkg})
2236 pname=$(magename2pname ${pkg})
2237 pver=$(magename2pver ${pkg})
2238 pbuild=$(magename2pbuild ${pkg})
2239 can_pcat="${pcat}"
2240 can_pname="${pname}"
2241
2242 if [ -z "${can_ver_list}" ]
2243 then
2244 can_ver_list=" ${pver}-${pbuild}"
2245 else
2246 can_ver_list="${can_ver_list}, ${pver}-${pbuild}"
2247 fi
2248 done
2249
2250 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2251 echo "following candidate(s) will be removed:"
2252 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2253 echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}"
2254 echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"
2255 echo
2256 if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ]
2257 then
2258 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2259 echo "( Press [CTRL+C] to abort )"
2260 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2261 echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."
2262 for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))
2263 do
2264 echo -ne "${COLRED} ${i}${COLDEFAULT}"
2265 sleep 1
2266 done
2267 echo
2268 echo
2269 fi
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="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${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 }
2418
2419 pkgsearch()
2420 {
2421 local string="$1"
2422 local result
2423 local pkg
2424 local pcat
2425 local pname
2426 local magefile
2427 local pver
2428 local pbuild
2429 local state
2430 local descriptiom
2431 local homepage
2432 local i
2433 local all_installed
2434 local ipver
2435 local ipbuild
2436
2437 # only names no versions
2438 result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name *${string}*)"
2439 #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)"
2440
2441 # nothing found
2442 [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
2443
2444 for pkg in ${result}
2445 do
2446 # dirty, but does the job
2447 pcat="$(magename2pcat ${pkg}/foo)"
2448 pname="$(magename2pname ${pkg}-foo-foo)"
2449
2450 # get highest version available
2451 magefile=$(get_highest_magefile ${pcat} ${pname})
2452
2453 # now get all needed infos to print a nice output
2454 pver="$(magename2pver ${magefile})"
2455 pbuild="$(magename2pbuild ${magefile})"
2456 state="$(get_value_from_magefile STATE ${magefile})"
2457 description="$(get_value_from_magefile DESCRIPTION ${magefile})"
2458 homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
2459
2460 # all installed
2461 for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
2462 do
2463 ipver="$(magename2pver ${i})"
2464 ipbuild="$(magename2pbuild ${i})"
2465
2466 if [[ -z ${all_installed} ]]
2467 then
2468 all_installed="${ipver}-${ipbuild}"
2469 else
2470 all_installed="${all_installed} ${ipver}-${ipbuild}"
2471 fi
2472 done
2473 [[ -z ${all_installed} ]] && all_installed="none"
2474
2475 case ${state} in
2476 stable) state=${COLGREEN}"[s] ";;
2477 testing) state=${COLYELLOW}"[t] ";;
2478 unstable) state=${COLRED}"[u] ";;
2479 old) state=${COLGRAY}"[o] ";;
2480 esac
2481
2482 echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
2483 echo " Latest available: ${pver}-${pbuild}"
2484 echo " Installed versions: ${all_installed}"
2485 echo " Description: ${description}"
2486 echo " Homepage: ${homepage}"
2487 echo
2488
2489 unset pcat
2490 unset pname
2491 unset magefile
2492 unset pver
2493 unset pbuild
2494 unset state
2495 unset descriptiom
2496 unset homepage
2497 unset all_installed
2498 unset ipver
2499 unset ipbuild
2500 done
2501 }