Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 44 - (show annotations) (download) (as text)
Mon Jan 10 01:59:30 2005 UTC (19 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 14193 byte(s)
updated path variable and now sourcing /etc/profile everytime

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

Properties

Name Value
svn:executable *