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