Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 212 - (show annotations) (download) (as text)
Sun Aug 28 19:20:08 2005 UTC (18 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 15221 byte(s)
- added NOCOLORS option

1 #!/bin/sh
2 # Magellan Linux Installer (mage.sh)
3 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage3.sh,v 1.20 2005-08-28 19:20:08 niro Exp $
4
5 ##configuration -> mage.rc
6 #PKGDIR="/usr/src/packages"
7 PKGSUFFIX="mpk"
8 #BUILDDIR="/usr/src"
9 #INSTALLDB="/var/ALXInstDB"
10 #MAGEDIR="/usr/src/mage-0.2"
11 MAGENAME="$2"
12 #PKGNAME="`basename $2 .mage`"
13 MLIBDIR=/usr/lib/mage
14 MAGEVERSION="$( < ${MLIBDIR}/version)"
15
16 ## nur für tests -> normalerweise in /etc/rc.d/init.d/functions
17 COLRED="\033[1;6m\033[31m"
18 COLGREEN="\033[1;6m\033[32m"
19 COLBLUE="\033[1;6m\033[34m"
20 COLDEFAULT="\033[0m"
21
22 if [[ ${NOCOLORS} = true ]]
23 then
24 COLRED=""
25 COLGREEN=""
26 COLYELLOW=""
27 COLBLUE=""
28 COLMAGENTA=""
29 COLWHITE=""
30 COLDEFAULT=""
31 fi
32
33 # default path
34 PATH="${PATH}:${MLIBDIR}"
35
36 # export the default C locale
37 export LC_ALL=C
38
39 ##functions
40 if [ -f /etc/mage.rc ]
41 then
42 source /etc/mage.rc
43 else
44 echo "Your /etc/mage.rc is missing. Aborting."
45 exit 1
46 fi
47
48 #virtualdb locations
49 VIRTUALDB_DEFAULTS=/etc/mage-profile/virtuals.defaults
50 VIRTUALDB_FILE=${INSTALLDB}/virtuals
51
52 #fix small problems
53 [ ! -e ${VIRTUALDB_FILE} ] && touch ${VIRTUALDB_FILE}
54
55 if [ ! -e ${VIRTUALDB_DEFAULTS} -a "$1" != "update" ]
56 then
57 echo
58 echo "Please choose an profile from the mage tree."
59 echo "ln -snf ${MAGEDIR}/profiles/profilename /etc/mage-profile"
60 exit 1
61 fi
62
63
64 #loads functions
65 source ${MLIBDIR}/mage3.functions.sh
66
67 #############DIALOGE##############
68 showversion() {
69 echo -en "Magellan Package Manager v${MAGEVERSION} "
70 echo -e "-- Niels Rogalla (niro@magellan-linux.de)"
71 }
72
73 print_usage(){
74 showversion
75 echo -e "\nUsage: (basename $0) [option] pkgname ..."
76 echo "Options:"
77 echo -e "\tpretend - pretends dependencies of a package"
78 echo -e "\tsrcpretend - pretends dependencies of a package (build from source)"
79 echo -e "\tinstall - installs a package"
80 echo -e "\tsrcinstall - installs a package from source"
81 echo -e "\tuninstall - removes a package"
82 echo -e "\tupdate - updates mage-tree"
83 echo -e "\tsearch - searches mage-tree for a package"
84 echo -e "\tclean - removes *all* downloaded packages"
85 echo -e "\tunpack - unpacks a package"
86 echo -e "\tdownload - downloads a package"
87 echo -e "\tkeepfiles - prevents files from uninstalling"
88 echo -e "\tinject - inject a package to fake dependencies"
89 echo -e "\treminjected - removes *all* fake packages"
90 echo -e "\tversion - prints version info"
91 echo
92 echo -e "Other:"
93 echo -e "NOINSTALL=yes $(basename $0) srcinstall PACKAGE"
94 echo -e "Builds a Package with its dependencies, but won't install anything."
95 echo
96 echo -e "BOOTSTRAP=yes $(basename $0) srcinstall PACKAGE"
97 echo -e "Force an bootstrap build for a Package."
98 echo -e "Works only for packages wich take use of that (like glibc and binutils),"
99 echo -e "by any other this feature will simple be ignored."
100 echo
101 echo -e "USE_UNSTABLE=true $(basename $0) [src]install PACKAGE"
102 echo -e "Overrides stable packages; you can install packages that are marked unstable."
103 echo
104 }
105
106 run_etc_update() {
107 if [ ${PROTECT_COUNT} -eq 0 ]
108 then
109 return 0
110 fi
111
112 echo
113 echo "Important:"
114 echo "${PROTECT_COUNT} protected file(s) were installed."
115 echo
116 echo "Please run 'etc-update' to update your configuration files."
117 echo
118 }
119
120 mage_install_virtual(){
121 echo -e "\nInstallation of Package: ${COLGREEN}$PKGNAME${COLDEFAULT}\n"
122
123 export -f preinstall 2> /dev/null
124 if [ "$?" == "0" ]
125 then
126 echo -e "\nRunning Preinstall ... \n"
127 preinstall
128 unset preinstall
129 fi
130
131 #creates fake db entry
132 install_database_entry ${PKGNAME} ${PKGTYPE}
133
134 export -f postinstall 2> /dev/null
135 if [ "$?" == "0" ]
136 then
137 echo -e "\nRunning Postinstall ... \n"
138 postinstall
139 unset postinstall
140 fi
141
142 #check for virtuals and PROVIDE
143 # if so install it to virtualdb
144 register_virtual_pkg
145
146 ${MLIBDIR}/env-rebuild.sh
147 echo -e "\nPackage '${PKGNAME/-${ARCH}/}' sucessfully installed.\n"
148
149 #unsets virtual state of packages
150 unset PKGTYPE
151 return 0
152 }
153
154
155 register_virtual_pkg(){
156 #first check if this pkg is an virtual_pkg
157 #echo "DEB: PKGNAME=${PKGNAME}"
158
159 if [ -e ${BUILDDIR}/virtuals/virtuals.${PKGNAME/-${ARCH}/} ]
160 then
161 #add it
162 source ${BUILDDIR}/virtuals/virtuals.${PKGNAME/-${ARCH}/}
163 virtuals_add ${DB_VIRTUAL_NAME} ${DB_PKG_NAME}
164
165 #than clean up
166 unset DB_VIRTUAL_NAME DB_PKG_NAME
167 rm ${BUILDDIR}/virtuals/virtuals.${PKGNAME/-${ARCH}/}
168 fi
169
170 if [ -n "${PROVIDE}" ]
171 then
172 # wander through all provides
173 local my_provides
174 for my_provides in ${PROVIDE}
175 do
176 local my_pgk
177 #cut arch
178 my_pkg=${PKGNAME/-${ARCH}/}
179 #cut version & build
180 my_pkg=${my_pkg%-*-*}
181
182 virtuals_add ${my_provides} ${CATEGORIE}/${my_pkg}
183 done
184 unset PROVIDE
185 unset my_provides
186 fi
187 }
188
189 unregister_virtual_pkg(){
190 if [ -n "${PROVIDE}" ]
191 then
192 local my_pgk
193 local my_cat
194 local directory
195 local x
196
197 #cut arch
198 my_pkg=${PKGNAME/-${ARCH}/}
199
200 #cut version & build
201 my_pkg=${my_pkg%-*-*}
202 my_cat=$(dirname ${my_pkg})
203
204 #check if this was the last one or if any other exists
205 for directory in ${INSTALLDB}/${my_cat}/*
206 do
207 # continue if not a directory,
208 # or the same PNAME-PVER-PBUILD
209 if [ ! -d "${directory}" ]
210 then
211 continue
212 fi
213
214 #check if $directory is the same as $my_pkg
215 x=$(basename ${directory})
216 if [[ ${my_cat}/${x%-*-*} = ${my_pkg} ]]
217 then
218 # break here
219 echo "==== another version of ${my_pkg} exists, not deleting ${VIRTUAL_NAME} ..."
220 return 0
221 fi
222 done
223
224 #virtuals_del ${PROVIDE} ${CATEGORIE}/${my_pkg}
225
226 # wander through all provides
227 local my_provides
228 for my_provides in ${PROVIDE}
229 do
230 #my_pkg has already the categorie -> ex my_pkg=x11-base/xfree
231 virtuals_del ${my_provides} ${my_pkg}
232 done
233
234 unset PROVIDE
235 unset my_provides
236 fi
237 }
238
239 mage_install_sources() {
240
241 #creates fake db entry
242 install_database_entry ${PKGNAME} ${PKGTYPE}
243
244 #check for virtuals and PROVIDE
245 # if so install it to virtualdb
246 register_virtual_pkg
247
248 echo
249 echo -e "This Package is a Source Package."
250 echo
251 echo -e "Only 'srcinstall' works with this type of packages"
252 echo -en "If you have done a srcinstall before, "
253 echo -e "you will find the files in /usr/src."
254 echo
255
256 #nice timer (4 seconds)
257 # local x
258 # declare -i x=4
259 # echo -en "Continues in 4s ..."
260 # while [ ${x} -gt 0 ]
261 # do
262 # i=${x}+1
263 # echo -en "\b\b\b\b\b\b${x}s ..."
264 # #beeper
265 # echo -en "\a"
266 # sleep 1
267 # done
268 # echo
269
270 sleep 1
271 xtitleclean
272 }
273
274 mage_install() {
275 local MAGEFILE
276 local PKGTARBALL
277
278 MAGEFILE=$1
279
280 source ${MAGEFILE}
281
282 #abbruch wenn schon installiert
283 if [ -e ${INSTALLDB}/${PKGNAME/-${ARCH}/} ]
284 then
285 echo -en "\n${COLRED}Package '${PKGNAME/-${ARCH}/}'" \
286 echo -e "already installed. Installation Aborted.${COLDEFAULT}\n"
287 exit 3
288 fi
289
290 xtitle "[ Installing ${PKGNAME/-${ARCH}/} ]"
291
292 if [ "${PKGTYPE}" == "virtual" ]
293 then
294 mage_install_virtual
295 return 0
296 fi
297
298 if [ "${PKGTYPE}" == "sources" ]
299 then
300 mage_install_sources
301 return 0
302 fi
303
304 if [ ! -e ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} ]
305 then
306 echo -en "\nPrefetching needed Packages for "
307 echo -e "${COLGREEN}${PKGNAME/-${ARCH}/}${COLDEFAULT}...\n"
308 getpackages
309 fi
310
311 echo -e "\nInstallation of Package: ${COLGREEN}${PKGNAME/-${ARCH}/}${COLDEFAULT}\n"
312 #( build_unpackpkg ) | echo -e "Unpacking Package ...\n"
313
314 echo -en "Unpacking Package ..."
315 build_unpackpkg
316 echo "done"
317
318 ##preinstall scripte
319 export -f preinstall 2> /dev/null
320 if [ "$?" == "0" ]
321 then
322 echo -e "\nRunning Preinstall ... \n"
323 preinstall
324 unset preinstall
325 fi
326
327 #install of package
328 if [ "$VERBOSE" == "off" ]
329 then
330 #spinner disabled
331 #touch /var/tmp/proz
332 #build_doinstall|spin_processbar
333
334 echo -en "Processing ... "
335 build_doinstall ${PKGNAME}
336 echo "done"
337 fi
338
339 if [ "$VERBOSE" == "on" ]
340 then
341 #build_doinstall
342 build_doinstall ${PKGNAME}
343 fi
344
345 #postinstall scripte
346 export -f postinstall 2> /dev/null
347 if [ "$?" == "0" ]
348 then
349 echo -e "\nRunning Postinstall ... \n"
350 postinstall
351 unset postinstall
352 fi
353
354 #install database entry
355 install_database_entry ${PKGNAME}
356
357 #cleanup
358 if [ -d ${BUILDDIR}/${PKGNAME} ]
359 then
360 rm -rf ${BUILDDIR}/${PKGNAME}
361 fi
362
363
364 #check for virtuals and PROVIDE
365 # if so install it to virtualdb
366 register_virtual_pkg
367
368
369 #update mtimes of packages and db_entries
370 update_mtime
371
372 #rebuilds toplevel info node
373 echo -en "\n>>>> Rebuilding top-level info node ... "
374 ${MLIBDIR}/mkinfodir /usr/share/info > /usr/share/info/dir \
375 && echo "done" || echo "false"
376
377 #rebuilds the enviroment with the content of /etc/env.d
378 ${MLIBDIR}/env-rebuild.sh
379
380 xtitleclean
381
382 echo -e "\nPackage '${PKGNAME/-${ARCH}/}' sucessfully installed.\n"
383 }
384
385 mage_uninstall() {
386 # #installdbhome #packagedir #magefile
387 #source ${INSTALLDB}/$(basename ${MAGENAME} .mage)/$(basename ${MAGENAME})
388 #source ${INSTALLDB}/${CATEGORIE}/$(basename ${MAGENAME} .mage)/$(basename ${MAGENAME})
389
390 local UNINST_MAGEFILE CAT_PKGNAME
391
392 CAT_PKGNAME=$1
393
394 #trim pkgname from CAT_PKGNAME to get magefile name
395 UNINST_MAGEFILE="$(echo ${CAT_PKGNAME}| cut -d / -f2).mage"
396
397 #then source it
398 source ${INSTALLDB}/${CAT_PKGNAME}/${UNINST_MAGEFILE}
399
400 #fix for mage-0.3.6-r5
401 #PKGNAME=${PKGNAME/-${ARCH}/}
402 PKGNAME=${CAT_PKGNAME}
403
404 #if [ ! -e ${INSTALLDB}/${PKGNAME/-${ARCH}/} ]
405 if [ ! -e ${INSTALLDB}/${CAT_PKGNAME} ]
406 then
407 echo -e "\nPackage '${PKGNAME}' is not installed. Uninstallation Aborted.\n"
408 exit 3
409 fi
410
411 echo -e "\nUninstall of Package:\t${COLRED}${PKGNAME}${COLDEFAULT}\n"
412
413 if [ -z "${MAGE_UNINSTALL_TIMEOUT}" ]
414 then
415 MAGE_UNINSTALL_TIMEOUT=5
416 fi
417
418 for ((i=0; i < MAGE_UNINSTALL_TIMEOUT; i++))
419 do
420 timeout=$(expr ${MAGE_UNINSTALL_TIMEOUT} - ${i})
421 echo -e "Starting in ${COLRED} ${timeout}" \
422 "${COLDEFAULT} seconds ... ( [CTRL+C] to abort )"
423 sleep 1
424 #moves the cursor up
425 echo -en \\033[A
426 done
427
428 #moves the cursor up
429 echo -en \\033[A
430 #min. 30 spaces needed for clearing up the rest of the line
431 echo -e "\nUninstall ${COLRED}started${COLDEFAULT} ..." \
432 " \n"
433 sleep 1
434
435
436 ##preremove scripte
437 export -f preremove 2> /dev/null
438 if [ "$?" == "0" ]
439 then
440 echo -e "\nRunning Preremove ... \n"
441 preremove
442 unset preremove
443 fi
444
445 #runs uninstall
446 build_douninstall ${PKGNAME}
447
448 #postremove scripte
449 export -f postremove 2> /dev/null
450 if [ "$?" == "0" ]
451 then
452 echo -e "\nRunning Postremove ... \n"
453 postremove
454 unset postremove
455 fi
456
457 #remove database entry
458 remove_database_entry ${PKGNAME}
459
460 #check for PROVIDE
461 # if so uninstall it from virtualdb
462 unregister_virtual_pkg
463
464 #rebuilds toplevel info node
465 echo -en "\n>>>> Rebuilding top-level info node ... "
466 ${MLIBDIR}/mkinfodir /usr/share/info > /usr/share/info/dir \
467 && echo "done" || echo "false"
468
469 #rebuilds the enviroment with the content of /etc/env.d
470 ${MLIBDIR}/env-rebuild.sh
471
472 echo -e "\nPackage '${PKGNAME}' sucessfully removed.\n"
473 }
474
475
476 case "$1" in
477 download)
478 choppkgname
479 getcategorie
480 get_highest_magefile || exit 1
481 source ${MAGEFILE}
482 getpackages
483 ;;
484
485 pretend)
486 choppkgname
487 getcategorie
488 get_highest_magefile || exit 1
489 ${MLIBDIR}/depwanderer.sh pretend ${MAGEFILE}
490 #abort already installed
491 if [ "$?" == "3" ]
492 then
493 echo -en "Package "
494 echo -en "${COLRED}$(basename ${MAGEFILE} .mage)${COLDEFAULT}"
495 echo -e " already installed."
496 fi
497 ;;
498
499 srcpretend)
500 choppkgname
501 getcategorie
502 get_highest_magefile || exit 1
503 ${MLIBDIR}/depwanderer.sh srcpretend ${MAGEFILE}
504 #abort already installed
505 if [ "$?" == "3" ]
506 then
507 echo -en "Package "
508 echo -en "${COLRED}$(basename ${MAGEFILE} .mage)${COLDEFAULT}"
509 echo -e " already installed."
510 fi
511 ;;
512
513 install)
514 #counter for protected files
515 declare -i PROTECT_COUNT=0
516 choppkgname
517 getcategorie
518 get_highest_magefile || exit 1
519 ALLDEPS="$(/usr/lib/mage/depwanderer.sh install ${MAGEFILE})"
520 #abort already installed
521 if [ "$?" == "3" ]
522 then
523 echo -en "Package "
524 echo -en "${COLRED}$(basename ${MAGEFILE} .mage)${COLDEFAULT}"
525 echo -e " already installed."
526 echo -e "Installation aborted."
527 exit 0
528 fi
529 for i in ${ALLDEPS}
530 do
531 #first unset all vars to be safe
532 unset PKGNAME
533 unset STATE
534 unset DESCRIPTION
535 unset HOMEPAGE
536 unset DEPEND
537 unset SDEPEND
538 unset PROVIDE
539 unset PKGTYPE
540 unset preinstall
541 unset postinstall
542
543 #then source an evtl new generated profile
544 [ -e /etc/profile ] && source /etc/profile
545
546 #than install
547 MY_CAT_FIX="$(dirname ${i})"
548 CATEGORIE="$(basename ${MY_CAT_FIX%/*})"
549 mage_install ${i}
550 done
551 run_etc_update
552 ;;
553
554 srcinstall)
555 #counter for protected files
556 declare -i PROTECT_COUNT=0
557 choppkgname
558 getcategorie
559 get_highest_magefile || exit 1
560 ALLDEPS="$(/usr/lib/mage/depwanderer.sh srcinstall ${MAGEFILE})"
561 #abort already installed
562 if [ "$?" == "3" ]
563 then
564 echo -en "Package "
565 echo -en "${COLRED}$(basename ${MAGEFILE} .mage)${COLDEFAULT}"
566 echo -e " already installed."
567 echo -e "Installation aborted."
568 exit 0
569 fi
570 for i in ${ALLDEPS}
571 do
572 #first unset all vars to be safe
573 unset PKGNAME
574 unset STATE
575 unset DESCRIPTION
576 unset HOMEPAGE
577 unset DEPEND
578 unset SDEPEND
579 unset PROVIDE
580 unset PKGTYPE
581 unset preinstall
582 unset postinstall
583
584 #then source an evtl new generated profile
585 [ -e /etc/profile ] && source /etc/profile
586
587 #than srcinstall
588 MY_CAT_FIX="$(dirname ${i})"
589 CATEGORIE="$(basename ${MY_CAT_FIX%/*})"
590 #builds the package from source
591 ${MLIBDIR}/sourceinstall.sh ${i} "${MAGE_TARGETS}" || exit 1
592 done
593 run_etc_update
594 ;;
595
596 uninstall)
597 RESULT=$(get_magefile_to_uninstall ${MAGENAME})
598 #get_magefile_to_uninstall ${MAGENAME}
599 #echo $?
600 #read
601 case $? in
602 0)
603 #MAGENAME=${RESULT}
604 #mage_uninstall
605 mage_uninstall ${RESULT}
606 ;;
607 1)
608 echo "No package found named '${RESULT}'."
609 exit 1
610 ;;
611 2)
612 echo -e ${COLRED}"Warning: More than one package found ..."${COLDEFAULT}
613 echo
614 echo "Please select the package you want to uninstall:"
615 echo
616 declare -i i=0
617 declare -i USERSEL=0
618 for x in ${RESULT}
619 do
620 echo -e "\t${COLBLUE}[${i}] ${COLGREEN}$(basename ${x})${COLDEFAULT}"
621 SELECTION[${i}]=${x}
622 i=${i}+1
623 done
624 echo
625 echo -n "Choose a number: "
626 read USERSEL
627
628 if [ ${USERSEL} -ge 0 -a ${USERSEL} -le ${i} ]
629 then
630 #the correct magefile
631 #MAGENAME="${SELECTION[${USERSEL}]}/$(basename ${SELECTION[${USERSEL}]}).mage"
632 MAGENAME="${SELECTION[${USERSEL}]}"
633 mage_uninstall ${MAGENAME}
634 else
635 echo "Wrong input. Uninstall abortet ..."
636 exit 1
637 fi
638 #echo
639 #echo "Uninstallation Aborted."
640 #exit 1
641 ;;
642 esac
643 ;;
644
645 search)
646 ${MLIBDIR}/pkgsearch.sh ${MAGENAME}
647 ;;
648
649 unpack)
650 build_unpackpkg
651 ;;
652
653 update)
654 syncmage
655 ;;
656 clean)
657 cleanpkg
658 ;;
659 keepfiles)
660 keepfiles "$2" "$3"
661 ;;
662 inject)
663 injectpkg "$2"
664 ;;
665 reminjected)
666 reminjected
667 ;;
668 version)
669 showversion
670 ;;
671 regen-mage-tree)
672 if [ -z "${SMAGESCRIPTSDIR}" ] || [ ! -d "${SMAGESCRIPTSDIR}" ]
673 then
674 echo "SMAGESCRIPTSDIR not found. Check your mage.rc or check out smage repos."
675 exit 1
676 fi
677 for i in $(find ${SMAGESCRIPTSDIR} -type f -name "*.smage2")
678 do
679 smage2 only-regen-tree "${i}"
680 done
681 ;;
682 *)
683 print_usage
684 ;;
685 esac

Properties

Name Value
svn:executable *