Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 60 - (hide annotations) (download) (as text)
Tue Feb 15 22:59:14 2005 UTC (19 years, 3 months ago) by niro
File MIME type: application/x-sh
File size: 14379 byte(s)
rev bump to 0.3.6-r13

1 niro 24 #!/bin/sh
2     # Magellan Linux Installer (mage.sh)
3 niro 60 # version: 0.3.6-r13
4 niro 24
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 niro 60 MAGEVERSION=0.3.6-r13
15 niro 24
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 niro 44 # default path
23     PATH="${PATH}:${MLIBDIR}"
24 niro 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 niro 30 local my_cat
175     local directory
176     local x
177    
178 niro 24 #cut arch
179     my_pkg=${PKGNAME/-${ARCH}/}
180 niro 30
181 niro 24 #cut version & build
182     my_pkg=${my_pkg%-*-*}
183 niro 30 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 niro 24 #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 niro 36 get_highest_magefile || exit 1
456 niro 24 source ${MAGEFILE}
457     getpackages
458     ;;
459    
460     pretend)
461     choppkgname
462     getcategorie
463 niro 36 get_highest_magefile || exit 1
464 niro 24 ${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 niro 36 get_highest_magefile || exit 1
478 niro 24 ${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 niro 36 get_highest_magefile || exit 1
494 niro 24 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 niro 56 #then source an evtl new generated profile
519     [ -e /etc/profile ] && source /etc/profile
520    
521 niro 24 #than install
522     MY_CAT_FIX="$(dirname ${i})"
523     CATEGORIE="$(basename ${MY_CAT_FIX%/*})"
524     mage_install ${i}
525     done
526     run_etc_update
527     ;;
528    
529     srcinstall)
530     #counter for protected files
531     declare -i PROTECT_COUNT=0
532     choppkgname
533     getcategorie
534 niro 36 get_highest_magefile || exit 1
535 niro 24 ALLDEPS="$(/usr/lib/mage/depwanderer.sh srcinstall ${MAGEFILE})"
536     #abort already installed
537     if [ "$?" == "3" ]
538     then
539     echo -en "Package "
540     echo -en "${COLRED}$(basename ${MAGEFILE} .mage)${COLDEFAULT}"
541     echo -e " already installed."
542     echo -e "Installation aborted."
543     exit 0
544     fi
545     for i in ${ALLDEPS}
546     do
547     #first unset all vars to be safe
548     unset PKGNAME
549     unset STATE
550     unset DESCRIPTION
551     unset HOMEPAGE
552     unset DEPEND
553     unset SDEPEND
554     unset PROVIDE
555     unset PKGTYPE
556     unset preinstall
557     unset postinstall
558    
559 niro 56 #then source an evtl new generated profile
560     [ -e /etc/profile ] && source /etc/profile
561    
562 niro 24 #than srcinstall
563     MY_CAT_FIX="$(dirname ${i})"
564     CATEGORIE="$(basename ${MY_CAT_FIX%/*})"
565     #builds the package from source
566     ${MLIBDIR}/sourceinstall.sh ${i} || exit 1
567     done
568     run_etc_update
569     ;;
570    
571     uninstall)
572     RESULT=$(get_magefile_to_uninstall ${MAGENAME})
573     #get_magefile_to_uninstall ${MAGENAME}
574     #echo $?
575     #read
576     case $? in
577     0)
578     #MAGENAME=${RESULT}
579     #mage_uninstall
580     mage_uninstall ${RESULT}
581     ;;
582     1)
583     echo "No package found named '${RESULT}'."
584     exit 1
585     ;;
586     2)
587     echo -e ${COLRED}"Warning: More than one package found ..."${COLDEFAULT}
588     echo
589     echo "Please select the package you want to uninstall:"
590     echo
591     declare -i i=0
592     declare -i USERSEL=0
593     for x in ${RESULT}
594     do
595     echo -e "\t${COLBLUE}[${i}] ${COLGREEN}$(basename ${x})${COLDEFAULT}"
596     SELECTION[${i}]=${x}
597     i=${i}+1
598     done
599     echo
600     echo -n "Choose a number: "
601     read USERSEL
602    
603     if [ ${USERSEL} -ge 0 -a ${USERSEL} -le ${i} ]
604     then
605     #the correct magefile
606     #MAGENAME="${SELECTION[${USERSEL}]}/$(basename ${SELECTION[${USERSEL}]}).mage"
607     MAGENAME="${SELECTION[${USERSEL}]}"
608     mage_uninstall ${MAGENAME}
609     else
610     echo "Wrong input. Uninstall abortet ..."
611     exit 1
612     fi
613     #echo
614     #echo "Uninstallation Aborted."
615     #exit 1
616     ;;
617     esac
618     ;;
619    
620     search)
621     ${MLIBDIR}/pkgsearch.sh ${MAGENAME}
622     ;;
623    
624     unpack)
625     build_unpackpkg
626     ;;
627    
628     update)
629     syncmage
630     ;;
631     clean)
632     cleanpkg
633     ;;
634     keepfiles)
635     keepfiles "$2" "$3"
636     ;;
637     inject)
638     injectpkg "$2"
639     ;;
640     reminjected)
641     reminjected
642     ;;
643     version)
644     showversion
645     ;;
646     *)
647     print_usage
648     ;;
649     esac

Properties

Name Value
svn:executable *