Contents of /trunk/mage/usr/lib/mage/mage3.sh
Parent Directory | Revision Log
Revision 24 -
(show annotations)
(download)
(as text)
Wed Jan 5 05:08:01 2005 UTC (19 years, 5 months ago) by niro
File MIME type: application/x-sh
File size: 13527 byte(s)
Wed Jan 5 05:08:01 2005 UTC (19 years, 5 months ago) by niro
File MIME type: application/x-sh
File size: 13527 byte(s)
mage-0.3.6-r8 import
1 | #!/bin/sh |
2 | # Magellan Linux Installer (mage.sh) |
3 | # version: 0.3.6-r8 |
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-r8 |
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 | #cut arch |
173 | my_pkg=${PKGNAME/-${ARCH}/} |
174 | #cut version & build |
175 | my_pkg=${my_pkg%-*-*} |
176 | |
177 | #virtuals_del ${PROVIDE} ${CATEGORIE}/${my_pkg} |
178 | |
179 | #my_pkg has already the categorie -> ex my_pkg=x11-base/xfree |
180 | virtuals_del ${PROVIDE} ${my_pkg} |
181 | |
182 | unset PROVIDE |
183 | fi |
184 | } |
185 | |
186 | mage_install_sources() { |
187 | |
188 | #creates fake db entry |
189 | install_database_entry ${PKGNAME} ${PKGTYPE} |
190 | |
191 | #check for virtuals and PROVIDE |
192 | # if so install it to virtualdb |
193 | register_virtual_pkg |
194 | |
195 | echo |
196 | echo -e "This Package is a Source Package." |
197 | echo |
198 | echo -e "Only 'srcinstall' works with this type of packages" |
199 | echo -en "If you have done a srcinstall before, " |
200 | echo -e "you will find the files in /usr/src." |
201 | echo |
202 | |
203 | #nice timer (4 seconds) |
204 | # local x |
205 | # declare -i x=4 |
206 | # echo -en "Continues in 4s ..." |
207 | # while [ ${x} -gt 0 ] |
208 | # do |
209 | # i=${x}+1 |
210 | # echo -en "\b\b\b\b\b\b${x}s ..." |
211 | # #beeper |
212 | # echo -en "\a" |
213 | # sleep 1 |
214 | # done |
215 | # echo |
216 | |
217 | sleep 1 |
218 | xtitleclean |
219 | } |
220 | |
221 | mage_install() { |
222 | local MAGEFILE |
223 | local PKGTARBALL |
224 | |
225 | MAGEFILE=$1 |
226 | |
227 | source ${MAGEFILE} |
228 | |
229 | #abbruch wenn schon installiert |
230 | if [ -e ${INSTALLDB}/${PKGNAME/-${ARCH}/} ] |
231 | then |
232 | echo -en "\n${COLRED}Package '${PKGNAME/-${ARCH}/}'" \ |
233 | echo -e "already installed. Installation Aborted.${COLDEFAULT}\n" |
234 | exit 3 |
235 | fi |
236 | |
237 | xtitle "[ Installing ${PKGNAME/-${ARCH}/} ]" |
238 | |
239 | if [ "${PKGTYPE}" == "virtual" ] |
240 | then |
241 | mage_install_virtual |
242 | return 0 |
243 | fi |
244 | |
245 | if [ "${PKGTYPE}" == "sources" ] |
246 | then |
247 | mage_install_sources |
248 | return 0 |
249 | fi |
250 | |
251 | if [ ! -e ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} ] |
252 | then |
253 | echo -en "\nPrefetching needed Packages for " |
254 | echo -e "${COLGREEN}${PKGNAME/-${ARCH}/}${COLDEFAULT}...\n" |
255 | getpackages |
256 | fi |
257 | |
258 | echo -e "\nInstallation of Package: ${COLGREEN}${PKGNAME/-${ARCH}/}${COLDEFAULT}\n" |
259 | #( build_unpackpkg ) | echo -e "Unpacking Package ...\n" |
260 | |
261 | echo -en "Unpacking Package ..." |
262 | build_unpackpkg |
263 | echo "done" |
264 | |
265 | ##preinstall scripte |
266 | export -f preinstall 2> /dev/null |
267 | if [ "$?" == "0" ] |
268 | then |
269 | echo -e "\nRunning Preinstall ... \n" |
270 | preinstall |
271 | unset preinstall |
272 | fi |
273 | |
274 | #install of package |
275 | if [ "$VERBOSE" == "off" ] |
276 | then |
277 | #spinner disabled |
278 | #touch /var/tmp/proz |
279 | #build_doinstall|spin_processbar |
280 | |
281 | echo -en "Processing ... " |
282 | build_doinstall ${PKGNAME} |
283 | echo "done" |
284 | fi |
285 | |
286 | if [ "$VERBOSE" == "on" ] |
287 | then |
288 | #build_doinstall |
289 | build_doinstall ${PKGNAME} |
290 | fi |
291 | |
292 | #postinstall scripte |
293 | export -f postinstall 2> /dev/null |
294 | if [ "$?" == "0" ] |
295 | then |
296 | echo -e "\nRunning Postinstall ... \n" |
297 | postinstall |
298 | unset postinstall |
299 | fi |
300 | |
301 | #install database entry |
302 | install_database_entry ${PKGNAME} |
303 | |
304 | #cleanup |
305 | if [ -d ${BUILDDIR}/${PKGNAME} ] |
306 | then |
307 | rm -rf ${BUILDDIR}/${PKGNAME} |
308 | fi |
309 | |
310 | |
311 | #check for virtuals and PROVIDE |
312 | # if so install it to virtualdb |
313 | register_virtual_pkg |
314 | |
315 | |
316 | #update mtimes of packages and db_entries |
317 | update_mtime |
318 | |
319 | #rebuilds toplevel info node |
320 | echo -en "\n>>>> Rebuilding top-level info node ... " |
321 | ${MLIBDIR}/mkinfodir /usr/share/info > /usr/share/info/dir \ |
322 | && echo "done" || echo "false" |
323 | |
324 | #rebuilds the enviroment with the content of /etc/env.d |
325 | ${MLIBDIR}/env-rebuild.sh |
326 | |
327 | xtitleclean |
328 | |
329 | echo -e "\nPackage '${PKGNAME/-${ARCH}/}' sucessfully installed.\n" |
330 | } |
331 | |
332 | mage_uninstall() { |
333 | # #installdbhome #packagedir #magefile |
334 | #source ${INSTALLDB}/$(basename ${MAGENAME} .mage)/$(basename ${MAGENAME}) |
335 | #source ${INSTALLDB}/${CATEGORIE}/$(basename ${MAGENAME} .mage)/$(basename ${MAGENAME}) |
336 | |
337 | local UNINST_MAGEFILE CAT_PKGNAME |
338 | |
339 | CAT_PKGNAME=$1 |
340 | |
341 | #trim pkgname from CAT_PKGNAME to get magefile name |
342 | UNINST_MAGEFILE="$(echo ${CAT_PKGNAME}| cut -d / -f2).mage" |
343 | |
344 | #then source it |
345 | source ${INSTALLDB}/${CAT_PKGNAME}/${UNINST_MAGEFILE} |
346 | |
347 | #fix for mage-0.3.6-r5 |
348 | #PKGNAME=${PKGNAME/-${ARCH}/} |
349 | PKGNAME=${CAT_PKGNAME} |
350 | |
351 | #if [ ! -e ${INSTALLDB}/${PKGNAME/-${ARCH}/} ] |
352 | if [ ! -e ${INSTALLDB}/${CAT_PKGNAME} ] |
353 | then |
354 | echo -e "\nPackage '${PKGNAME}' is not installed. Uninstallation Aborted.\n" |
355 | exit 3 |
356 | fi |
357 | |
358 | echo -e "\nUninstall of Package:\t${COLRED}${PKGNAME}${COLDEFAULT}\n" |
359 | |
360 | if [ -z "${MAGE_UNINSTALL_TIMEOUT}" ] |
361 | then |
362 | MAGE_UNINSTALL_TIMEOUT=5 |
363 | fi |
364 | |
365 | for ((i=0; i < MAGE_UNINSTALL_TIMEOUT; i++)) |
366 | do |
367 | timeout=$(expr ${MAGE_UNINSTALL_TIMEOUT} - ${i}) |
368 | echo -e "Starting in ${COLRED} ${timeout}" \ |
369 | "${COLDEFAULT} seconds ... ( [CTRL+C] to abort )" |
370 | sleep 1 |
371 | #moves the cursor up |
372 | echo -en \\033[A |
373 | done |
374 | |
375 | #moves the cursor up |
376 | echo -en \\033[A |
377 | #min. 30 spaces needed for clearing up the rest of the line |
378 | echo -e "\nUninstall ${COLRED}started${COLDEFAULT} ..." \ |
379 | " \n" |
380 | sleep 1 |
381 | |
382 | |
383 | ##preremove scripte |
384 | export -f preremove 2> /dev/null |
385 | if [ "$?" == "0" ] |
386 | then |
387 | echo -e "\nRunning Preremove ... \n" |
388 | preremove |
389 | unset preremove |
390 | fi |
391 | |
392 | #runs uninstall |
393 | build_douninstall ${PKGNAME} |
394 | |
395 | #postremove scripte |
396 | export -f postremove 2> /dev/null |
397 | if [ "$?" == "0" ] |
398 | then |
399 | echo -e "\nRunning Postremove ... \n" |
400 | postremove |
401 | unset postremove |
402 | fi |
403 | |
404 | #remove database entry |
405 | remove_database_entry ${PKGNAME} |
406 | |
407 | #check for PROVIDE |
408 | # if so uninstall it from virtualdb |
409 | unregister_virtual_pkg |
410 | |
411 | #rebuilds toplevel info node |
412 | echo -en "\n>>>> Rebuilding top-level info node ... " |
413 | ${MLIBDIR}/mkinfodir /usr/share/info > /usr/share/info/dir \ |
414 | && echo "done" || echo "false" |
415 | |
416 | #rebuilds the enviroment with the content of /etc/env.d |
417 | ${MLIBDIR}/env-rebuild.sh |
418 | |
419 | echo -e "\nPackage '${PKGNAME}' sucessfully removed.\n" |
420 | } |
421 | |
422 | |
423 | case "$1" in |
424 | download) |
425 | choppkgname |
426 | getcategorie |
427 | get_highest_magefile |
428 | source ${MAGEFILE} |
429 | getpackages |
430 | ;; |
431 | |
432 | pretend) |
433 | choppkgname |
434 | getcategorie |
435 | get_highest_magefile |
436 | ${MLIBDIR}/depwanderer.sh pretend ${MAGEFILE} |
437 | #abort already installed |
438 | if [ "$?" == "3" ] |
439 | then |
440 | echo -en "Package " |
441 | echo -en "${COLRED}$(basename ${MAGEFILE} .mage)${COLDEFAULT}" |
442 | echo -e " already installed." |
443 | fi |
444 | ;; |
445 | |
446 | srcpretend) |
447 | choppkgname |
448 | getcategorie |
449 | get_highest_magefile |
450 | ${MLIBDIR}/depwanderer.sh srcpretend ${MAGEFILE} |
451 | #abort already installed |
452 | if [ "$?" == "3" ] |
453 | then |
454 | echo -en "Package " |
455 | echo -en "${COLRED}$(basename ${MAGEFILE} .mage)${COLDEFAULT}" |
456 | echo -e " already installed." |
457 | fi |
458 | ;; |
459 | |
460 | install) |
461 | #counter for protected files |
462 | declare -i PROTECT_COUNT=0 |
463 | choppkgname |
464 | getcategorie |
465 | get_highest_magefile |
466 | ALLDEPS="$(/usr/lib/mage/depwanderer.sh install ${MAGEFILE})" |
467 | #abort already installed |
468 | if [ "$?" == "3" ] |
469 | then |
470 | echo -en "Package " |
471 | echo -en "${COLRED}$(basename ${MAGEFILE} .mage)${COLDEFAULT}" |
472 | echo -e " already installed." |
473 | echo -e "Installation aborted." |
474 | exit 0 |
475 | fi |
476 | for i in ${ALLDEPS} |
477 | do |
478 | #first unset all vars to be safe |
479 | unset PKGNAME |
480 | unset STATE |
481 | unset DESCRIPTION |
482 | unset HOMEPAGE |
483 | unset DEPEND |
484 | unset SDEPEND |
485 | unset PROVIDE |
486 | unset PKGTYPE |
487 | unset preinstall |
488 | unset postinstall |
489 | |
490 | #than install |
491 | MY_CAT_FIX="$(dirname ${i})" |
492 | CATEGORIE="$(basename ${MY_CAT_FIX%/*})" |
493 | mage_install ${i} |
494 | done |
495 | run_etc_update |
496 | ;; |
497 | |
498 | srcinstall) |
499 | #counter for protected files |
500 | declare -i PROTECT_COUNT=0 |
501 | choppkgname |
502 | getcategorie |
503 | get_highest_magefile |
504 | ALLDEPS="$(/usr/lib/mage/depwanderer.sh srcinstall ${MAGEFILE})" |
505 | #abort already installed |
506 | if [ "$?" == "3" ] |
507 | then |
508 | echo -en "Package " |
509 | echo -en "${COLRED}$(basename ${MAGEFILE} .mage)${COLDEFAULT}" |
510 | echo -e " already installed." |
511 | echo -e "Installation aborted." |
512 | exit 0 |
513 | fi |
514 | for i in ${ALLDEPS} |
515 | do |
516 | #first unset all vars to be safe |
517 | unset PKGNAME |
518 | unset STATE |
519 | unset DESCRIPTION |
520 | unset HOMEPAGE |
521 | unset DEPEND |
522 | unset SDEPEND |
523 | unset PROVIDE |
524 | unset PKGTYPE |
525 | unset preinstall |
526 | unset postinstall |
527 | |
528 | #than srcinstall |
529 | MY_CAT_FIX="$(dirname ${i})" |
530 | CATEGORIE="$(basename ${MY_CAT_FIX%/*})" |
531 | #builds the package from source |
532 | ${MLIBDIR}/sourceinstall.sh ${i} || exit 1 |
533 | done |
534 | run_etc_update |
535 | ;; |
536 | |
537 | uninstall) |
538 | RESULT=$(get_magefile_to_uninstall ${MAGENAME}) |
539 | #get_magefile_to_uninstall ${MAGENAME} |
540 | #echo $? |
541 | #read |
542 | case $? in |
543 | 0) |
544 | #MAGENAME=${RESULT} |
545 | #mage_uninstall |
546 | mage_uninstall ${RESULT} |
547 | ;; |
548 | 1) |
549 | echo "No package found named '${RESULT}'." |
550 | exit 1 |
551 | ;; |
552 | 2) |
553 | echo -e ${COLRED}"Warning: More than one package found ..."${COLDEFAULT} |
554 | echo |
555 | echo "Please select the package you want to uninstall:" |
556 | echo |
557 | declare -i i=0 |
558 | declare -i USERSEL=0 |
559 | for x in ${RESULT} |
560 | do |
561 | echo -e "\t${COLBLUE}[${i}] ${COLGREEN}$(basename ${x})${COLDEFAULT}" |
562 | SELECTION[${i}]=${x} |
563 | i=${i}+1 |
564 | done |
565 | echo |
566 | echo -n "Choose a number: " |
567 | read USERSEL |
568 | |
569 | if [ ${USERSEL} -ge 0 -a ${USERSEL} -le ${i} ] |
570 | then |
571 | #the correct magefile |
572 | #MAGENAME="${SELECTION[${USERSEL}]}/$(basename ${SELECTION[${USERSEL}]}).mage" |
573 | MAGENAME="${SELECTION[${USERSEL}]}" |
574 | mage_uninstall ${MAGENAME} |
575 | else |
576 | echo "Wrong input. Uninstall abortet ..." |
577 | exit 1 |
578 | fi |
579 | #echo |
580 | #echo "Uninstallation Aborted." |
581 | #exit 1 |
582 | ;; |
583 | esac |
584 | ;; |
585 | |
586 | search) |
587 | ${MLIBDIR}/pkgsearch.sh ${MAGENAME} |
588 | ;; |
589 | |
590 | unpack) |
591 | build_unpackpkg |
592 | ;; |
593 | |
594 | update) |
595 | syncmage |
596 | ;; |
597 | clean) |
598 | cleanpkg |
599 | ;; |
600 | keepfiles) |
601 | keepfiles "$2" "$3" |
602 | ;; |
603 | inject) |
604 | injectpkg "$2" |
605 | ;; |
606 | reminjected) |
607 | reminjected |
608 | ;; |
609 | version) |
610 | showversion |
611 | ;; |
612 | *) |
613 | print_usage |
614 | ;; |
615 | esac |
Properties
Name | Value |
---|---|
svn:executable | * |