Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 190 - (show annotations) (download) (as text)
Fri Aug 19 02:22:37 2005 UTC (18 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 31668 byte(s)
fixed verbose messages and hopefully fixed the version issue ( 2.8.2 > 2.10.0)

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

Properties

Name Value
svn:executable *