Magellan Linux

Diff of /trunk/mage/usr/lib/mage/mage4.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 226 by niro, Fri Sep 9 16:35:46 2005 UTC revision 1780 by niro, Mon Mar 12 23:21:12 2012 UTC
# Line 1  Line 1 
1  #!/bin/sh  #!/bin/bash
2  # Magellan Linux Installer (mage.sh)  # Magellan Linux Installer (mage.sh)
3  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.sh,v 1.1 2005-09-09 16:35:41 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.sh,v 1.17 2008-06-16 09:29:57 niro Exp $
4    
5  # default die function  # default die function
6  die()  die()
7  {  {
8     echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT}
9   echo -e ${COLRED}"$@"${COLDEFAULT}   echo -e ${COLRED}"$@"${COLDEFAULT}
10   exit 1   exit 1
11  }  }
12    
13  # include all needed files  # include all needed files
14  # [ -f ${MLIBDIR}/conf/mage.rc.global ] &&  \  [ -f /etc/mage.rc.global ] &&  \
15  # source ${MLIBDIR}/conf/mage.rc.global || \   source /etc/mage.rc.global || \
16  # die "${MLIBDIR}/conf/mage.rc.global missing"   die "/etc/mage.rc.global missing"
17  #  
18  # [ -f /etc/mage.rc ] && source /etc/mage.rc || \  [ -f ${MAGERC} ] && source ${MAGERC} || \
19  # die "Your /etc/mage.rc is missing. Aborting."   die "Your ${MAGERC} is missing. Aborting."
20  #  
21  # [ -f ${MLIBDIR}/mage.functions.sh ] && \  [ -f ${MLIBDIR}/mage4.functions.sh ] && \
22  # source ${MLIBDIR}/mage.functions.sh || \   source ${MLIBDIR}/mage4.functions.sh || \
23  # die "mage functions missing"   die "mage functions missing"
   
 # for tests only  
 source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage.rc.global  
 source /etc/mage.rc  
 source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh  
 MLIBDIR=/home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage  
   
 ## only for tests -> normally in /etc/rc.d/init.d/functions  
 COLRED="\033[1;6m\033[31m"  
 COLGREEN="\033[1;6m\033[32m"  
 COLBLUE="\033[1;6m\033[34m"  
 COLDEFAULT="\033[0m"  
   
 if [[ ${NOCOLORS} = true ]]  
 then  
  COLRED=""  
  COLGREEN=""  
  COLYELLOW=""  
  COLBLUE=""  
  COLMAGENTA=""  
  COLWHITE=""  
  COLDEFAULT=""  
 fi  
24    
25  # export default path  # export default path
26  export PATH="${PATH}:${MLIBDIR}"  export PATH="${PATH}:${MLIBDIR}"
# Line 53  export LC_ALL=C Line 31  export LC_ALL=C
31  # sanity checks  # sanity checks
32  [ ! -e ${VIRTUALDB_FILE} ] && touch ${VIRTUALDB_FILE}  [ ! -e ${VIRTUALDB_FILE} ] && touch ${VIRTUALDB_FILE}
33    
34  if [ ! -e ${VIRTUALDB_DEFAULTS} ] && [[ $1 != update ]]  if [ ! -e ${VIRTUALDB_DEFAULTS} ] && [[ $1 != update ]] && [[ $1 != update-tarball ]]
35  then  then
36   echo   echo
37   echo "Please choose an profile from the mage tree."   echo "Please choose an profile from the mage tree."
# Line 62  then Line 40  then
40  fi  fi
41    
42  # default messages  # default messages
43  showversion() {  showversion()
44    {
45   local MAGEVERSION="$(< ${MLIBDIR}/version)"   local MAGEVERSION="$(< ${MLIBDIR}/version)"
46    
47   echo -en "Magellan Package Manager v${MAGEVERSION} "   echo -en "Magellan Package Manager v${MAGEVERSION} "
48   echo -e  "-- Niels Rogalla (niro@magellan-linux.de)"   echo -e  "-- Niels Rogalla (niro@magellan-linux.de)"
49  }  }
50    
51  print_usage(){  print_usage()
52   showversion  {
53   echo   #showversion
54     #echo
55   echo "Usage: $(basename $0) [option] pkgname ..."   echo "Usage: $(basename $0) [option] pkgname ..."
56   echo "Options:"   echo "Options:"
57   echo "     pretend        - pretends dependencies of a package"   echo "    pretend         - pretends dependencies of a package"
58   echo "     srcpretend     - pretends dependencies of a package (build from source)"   echo "    srcpretend      - pretends dependencies of a package (build from source)"
59   echo "     install        - installs a package"   echo "    install         - installs a package"
60   echo "     srcinstall     - installs a package from source"   echo "    srcinstall      - installs a package from source"
61   echo "     uninstall      - removes a package"   echo "    uninstall       - removes a package"
62   echo "     update         - updates mage-tree"   echo "    update          - updates the mage-tree via rsync"
63   echo "     search         - searches mage-tree for a package"   echo "    update-tarball  - updates the mage-tree via a tarball"
64   echo "     clean          - removes *all* downloaded packages"   echo "    uppretend       - pretend dependencies for a system upgrade"
65  # echo "     unpack         - unpacks a package"   echo "    upgrade         - runs a complete system upgrade"
66   echo "     download       - downloads a package"   echo "    srcuppretend    - pretend dependencies for a system upgrade from source"
67   echo "     version        - prints version info"   echo "    srcupgrade      - runs a complete system upgrade from source"
68     echo "    search          - searches mage-tree for a package"
69     echo "    clean           - removes *all* downloaded packages"
70     echo "    unpack          - unpacks *all* needed package for 'foo'"
71     echo "    download        - downloads *all* needed packages for 'foo'"
72     echo "    print-features  - prints all enabled mage-features"
73     echo "    version         - prints version info"
74     echo "    regen-mage-tree - regenerates the whole mage database (for devs only)"
75   echo   echo
76   echo "Other options:"   echo "Other options:"
77  # echo "NOINSTALL=yes $(basename $0) srcinstall PACKAGE"  # echo "NOINSTALL=yes $(basename $0) srcinstall PACKAGE"
78  # echo "Builds a Package with its dependencies, but won't install anything."  # echo "Builds a Package with its dependencies, but won't install anything."
79  # echo  # echo
80   echo "USE_UNSTABLE=true $(basename $0) [src]install PACKAGE"   echo "MAGE_DISTRIBUTION=unstable $(basename $0) [src]install PACKAGE"
81   echo "Overrides stable packages; you can install packages that are marked unstable."   echo "Overrides stable packages; you can install packages that are marked unstable."
82   echo   echo
83   echo "USE_TESTING=true $(basename $0) [src]install PACKAGE"   echo "MAGE_DISTRIBUTION=testing $(basename $0) [src]install PACKAGE"
84   echo "Overrides stable packages; you can install packages that are marked testing."   echo "Overrides stable packages; you can install packages that are marked testing."
85   echo   echo
86   echo "NOCOLORS=true $(basename $0) [src]install PACKAGE"   echo "NOCOLORS=true $(basename $0) [src]install PACKAGE"
# Line 105  print_usage(){ Line 92  print_usage(){
92  showversion  showversion
93  echo  echo
94    
 # before anything run mage_setup  
 mage_setup || die "error in mage_setup()"  
   
95  # install method  # install method
96  METHOD="$1"  METHOD="$1"
97    
98  # initial unversionized packagename, gets overridden later  # initial unversionized packagename, gets overridden later on
99  MAGENAME="$2"  MAGENAME="$2"
100    
101  [[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1  if [[ ${METHOD} != upgrade ]] &&
102     [[ ${METHOD} != srcupgrade ]] &&
103     [[ ${METHOD} != uppretend ]] &&
104     [[ ${METHOD} != srcuppretend ]] &&
105     [[ ${METHOD} != update ]] &&
106     [[ ${METHOD} != update-tarball ]] &&
107     [[ ${METHOD} != clean ]] &&
108     [[ ${METHOD} != version ]] &&
109     [[ ${METHOD} != search ]] &&
110     [[ ${METHOD} != regen-mage-tree ]] &&
111     [[ ${METHOD} != print-features ]]
112    then
113     [[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1
114    fi
115    
116    # set PKGDIR and BUILDDIR to MROOT
117    if [[ -n ${MROOT} ]]
118    then
119     PKGDIR=${MROOT}/${PKGDIR}
120     BUILDDIR=${MROOT}/${BUILDDIR}
121    fi
122    
123    # before anything run mage_setup
124    mage_setup || die "error in mage_setup()"
125    
126    # load supported mage features
127    load_mage_features
128    
129  case ${METHOD} in  case ${METHOD} in
130   download)   download)
# Line 126  case ${METHOD} in Line 135  case ${METHOD} in
135   [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."   [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
136    
137   # source the highest magefile of this pkg   # source the highest magefile of this pkg
138   source $(get_highest_magefile ${PCAT} ${MAGENAME})   PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
139    
140     # package is masked
141     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
142    
143   # convert PKGNAME to PNAME/PVER/PBUILD   # convert PKGNAME to PNAME/PVER/PBUILD
144   # we're working *only* with these three vars from here on   # we're working *only* with these three vars from here on
# Line 142  case ${METHOD} in Line 154  case ${METHOD} in
154   --pver ${PVER} \   --pver ${PVER} \
155   --pbuild ${PBUILD})"   --pbuild ${PBUILD})"
156   fetch_packages ${ALLDEPS} || die "fetching packages"   fetch_packages ${ALLDEPS} || die "fetching packages"
157     md5sum_packages ${ALLDEPS} || die "md5 sum packages"
158   ;;   ;;
159    
160   srcdownload)   srcdownload)
# Line 152  case ${METHOD} in Line 165  case ${METHOD} in
165   [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."   [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
166    
167   # source the highest magefile of this pkg   # source the highest magefile of this pkg
168   source $(get_highest_magefile ${PCAT} ${MAGENAME})   PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
169    
170     # package is masked
171     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
172    
173   # convert PKGNAME to PNAME/PVER/PBUILD   # convert PKGNAME to PNAME/PVER/PBUILD
174   # we're working *only* with these three vars from here on   # we're working *only* with these three vars from here on
# Line 178  case ${METHOD} in Line 194  case ${METHOD} in
194   [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."   [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
195    
196   # source the highest magefile of this pkg   # source the highest magefile of this pkg
197   source $(get_highest_magefile ${PCAT} ${MAGENAME})   PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
198    
199     # package is masked
200     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
201    
202   # convert PKGNAME to PNAME/PVER/PBUILD   # convert PKGNAME to PNAME/PVER/PBUILD
203   # we're working *only* with these three vars from here on   # we're working *only* with these three vars from here on
# Line 204  case ${METHOD} in Line 223  case ${METHOD} in
223   ;;   ;;
224    
225   install)   install)
226     have_root_privileges || die "You must be root to run this operation."
227    
228   # first of all get the right pkg which going to be installed   # first of all get the right pkg which going to be installed
229   PCAT="$(pname2pcat ${MAGENAME})"   PCAT="$(pname2pcat ${MAGENAME})"
230    
# Line 211  case ${METHOD} in Line 232  case ${METHOD} in
232   [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."   [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
233    
234   # source the highest magefile of this pkg   # source the highest magefile of this pkg
235   source $(get_highest_magefile ${PCAT} ${MAGENAME})   PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
236    
237     # package is masked
238     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
239    
240   # convert PKGNAME to PNAME/PVER/PBUILD   # convert PKGNAME to PNAME/PVER/PBUILD
241   # we're working *only* with these three vars from here on   # we're working *only* with these three vars from here on
# Line 222  case ${METHOD} in Line 246  case ${METHOD} in
246   if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}   if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}
247   then   then
248   echo -en "Package "   echo -en "Package "
249   echo -en "${COLRED}${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"   echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
250   echo -e  " already installed."   echo -e  " already installed."
251   exit 3   exit 3
252   fi   fi
# Line 243  case ${METHOD} in Line 267  case ${METHOD} in
267   ;;   ;;
268    
269   srcinstall)   srcinstall)
270     have_root_privileges || die "You must be root to run this operation."
271    
272   # first of all get the right pkg which going to be installed   # first of all get the right pkg which going to be installed
273   PCAT="$(pname2pcat ${MAGENAME})"   PCAT="$(pname2pcat ${MAGENAME})"
274    
# Line 250  case ${METHOD} in Line 276  case ${METHOD} in
276   [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."   [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
277    
278   # source the highest magefile of this pkg   # source the highest magefile of this pkg
279   source $(get_highest_magefile ${PCAT} ${MAGENAME})   PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
280    
281     # package is masked
282     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
283    
284   # convert PKGNAME to PNAME/PVER/PBUILD   # convert PKGNAME to PNAME/PVER/PBUILD
285   # we're working *only* with these three vars from here on   # we're working *only* with these three vars from here on
# Line 261  case ${METHOD} in Line 290  case ${METHOD} in
290   if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}   if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}
291   then   then
292   echo -en "Package "   echo -en "Package "
293   echo -en "${COLRED}${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"   echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
294   echo -e  " already installed."   echo -e  " already installed."
295   exit 3   exit 3
296   fi   fi
# Line 278  case ${METHOD} in Line 307  case ${METHOD} in
307   ;;   ;;
308    
309   uninstall)   uninstall)
310   ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})"   have_root_privileges || die "You must be root to run this operation."
311   if [ -z "${ALLDEPS}" ]  
312   then   ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})"
313   die "No package installed named '${MAGENAME}'."   if [ -z "${ALLDEPS}" ]
314   fi   then
315   uninstall_packages ${ALLDEPS}   die "No package installed named '${MAGENAME}'."
316     fi
317     uninstall_packages ${ALLDEPS}
318     ;;
319    
320     uppretend|srcuppretend)
321     ${MLIBDIR}/depwalker.sh \
322     --method ${METHOD} \
323     --pcat ${METHOD} \
324     --pname ${METHOD} \
325     --pver ${METHOD} \
326     --pbuild ${METHOD}
327     ;;
328    
329     upgrade)
330     have_root_privileges || die "You must be root to run this operation."
331    
332     # get all dependencies of *all* installed packages
333     # fake pcat,pname,pver,pbuild ...
334     ALLDEPS="$(${MLIBDIR}/depwalker.sh \
335     --method ${METHOD} \
336     --pcat ${METHOD} \
337     --pname ${METHOD} \
338     --pver ${METHOD} \
339     --pbuild ${METHOD})"
340    
341     # first fetch all packages
342     fetch_packages ${ALLDEPS} || die "fetching packages"
343     md5sum_packages ${ALLDEPS} || die "md5 sum packages"
344     unpack_packages ${ALLDEPS} || die "unpacking packages"
345     install_packages ${ALLDEPS} || die "installing packages"
346     ;;
347    
348     srcupgrade)
349     have_root_privileges || die "You must be root to run this operation."
350    
351     # get all dependencies of *all* installed packages
352     # fake pcat,pname,pver,pbuild ...
353     ALLDEPS="$(${MLIBDIR}/depwalker.sh \
354     --method ${METHOD} \
355     --pcat ${METHOD} \
356     --pname ${METHOD} \
357     --pver ${METHOD} \
358     --pbuild ${METHOD})"
359    
360     install_packages --src-install ${ALLDEPS} || die "src-installing packages"
361   ;;   ;;
362    
363   search)   search)
364   ${MLIBDIR}/pkgsearch.sh ${MAGENAME}   pkgsearch "${MAGENAME}"
365   ;;   ;;
366    
367  # unpack)   unpack)
368  # build_unpackpkg   have_root_privileges || die "You must be root to run this operation."
369  # ;;  
370     # first of all get the right pkg which going to be installed
371     PCAT="$(pname2pcat ${MAGENAME})"
372    
373     # package does not exists
374     [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
375    
376     # source the highest magefile of this pkg
377     PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
378    
379     # package is masked
380     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
381    
382     # convert PKGNAME to PNAME/PVER/PBUILD
383     # we're working *only* with these three vars from here on
384     PNAME="$(pkgname2pname ${PKGNAME})"
385     PVER="$(pkgname2pver ${PKGNAME})"
386     PBUILD="$(pkgname2pbuild ${PKGNAME})"
387    
388     # get all dependencies of this package
389     ALLDEPS="$(${MLIBDIR}/depwalker.sh \
390     --method install \
391     --pcat ${PCAT} \
392     --pname ${PNAME} \
393     --pver ${PVER} \
394     --pbuild ${PBUILD})"
395     fetch_packages ${ALLDEPS} || die "fetching packages"
396     md5sum_packages ${ALLDEPS} || die "md5 sum packages"
397     unpack_packages ${ALLDEPS} || die "unpacking packages"
398     ;;
399    
400   update)   update)
401     have_root_privileges || die "You must be root to run this operation."
402   syncmage   syncmage
403   ;;   ;;
404    
405     update-tarball)
406     have_root_privileges || die "You must be root to run this operation."
407     syncmage_tarball
408     ;;
409    
410   clean)   clean)
411     have_root_privileges || die "You must be root to run this operation."
412   cleanpkg   cleanpkg
413   ;;   ;;
414    
415   version)   version)
416   showversion   # showversion
417     exit 0
418   ;;   ;;
419    
420   regen-mage-tree)   regen-mage-tree)
421     have_root_privileges || die "You must be root to run this operation."
422    
423   if [ -z "${SMAGESCRIPTSDIR}" ] || [ ! -d "${SMAGESCRIPTSDIR}" ]   if [ -z "${SMAGESCRIPTSDIR}" ] || [ ! -d "${SMAGESCRIPTSDIR}" ]
424   then   then
425   echo "SMAGESCRIPTSDIR not found. Check your mage.rc or check out smage repos."   echo "SMAGESCRIPTSDIR not found. Check your mage.rc or check out smage repos."
# Line 318  case ${METHOD} in Line 431  case ${METHOD} in
431   done   done
432   ;;   ;;
433    
434     print-features)
435     mprintfeatures
436     ;;
437    
438   *)   *)
439   print_usage   print_usage
440   ;;   ;;

Legend:
Removed from v.226  
changed lines
  Added in v.1780