Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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