Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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