Magellan Linux

Contents of /branches/mage-0_3_7-r6/mage/usr/lib/mage/mage3.functions.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 397 - (show annotations) (download) (as text)
Mon Nov 20 11:54:46 2006 UTC (17 years, 5 months ago) by niro
File MIME type: application/x-sh
File size: 32127 byte(s)
included export_inherits function, to use newer mbuild smage include

1 #!/bin/bash
2 # Magellan Linux Installer Functions (mage.functions.sh)
3 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage3.functions.sh,v 1.17.2.1 2006-11-20 11:54:46 niro Exp $
4
5 mage_setup() {
6 install -d $INSTALLDB
7 }
8
9 fatal_error() {
10 #$1 is the missing file
11 echo -e "\nFatal Error: Package seemed to be corrupt."
12 echo -e "$1 was not found in ${PKGNAME}"
13 exit 1
14 }
15
16 build_unpackpkg() {
17 tar xjmf ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} -C ${BUILDDIR}
18 }
19
20 update_mtime() {
21 local M_MTIME
22 DB_ENTRY=${INSTALLDB}/${CATEGORIE}/${PKGNAME/-${ARCH}/}
23
24 #forcing mtime to same value
25 echo
26 echo -n ">>>> Forcing mtime to the same value ..."
27 #find ${BUILDDIR}/${PKGNAME}/binfiles \
28 # -exec touch -m -r ${BUILDDIR}/${PKGNAME}/.mtime '{}' ';' \
29 # && echo done || echo false
30
31
32 #get new M_MTIME from .mtime
33 M_MTIME=$(stat -c %Y ${DB_ENTRY}/.mtime)
34
35 #updating .files db entries; only if not empty, or they get killed
36 if [ -e "${DB_ENTRY}/.files" ]
37 then
38 if [ -n "$(cat ${DB_ENTRY}/.files)" ]
39 then
40 #make backup
41 mv ${DB_ENTRY}/.files \
42 ${DB_ENTRY}/.files-old
43
44 #sets fieldseperator to "§" instead of " "
45 IFS=§
46
47 #update
48 while read pathto posix user group mtime md5sum
49 do
50 echo "${pathto}§${posix}§${user}§${group}§${M_MTIME}§${md5sum}" \
51 >> ${DB_ENTRY}/.files
52 touch -c -m -r ${DB_ENTRY}/.mtime ${pathto}
53 done < ${DB_ENTRY}/.files-old
54
55 #remove old list
56 rm -f ${DB_ENTRY}/.files-old
57
58 #very important: unsetting the '§' fieldseperator
59 unset IFS
60 fi
61 else
62 fatal_error .files
63 fi
64
65
66 #updating .symlink db entries; only if not empty, or they get killed
67 if [ -e "${DB_ENTRY}/.symlinks" ]
68 then
69 if [ -n "$(cat ${DB_ENTRY}/.symlinks)" ]
70 then
71 #make backup
72 mv ${DB_ENTRY}/.symlinks \
73 ${DB_ENTRY}/.symlinks-old
74
75 #sets fieldseperator to "§" instead of " "
76 IFS=§
77
78 #update
79 while read pathto posix link mtime
80 do
81 echo "${pathto}§${posix}§${link}§${M_MTIME}" \
82 >> ${DB_ENTRY}/.symlinks
83 touch -c -m -r ${DB_ENTRY}/.mtime ${pathto}
84 done < ${DB_ENTRY}/.symlinks-old
85
86 #remove old list
87 rm -f ${DB_ENTRY}/.symlinks-old
88
89 #very important: unsetting the '§' fieldseperator
90 unset IFS
91 fi
92 else
93 fatal_error .symlinks
94 fi
95 }
96
97 ###################################################
98 # function install_direcories #
99 # install_direcories $PKGNAME #
100 ###################################################
101 install_directories() {
102 local PKGNAME
103 PKGNAME=$1
104
105 if [ -e ${BUILDDIR}/${PKGNAME}/.dirs ]
106 then
107
108 #sets fieldseperator to "§" instead of " "
109 IFS=§
110
111 while read pathto posix user group
112 do
113 if [ ! -z "$pathto" ]
114 then
115 if [ "$VERBOSE" == "on" ]
116 then
117 echo -e "\t>>> DIR: $pathto"
118 fi
119 install -m $posix -o $user -g $group -d "$pathto"
120 fi
121 done < ${BUILDDIR}/${PKGNAME}/.dirs
122
123 #very important: unsetting the '§' fieldseperator
124 unset IFS
125 else
126 fatal_error .dir
127 fi
128 }
129
130
131 ###################################################
132 # function install_files #
133 # install_files $PKGNAME #
134 ###################################################
135 install_files(){
136 local PKGNAME
137 local RETVAL
138 local COUNTER
139 local FILENAME
140 local DESTINATION
141
142 PKGNAME=$1
143
144 if [ -e ${BUILDDIR}/${PKGNAME}/.files ]
145 then
146 #sets fieldseperator to "§" instead of " "
147 IFS=§
148
149 while read pathto posix user group mtime md5sum
150 do
151 if [ ! -z "${pathto}" ]
152 then
153 if [ "${VERBOSE}" == "on" ]
154 then
155 echo -e "\t>>> FILE: ${pathto}"
156 fi
157 ### kleiner notfall fix ###
158 if [ ! -d "$(dirname "${pathto}")" ]
159 then
160 install -d "$(dirname "${pathto}")"
161 fi
162
163 #when file exists, check if protected
164 if [ -e "${pathto}" ]
165 then
166 is_config_protected "${pathto}"
167 RETVAL=$?
168
169 # 0 - not protected #
170 # 1 - error #
171 # 2 - protected #
172 # 3 - protected but masked #
173
174 case ${RETVAL} in
175 #file is not protected - overwrite it
176 0|3)
177 FILE="$pathto"
178 install -m ${posix} -o ${user} -g ${group} \
179 ${BUILDDIR}/${PKGNAME}/binfiles/"$FILE" \
180 "$pathto"
181 ;;
182
183 #file is protected - write backup file
184 # "._cfg${COUNTER}_{FILENAME}
185 2)
186 if [ "${VERBOSE}" == "on" ]
187 then
188 # moves the cursor up
189 echo -en \\033[A
190 echo -e "${COLRED}! prot ${COLDEFAULT} === FILE: $pathto"
191 fi
192 FILENAME="$(basename "${pathto}")"
193 FILE="$pathto"
194 COUNTER=$(count_protected_files "${FILE}")
195 DESTINATION="$(dirname "$pathto")/._cfg${COUNTER}_${FILENAME}"
196 install -m ${posix} -o ${user} -g ${group} \
197 ${BUILDDIR}/${PKGNAME}/binfiles/"$FILE" \
198 "${DESTINATION}"
199
200 #set run_etc_update=true
201 PROTECT_COUNT=${PROTECT_COUNT}+1
202 ;;
203 esac
204 else
205 #install file because it does not exists
206 FILE="$pathto"
207 install -m ${posix} -o ${user} -g ${group} \
208 ${BUILDDIR}/${PKGNAME}/binfiles/$FILE \
209 "$pathto"
210 fi
211
212 #not needed anymore ?
213 #if [ ! -z $user ]
214 #then
215 # chown $user:$group $FILE ### <---- test
216 #fi
217 fi
218 done < ${BUILDDIR}/${PKGNAME}/.files
219
220 #very important: unsetting the '§' fieldseperator
221 unset IFS
222 else
223 fatal_error .files
224 fi
225 }
226
227
228 ###################################################
229 # function install_symlinks #
230 # install_symlinks $PKGNAME #
231 ###################################################
232 install_symlinks() {
233 local PKGNAME
234 PKGNAME=$1
235
236 if [ -e ${BUILDDIR}/${PKGNAME}/.symlinks ]
237 then
238 #sets fieldseperator to "§" instead of " "
239 IFS=§
240
241 while read pathto posix link mtime
242 do
243 if [ ! -z "$pathto" ]
244 then
245 if [ "$VERBOSE" == "on" ]
246 then
247 echo -e "\t>>> LINK: $pathto"
248 fi
249 ln -snf $link "$pathto"
250 fi
251 done < ${BUILDDIR}/${PKGNAME}/.symlinks
252
253 #very important: unsetting the '§' fieldseperator
254 unset IFS
255 else
256 fatal_error .symlinks
257 fi
258 }
259
260
261 ###################################################
262 # function install_blockdevices #
263 # install_blockdevices $PKGNAME #
264 ###################################################
265 install_blockdevices() {
266 local PKGNAME
267 PKGNAME=$1
268
269 if [ -e ${BUILDDIR}/${PKGNAME}/.pipes ]
270 then
271 #sets fieldseperator to "§" instead of " "
272 IFS=§
273
274 while read pathto posix
275 do
276 if [ ! -z "$pathto" ]
277 then
278 if [ "$VERBOSE" == "on" ]
279 then
280 echo -e "\t>>> PIPE: $pathto"
281 fi
282 mkfifo -m $posix "$pathto"
283 fi
284 done < ${BUILDDIR}/${PKGNAME}/.pipes
285
286 #very important: unsetting the '§' fieldseperator
287 unset IFS
288 else
289 fatal_error .pipes
290 fi
291 }
292
293
294 ###################################################
295 # function install_characterdevices #
296 # install_characterdevices $PKGNAME #
297 ###################################################
298 install_characterdevices() {
299 local PKGNAME
300 PKGNAME=$1
301
302 if [ -e ${BUILDDIR}/${PKGNAME}/.char ]
303 then
304 #sets fieldseperator to "§" instead of " "
305 IFS=§
306
307 while read pathto posix
308 do
309 if [ ! -z "$pathto" ]
310 then
311 if [ "$VERBOSE" == "on" ]
312 then
313 echo -e "\t>>> CHAR: $pathto"
314 fi
315 mknode -m $posix -c "$pathto"
316 fi
317 done < ${BUILDDIR}/${PKGNAME}/.char
318
319 #very important: unsetting the '§' fieldseperator
320 unset IFS
321 else
322 fatal_error .char
323 fi
324
325 #very important: unsetting the '§' fieldseperator
326 unset IFS
327 }
328
329
330 ###################################################
331 # function build_doinstall #
332 # build_doinstall $PKGNAME #
333 # NOTE: this is an wrapper do install packages #
334 ###################################################
335 build_doinstall() {
336 #this is only a wrapper
337
338 # NOTE:
339 # !! we use § as field seperator !!
340 # doing so prevent us to get errors by filenames with spaces
341
342 local PKGNAME
343 PKGNAME=$1
344
345 install_directories ${PKGNAME}
346 install_files ${PKGNAME}
347 install_symlinks ${PKGNAME}
348 install_blockdevices ${PKGNAME}
349 install_characterdevices ${PKGNAME}
350 }
351
352
353 ###################################################
354 # function install_database_entry #
355 # install_database_entry $PKGNAME $PKGTYPE #
356 # PKGTYPE can be "virtual", "sources" or nothing #
357 ###################################################
358 install_database_entry(){
359 local PKGNAME
360 local PKGTYPE
361
362 PKGNAME=$1
363 PKGTYPE=$2
364
365 #add package to database
366 install -d ${INSTALLDB}/${CATEGORIE}/${PKGNAME/-${ARCH}/}
367
368 #install mage-file to database
369 install -m 0644 -o root -g root \
370 ${MAGEFILE} \
371 ${INSTALLDB}/${CATEGORIE}/${PKGNAME/-${ARCH}/}
372
373 # create fake file descriptors
374 # used by virtual and source packages
375 touch ${INSTALLDB}/${CATEGORIE}/${PKGNAME/-${ARCH}/}/.dirs
376 touch ${INSTALLDB}/${CATEGORIE}/${PKGNAME/-${ARCH}/}/.symlinks
377 touch ${INSTALLDB}/${CATEGORIE}/${PKGNAME/-${ARCH}/}/.files
378 touch ${INSTALLDB}/${CATEGORIE}/${PKGNAME/-${ARCH}/}/.pipes
379 touch ${INSTALLDB}/${CATEGORIE}/${PKGNAME/-${ARCH}/}/.char
380 touch ${INSTALLDB}/${CATEGORIE}/${PKGNAME/-${ARCH}/}/.mtime
381
382 #put category to database
383 echo ${CATEGORIE} > ${INSTALLDB}/${CATEGORIE}/${PKGNAME/-${ARCH}/}/.categorie
384
385 #install PKGTYPE specific files
386 case ${PKGTYPE} in
387 virtual)
388 touch ${INSTALLDB}/${CATEGORIE}/${PKGNAME/-${ARCH}/}/.virtual
389 ;;
390
391 sources)
392 touch ${INSTALLDB}/${CATEGORIE}/${PKGNAME/-${ARCH}/}/.sources
393 ;;
394
395 *)
396 # normal packages needs these files
397 cp -f ${BUILDDIR}/${PKGNAME}/.{char,dirs,files,pipes,symlinks,mtime} \
398 ${INSTALLDB}/${CATEGORIE}/${PKGNAME/-${ARCH}/}
399 ;;
400 esac
401 }
402
403
404 ###################################################
405 # function remove_database_entry #
406 # remove_database_entry $PKGNAME $PKGTYPE #
407 # PKGTYPE can be "virtual", "sources" or nothing #
408 ###################################################
409 remove_database_entry(){
410 local PKGNAME
411 local PKGTYPE
412
413 PKGNAME=$1
414 PKGTYPE=$2
415
416 #removes database entry
417 if [ -d ${INSTALLDB}/${PKGNAME} ]
418 then
419 rm -rf ${INSTALLDB}/${PKGNAME}
420 fi
421 }
422
423
424 ###################################################
425 # function compare_mtime #
426 # compare_mtime $PKGNAME /path/to/file #
427 # #
428 # returns: #
429 # 0=delete me #
430 # 1=keep me #
431 # #
432 # compares mtime of given files in packages #
433 ###################################################
434 compare_mtime(){
435 local DBDIR
436 local pathto
437 local x
438
439 DBDIR=$1
440 pathto=$2
441
442 M_MTIME=$(stat -c %Y ${INSTALLDB}/${DBDIR}/.mtime)
443
444 #if $pathto is a symlink than compare linked binary
445 if [ -L ${pathto} ]
446 then
447 #readlink -f resolves full path of linked file
448 x=$(stat -c %Y "$(readlink -f "${pathto}")")
449 else
450 x=$(stat -c %Y "${pathto}")
451 fi
452
453 if [ "${M_MTIME}" -eq "${x}" ]
454 then
455 #echo "delete me: ${pathto}"
456 return 0
457 else
458 #echo "keep me : ${pathto}"
459 return 1
460 fi
461 }
462
463
464 ###################################################
465 # function remove_symlinks #
466 # remove_symlinks $PKGNAME #
467 ###################################################
468 remove_symlinks() {
469 local PKGNAME
470 local RETVAL
471
472 PKGNAME=$1
473
474 if [ -e ${INSTALLDB}/${PKGNAME}/.symlinks ]
475 then
476 #sets fieldseperator to "§" instead of " "
477 IFS=§
478
479 while read pathto posix link mtime
480 do
481 if [ ! -z "$pathto" ]
482 then
483 if [ -L "$pathto" ]
484 then
485 compare_mtime ${PKGNAME} "${pathto}"
486 RETVAL=$?
487 # 0=delete me #
488 # 1=keep me #
489 case ${RETVAL} in
490 0)
491 if [ "${VERBOSE}" == "on" ]
492 then
493 echo -e "\t<<< LINK: $pathto"
494 fi
495 rm "$pathto"
496 ;;
497 1)
498 if [ "${VERBOSE}" == "on" ]
499 then
500 echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: $pathto"
501 fi
502 ;;
503 esac
504 else
505 if [ "${VERBOSE}" == "on" ]
506 then
507 echo -e "${COLRED}! exist${COLDEFAULT} === LINK: $pathto"
508 fi
509 fi
510 fi
511 done < ${INSTALLDB}/${PKGNAME}/.symlinks
512
513 #very important: unsetting the '§' fieldseperator
514 unset IFS
515 else
516 fatal_error .symlinks
517 fi
518 }
519
520
521 ###################################################
522 # function remove_files #
523 # remove_files $PKGNAME #
524 ###################################################
525 remove_files() {
526 local PKGNAME
527 local RETVAL
528
529 PKGNAME=$1
530
531 #uninstall of files
532 if [ -e ${INSTALLDB}/${PKGNAME}/.files ]
533 then
534 #sets fieldseperator to "§" instead of " "
535 IFS=§
536
537 while read pathto posix user group mtime md5sum
538 do
539 if [ ! -z "$pathto" ]
540 then
541 if [ -e "$pathto" ]
542 then
543 compare_mtime ${PKGNAME} "${pathto}"
544 RETVAL=$?
545 # 0=delete me #
546 # 1=keep me #
547 case ${RETVAL} in
548 0)
549 if [ "${VERBOSE}" == "on" ]
550 then
551 echo -e "\t<<< FILE: $pathto"
552 fi
553 rm "$pathto"
554 ;;
555 1)
556 if [ "${VERBOSE}" == "on" ]
557 then
558 echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: $pathto"
559 fi
560 ;;
561 esac
562 else
563 if [ "${VERBOSE}" == "on" ]
564 then
565 echo -e "${COLRED}! exist${COLDEFAULT} === FILE: $pathto"
566 fi
567 fi
568 fi
569 done < ${INSTALLDB}/${PKGNAME}/.files
570
571 #very important: unsetting the '§' fieldseperator
572 unset IFS
573 else
574 fatal_error .files
575 fi
576 }
577
578
579 ###################################################
580 # function remove_blockdevices #
581 # remove_blockdevices $PKGNAME #
582 ###################################################
583 remove_blockdevices() {
584 local PKGNAME
585 PKGNAME=$1
586
587 if [ -e ${INSTALLDB}/${PKGNAME}/.pipes ]
588 then
589 #sets fieldseperator to "§" instead of " "
590 IFS=§
591
592 while read pathto posix
593 do
594 if [ ! -z "$pathto" ]
595 then
596 if [ "${VERBOSE}" == "on" ]
597 then
598 echo -e "\t<<< PIPE: $pathto"
599 fi
600 rm "$pathto"
601 fi
602 done < ${INSTALLDB}/${PKGNAME}/.pipes
603
604 #very important: unsetting the '§' fieldseperator
605 unset IFS
606 else
607 fatal_error .pipes
608 fi
609 }
610
611
612 ###################################################
613 # function remove_characterdevices #
614 # remove_characterdevices $PKGNAME #
615 ###################################################
616 remove_characterdevices() {
617 local PKGNAME
618 PKGNAME=$1
619
620 if [ -e ${INSTALLDB}/${PKGNAME}/.char ]
621 then
622 #sets fieldseperator to "§" instead of " "
623 IFS=§
624
625 while read pathto posix
626 do
627 if [ ! -z "$pathto" ]
628 then
629 if [ "${VERBOSE}" == "on" ]
630 then
631 echo -e "\t<<< CHAR: $pathto"
632 fi
633 rm "$pathto"
634 fi
635 done < ${INSTALLDB}/${PKGNAME}/.char
636
637 #very important: unsetting the '§' fieldseperator
638 unset IFS
639 else
640 fatal_error .char
641 fi
642 }
643
644
645 ###################################################
646 # function remove_direcories #
647 # remove_direcories $PKGNAME #
648 ###################################################
649 remove_directories() {
650 local PKGNAME
651 PKGNAME=$1
652
653 #uninstall of dirs ## added small hack to fix dirs
654 # must be reverse -> smage2 doesn't sort them
655 if [ -e ${INSTALLDB}/${PKGNAME}/.dirs ]
656 then
657
658 #sort directory order
659 mv ${INSTALLDB}/${PKGNAME}/.dirs ${INSTALLDB}/${PKGNAME}/.dirs_old
660 cat ${INSTALLDB}/${PKGNAME}/.dirs_old | sort > ${INSTALLDB}/${PKGNAME}/.dirs
661
662 #sets fieldseperator to "§" instead of " "
663 IFS=§
664
665 while read pathto posix
666 do
667 if [ ! -z "$pathto" ]
668 then
669 if [ -e "$pathto" ]
670 then
671 if [ "${VERBOSE}" == "on" ]
672 then
673 echo -e "\t<<< DIR: $pathto"
674 fi
675 rmdir "$pathto" &> /dev/null
676 if [ "$?" -ne "0" ]
677 then
678 if [ "${VERBOSE}" == "on" ]
679 then
680 #moves the cursor up
681 echo -en \\033[A
682 echo -e "${COLRED}! empty${COLDEFAULT} === DIR: $pathto"
683 fi
684 fi
685 else
686 if [ "${VERBOSE}" == "on" ]
687 then
688 echo -e "${COLRED}! exist${COLDEFAULT} === DIR: $pathto"
689 fi
690 fi
691 fi
692 done < ${INSTALLDB}/${PKGNAME}/.dirs
693
694 #very important: unsetting the '§' fieldseperator
695 unset IFS
696 else
697 fatal_error .dirs
698 fi
699 }
700
701
702 ###################################################
703 # function build_douninstall #
704 # build_douninstall $PKGNAME #
705 # NOTE: this is an wrapper do remove packages #
706 ###################################################
707 build_douninstall() {
708 #this is only a wrapper
709
710 # NOTE:
711 # !! we use § as field seperator !!
712 # doing so prevent us to get errors by filenames with spaces
713
714 local PKGNAME
715 PKGNAME=$1
716
717 remove_symlinks ${PKGNAME}
718 remove_files ${PKGNAME}
719 remove_blockdevices ${PKGNAME}
720 remove_characterdevices ${PKGNAME}
721 remove_directories ${PKGNAME}
722 }
723
724 getpackages() {
725 if [ -z "$MIRRORS" ]
726 then
727 echo "You have no mirrors defined. Please edit your /etc/mage.rc."
728 exit 1
729 fi
730
731 local i
732 for i in $MIRRORS
733 do
734 wget \
735 --passive-ftp \
736 --tries 3 \
737 --continue \
738 --progress bar \
739 --directory-prefix=${PKGDIR} \
740 ${i}/packages/${PKGNAME}.${PKGSUFFIX}
741 if [ "$?" == "0" ]
742 then
743 break
744 else
745 continue
746 fi
747 done
748 }
749
750 syncmage() {
751 if [ -z "$RSYNC" ]
752 then
753 echo "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."
754 exit 1
755 fi
756
757 local i
758 for i in $RSYNC
759 do
760 rsync \
761 --recursive \
762 --links \
763 --perms \
764 --times \
765 --devices \
766 --timeout=600 \
767 --verbose \
768 --compress \
769 --progress \
770 --stats \
771 --delete \
772 --delete-after \
773 $i $MAGEDIR
774 if [ "$?" == "0" ]
775 then
776 break
777 else
778 continue
779 fi
780 done
781
782 #clean up backup files (foo~)
783 find ${MAGEDIR} -name *~ -exec rm '{}' ';'
784
785 # check if an newer mage version is available
786 is_newer_mage_version_available
787 }
788
789 cleanpkg(){
790 if [ -d "$PKGDIR" ]
791 then
792 echo -n "Removing downloaded packages... "
793 rm -rf ${PKGDIR}/*
794 echo "done."
795 fi
796 }
797
798 ###################################################
799 # function keepfiles #
800 # keepfiles "$CATEGORIE/$PNAME" "$filename" #
801 # note wildchars allowed #
802 ###################################################
803 keepfiles() {
804 local name
805 local keep
806 name="`echo $1| cut -d '/' -f2`"
807 keep="$2"
808
809 DELPKG="`find ${INSTALLDB} -name ${name}*.mage`"
810 DELDIR="${INSTALLDB}/$(basename ${DELPKG} .mage)"
811 cp ${DELDIR}/.files ${DELDIR}/.files-orig
812 sed "s:${keep}::" \
813 ${DELDIR}/.files-orig > ${DELDIR}/.files
814 rm ${DELDIR}/.files-orig
815 }
816
817
818 ###################################################
819 # function injectpkg #
820 # injectpkg "$CATEGORIE/$PNAME" #
821 # note wildchars allowed #
822 ###################################################
823 injectpkg() {
824 local name
825 local categorie
826 local magename
827 name="`echo $1| cut -d '/' -f2`"
828 categorie="`echo $1| cut -d '/' -f1`"
829
830 INJPKG="`find ${MAGEDIR} -name ${name}-*.mage`"
831 for i in ${INJPKG}
832 do
833 magename="$(basename ${INJPKG} .mage)"
834 echo -e "Injecting fake package for ${COLBLUE}${categorie}${COLDEFAULT}/${COLGREEN}${magename}${COLDEFAULT}"
835 install -d ${INSTALLDB}/${magename}
836 touch ${INSTALLDB}/${magename}/{.injected,.files,.dirs,.symlinks,.pipes,.char}
837
838 #installs magefile
839 install -m 0644 -o root -g root \
840 ${MAGEDIR}/${categorie}/${magename}.mage \
841 ${INSTALLDB}/${magename}
842 done
843 }
844
845 ###################################################
846 # function reminjected #
847 # reminjected #
848 # note: removes all injected packages #
849 ###################################################
850 reminjected() {
851 DELINJ="`find ${INSTALLDB} -name .injected`"
852 for i in ${DELINJ}
853 do
854 magename=$(dirname ${i})
855 if [ -d "${magename}" ]
856 then
857 # small fix to protect the mage-db deleting itself, that is not so funny :)
858 if [ "${magename}" != "${INSTALLDB}" ]
859 then
860 echo -e "removing fake package ${COLRED}${magename#${INSTALLDB}/*}${COLDEFAULT}"
861 rm -rf ${magename}
862 fi
863 fi
864 done
865 }
866
867
868 xtitle() {
869 if [ ${TERM} == "xterm" ]
870 then
871 echo -ne "\033]0;Mage: $1\007"
872 fi
873 return 0
874 }
875
876
877 xtitleclean() {
878 if [ ${TERM} == "xterm" ]
879 then
880 echo -ne "\033]0;\007"
881 fi
882 return 0
883 }
884
885
886 spin_processbar() {
887
888 # does not works as it should -- disabled
889 # you musst add and remove a tempfile outside this funktion
890 # to leave this funktion ...
891
892 # before you call this function do this:
893 #
894 # touch /var/tmp/proz
895 # build_doinstall|spin_processbar
896
897 echo -en "Processing: "
898 while [ -f /var/tmp/proz ]
899 do
900 echo -en "-\b"
901 sleep 0.01
902 echo -en "\\ \b\b"
903 sleep 0.01
904 echo -en "|\b"
905 sleep 0.01
906 echo -en "/\b"
907 sleep 0.01
908 done
909 echo "done"
910 return 0
911
912 # when you want to leave the funktion do
913 # something like this:
914 #
915 # #remove spinner tempfile
916 # if [ "$VERBOSE" == "off" ]
917 # then
918 # if [ -f /var/tmp/proz ]
919 # then
920 # rm /var/tmp/proz
921 # fi
922 # fi
923
924 }
925
926
927 #cuts full pathnames or versioniezed names down to basename
928 choppkgname(){
929 #we want this only if full name was used
930 if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
931 then
932 #cuts ARCH and PBUILD
933 #ARCH comes from /etc/mage.rc
934 MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")
935
936 #cuts version number
937 MAGENAME=$(basename ${MAGENAME%-*} .mage)
938 fi
939 }
940
941
942 # get_categorie $PKGNAME, returns CATEGORIE
943 # ret 0=ok, 1=not_found
944 getcategorie(){
945 for CAT in ${MAGEDIR}/*
946 do
947 if [ -d ${CAT}/${MAGENAME} ]
948 then
949 #debug only
950 if [ "$MAGEDEBUG" == "on" ]
951 then
952 echo "$MAGENAME found -> $CAT/$MAGENAME"
953 echo "categorie = $(basename ${CAT})"
954 fi
955 CATEGORIE=$(basename ${CAT})
956 fi
957 done
958
959 #package does not exists
960 if [ -z "$CATEGORIE" ]
961 then
962 echo -e "Package "${COLRED}"\"${MAGENAME}\""${COLDEFAULT}" does not exists."
963 exit 1
964 fi
965 }
966
967
968 #check_stable_package /path/to/foo.mage
969 # returns 0=stable 1=unstable
970 check_stable_package(){
971 #be sure no previous $STATES exists
972 unset STATE
973
974 source $1
975
976 #if USE_UNSTABLE=true this must be prevented
977 if [ "${USE_UNSTABLE}" != "true" ]
978 then
979 if [ "${STATE}" != "stable" ]
980 then
981 return 1
982 else
983 if [ "${STATE}" == "old" ]
984 then
985 return 1
986 fi
987 fi
988 fi
989
990 #unset the sourced varibales;
991 #we'll got bad problems later on if we don't do this
992 unset PKGNAME
993 unset STATE
994 unset DESCRIPTION
995 unset HOMEPAGE
996 unset DEPEND
997 unset SDEPEND
998 unset PROVIDE
999 unset PKGTYPE
1000 unset preinstall
1001 unset postinstall
1002
1003 return 0
1004 }
1005
1006
1007 #get_highest_magefile ${CATEGORIE} ${PKGNAME}
1008 #fake at moment returns only stable pkgs (must set to be one)
1009 # return $HIGHEST_MAGEFILE
1010 get_highest_magefile(){
1011 unset HIGHEST_MAGEFILE
1012 #CATEGORIE=$1
1013 #PKGNAME=$2
1014
1015 for i in $(ls --format=single-column -v ${MAGEDIR}/${CATEGORIE}/${MAGENAME}/*)
1016 do
1017 #we exclude subdirs (for stuff like a md5sum dir)
1018 if [ ! -d ${i} ]
1019 then
1020 check_stable_package ${i}
1021 if [ "$?" == "0" ]
1022 then
1023 HIGHEST_MAGEFILE=${i}
1024 #for debug only
1025 if [ "$MAGEDEBUG" == "on" ]
1026 then
1027 echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"
1028 fi
1029 fi
1030 fi
1031 done
1032
1033 # stop here if HIGHEST_MAGEFILE is zero
1034 # this package must be unstable or old
1035 if [ -z "${HIGHEST_MAGEFILE}" ]
1036 then
1037 echo
1038 echo -n "All packages named "
1039 echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}
1040 echo -n " are marked "
1041 echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}
1042 echo "."
1043 echo "You need to declare USE_UNSTABLE=true to install this."
1044 echo
1045 echo "Example:"
1046 echo " USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"
1047 echo
1048 echo "Be warned that these packages are not stable and may cause serious problems."
1049 echo "You should know what you are doing, so don't complain about any damage."
1050 echo
1051 return 1
1052 fi
1053
1054 MAGEFILE=${HIGHEST_MAGEFILE}
1055 return 0
1056 }
1057
1058
1059 ###################################################
1060 # function is_config_protected #
1061 # is_config_protected /path/to/file #
1062 # #
1063 # returns: #
1064 # 0 - not protected #
1065 # 1 - error #
1066 # 2 - protected #
1067 # 3 - protected but masked #
1068 # #
1069 ###################################################
1070 is_config_protected() {
1071 local EXPFILE
1072 local TEST
1073 local PROTECTED
1074 local IFS
1075
1076 EXPFILE=$1
1077
1078 #to be safe; it may be '§'
1079 IFS=' '
1080
1081 #check ob in config protect
1082 for i in ${CONFIG_PROTECT}
1083 do
1084 #ersetzen von $i nur wenn am anfang der variable
1085 TEST="${EXPFILE/#${i}/Protected}"
1086 if [ "${TEST}" != "${EXPFILE}" ]
1087 then
1088 #setzen das es protected ist
1089 PROTECTED=TRUE
1090
1091 #check ob nicht doch maskiert
1092 for x in ${CONFIG_PROTECT_MASK}
1093 do
1094 TEST="${EXPFILE/#${x}/Protect_Masked}"
1095 if [ "${TEST}" != "${EXPFILE}" ]
1096 then
1097 PROTECTED=MASKED
1098 fi
1099 done
1100 fi
1101 done
1102
1103 unset IFS
1104
1105 case ${PROTECTED} in
1106 TRUE)
1107 #echo "I'm protected"
1108 return 2
1109 ;;
1110 MASKED)
1111 #echo "I'm protected, but masked - delete me"
1112 return 3
1113 ;;
1114 *)
1115 #echo "delete me"
1116 return 0
1117 ;;
1118 esac
1119 }
1120
1121
1122 ###################################################
1123 # function count_protected_files #
1124 # count_protected_files /path/to/file #
1125 # #
1126 # note: prints number of protected files #
1127 # exp: 0012 #
1128 ###################################################
1129 count_protected_files() {
1130 ${MLIBDIR}/writeprotected "$1"
1131 }
1132
1133
1134 #call with 'get_magefile_to_uninstall SEARCHSTRING'
1135 #returns /path/to/magefile
1136 get_magefile_to_uninstall() {
1137 local RESULT
1138 local SSTRING
1139 local i
1140 local x
1141 local z
1142
1143 SSTRING=$1
1144
1145 for i in ${INSTALLDB}/*/*
1146 do
1147 #echo ${i}
1148 #to be sure
1149 if [ -d ${i} ]
1150 then
1151 #echo "DEBUG: stripped i: $(basename ${i%-*-*})"
1152 if [ $(basename ${i%-*-*}) == ${SSTRING} ]
1153 then
1154 #RESULT="${RESULT} ${i}"
1155 CATEGORIE=$(< ${i}/.categorie)
1156 #echo ${CATEGORIE}/$(basename ${RESULT})
1157 RESULT="${RESULT} ${CATEGORIE}/$(basename ${i})"
1158 fi
1159 fi
1160 done
1161
1162 if [ -n "${RESULT}" ]
1163 then
1164 #check if ONE package was found and not more
1165 declare -i x=0
1166 for i in ${RESULT}
1167 do
1168 x=${x}+1
1169 done
1170 if [ ${x} -eq 1 ]
1171 then
1172 #echo "jo ich uninstall $(basename ${RESULT}) ..."
1173 #the mage file
1174 #echo "${RESULT}/$(basename ${RESULT}).mage"
1175
1176 #gets categorie of the package
1177 #CATEGORIE=$(< ${i}/.categorie)
1178 #echo ${CATEGORIE}/$(basename ${RESULT})
1179 echo "${RESULT}"
1180 return 0
1181 else
1182 #echo "More than one package found ..."
1183 echo "${RESULT}"
1184 return 2
1185 fi
1186 else
1187 #echo "No package found named '${SSTRING}'."
1188 echo "${SSTRING}"
1189 return 1
1190 fi
1191 }
1192
1193
1194 # reads virtualdb file
1195 #$1 = virtualname; $2 commands: showpkgs, showline
1196 #return 0 == installed -> shows installed pkg as well
1197 #return 1 == not installed
1198 virtuals_read() {
1199 local VIRTUAL_NAME COMMAND VIRT_LINE line x i
1200
1201 VIRTUAL_NAME=$1
1202 COMMAND=$2
1203
1204 # parse file to get virtual_name line
1205 IFS=$'\n'
1206 for line in $(< ${VIRTUALDB_FILE})
1207 do
1208 IFS=$' '
1209 for x in ${line}
1210 do
1211 if [ "${x}" == "${VIRTUAL_NAME}" ]
1212 then
1213 VIRT_LINE="${line}"
1214
1215 if [ "${COMMAND}" == "showline" ]
1216 then
1217 #give out the non stripped line
1218 echo "${line}"
1219 fi
1220 fi
1221 done
1222
1223 IFS=$'\n'
1224 done
1225
1226 unset IFS
1227
1228 #now read the packages linked to VIRTUAL_NAME and output them
1229 if [ -n "${VIRT_LINE}" ]
1230 then
1231 if [ "${COMMAND}" == "showpkgs" ]
1232 then
1233 declare -i x=0
1234 for i in ${VIRT_LINE}
1235 do
1236 if [ ${x} -ge 1 ]
1237 then
1238 echo "${i}"
1239 fi
1240 ((x++))
1241 done
1242 fi
1243 return 0
1244 fi
1245 return 1
1246 }
1247
1248
1249 #add pkg to virtualdb
1250 # $1 == virtualname $2= pkgname
1251 # retvals: 0=ok,added; 1=error; 3=pkg already in virtual
1252 virtuals_add(){
1253 local VIRTUAL_NAME PKG_NAME OLD_LINE line i
1254
1255 VIRTUAL_NAME=$1
1256 PKG_NAME=$2
1257
1258
1259 if virtuals_read ${VIRTUAL_NAME}
1260 then
1261 #make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1262 for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)
1263 do
1264 if [ "${i}" == ${PKG_NAME} ]
1265 then
1266 echo "==== ${PKG_NAME} already linked with ${VIRTUAL_NAME} ..."
1267 return 3
1268 fi
1269 done
1270
1271 echo ">>>> Updating ${VIRTUAL_NAME} with ${PKG_NAME} in virtual database ..."
1272 OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"
1273
1274 #make a backup
1275 mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1276
1277 IFS=$'\n'
1278 for line in $(< ${VIRTUALDB_FILE}.old)
1279 do
1280 #if the right line, append ${PKG_NAME}, else do nothing
1281 if [ "${line}" == "${OLD_LINE}" ]
1282 then
1283 echo "${line} ${PKG_NAME}" >> ${VIRTUALDB_FILE}
1284 else
1285 echo "${line}" >> ${VIRTUALDB_FILE}
1286 fi
1287 done
1288
1289 unset IFS
1290 else
1291 echo ">>>> Adding ${PKG_NAME} as ${VIRTUAL_NAME} to virtual database ..."
1292 echo "${VIRTUAL_NAME} ${PKG_NAME}" >> ${VIRTUALDB_FILE} \
1293 && echo "ok" || echo "false"
1294 fi
1295
1296 return 0
1297 }
1298
1299 #deletes pakages from virtual database
1300 #$1 virtualname; $2 pkgname
1301 virtuals_del() {
1302
1303 local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED
1304
1305 VIRTUAL_NAME=$1
1306 PKG_NAME=$2
1307
1308 #first check if exists
1309 if virtuals_read ${VIRTUAL_NAME}
1310 then
1311 #get method -> delall or update and check if ${PKG_NAME} exists in ${VIRTUAL_NAME}
1312 declare -i x=0
1313 for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)
1314 do
1315 if [ "${i}" == "${PKG_NAME}" ]
1316 then
1317 PKG_INSTALLED=true
1318 fi
1319 ((x++))
1320 done
1321
1322 #abort if not installed
1323 if [ "${PKG_INSTALLED}" != "true" ]
1324 then
1325 echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."
1326 return 0
1327 fi
1328
1329 if [ ${x} -ge 2 ]
1330 then
1331 METHOD=update
1332 else
1333 METHOD=delall
1334 fi
1335
1336 #get the complete line
1337 OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"
1338
1339 #make a backup
1340 mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1341
1342 #parse virtualdb
1343 IFS=$'\n'
1344 for line in $(< ${VIRTUALDB_FILE}.old)
1345 do
1346 if [ "${line}" == "${OLD_LINE}" ]
1347 then
1348 #delall or update?
1349 case ${METHOD} in
1350 update)
1351 echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."
1352 #del PKG_NAME from line
1353 echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}
1354 ;;
1355 delall)
1356 echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."
1357 #continue; do not write anything
1358 continue
1359 ;;
1360 esac
1361 else
1362 echo "${line}" >> ${VIRTUALDB_FILE}
1363 fi
1364 done
1365 unset IFS
1366 else
1367 echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."
1368 fi
1369 }
1370
1371 # gets real pkgname from virtuals.default
1372 #$1=VIRTUAL_NAME; returns PKG_NAME
1373 default_virtualname_to_pkgname(){
1374 local VIRTUAL_NAME PKG_NAME db_virtualname db_pkgname
1375
1376 VIRTUAL_NAME=$1
1377
1378 while read db_virtualname db_pkgname
1379 do
1380 if [ "${db_virtualname}" == "${VIRTUAL_NAME}" ]
1381 then
1382 PKG_NAME="${db_pkgname}"
1383 fi
1384 done << EOF
1385 $(< ${VIRTUALDB_DEFAULTS})
1386 EOF
1387
1388 if [ -n "${PKG_NAME}" ]
1389 then
1390 echo "${PKG_NAME}"
1391 fi
1392 }
1393
1394 minclude() {
1395 local i
1396
1397 if [ -n "$@" ]
1398 then
1399 for i in $@
1400 do
1401 [[ ${MAGEDEBUG} = on ]] && \
1402 echo "--- Including ${MAGEDIR}/include/${i}.minc"
1403 source ${MAGEDIR}/include/${i}.minc
1404 done
1405 [[ ${MAGEDEBUG} = on ]] && echo
1406 fi
1407 }
1408
1409 sminclude() {
1410 local i
1411
1412 if [ -n "$@" ]
1413 then
1414 for i in $@
1415 do
1416 echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
1417 source ${SMAGESCRIPTSDIR}/include/${i}.sminc
1418 done
1419 echo
1420 fi
1421 }
1422
1423 # checks if an newer mage version is available
1424 is_newer_mage_version_available() {
1425 local newest_mage
1426 local installed_mage
1427
1428 newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"
1429 installed_mage="$(magequery -n mage | cut -d' ' -f5)"
1430
1431 if [[ ${newest_mage} > ${installed_mage} ]]
1432 then
1433 echo
1434 echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
1435 echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
1436 echo "It is recommened to install this newer version"
1437 echo "or your current system installation may brake."
1438 echo
1439 echo -en "Please update mage by running "
1440 echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
1441 echo
1442 fi
1443 }
1444
1445 export_inherits()
1446 {
1447 local include="$1"
1448 shift
1449
1450 while [ "$1" ]
1451 do
1452 local functions="$1"
1453
1454 # sanity checks
1455 [ -z "${include}" ] && die "export_inherits(): \$include not given."
1456 [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
1457
1458 eval "${functions}() { ${include}_${functions} ; }"
1459
1460 # debug
1461 [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
1462
1463 shift
1464 done
1465 }

Properties

Name Value
svn:executable *