Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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