Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 167 - (show annotations) (download) (as text)
Fri Jul 29 14:28:43 2005 UTC (18 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 14708 byte(s)
updated mage version

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

Properties

Name Value
svn:executable *