Magellan Linux

Diff of /branches/mage-next/src/mage.in

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

trunk/mage/usr/lib/mage/mage4.sh revision 1269 by niro, Tue Apr 26 08:57:30 2011 UTC branches/mage-next/src/mage.in revision 2617 by niro, Tue Mar 4 15:31:43 2014 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/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.17 2008-06-16 09:29:57 niro Exp $  # $Id$
   
 # default die function  
 die()  
 {  
  echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT}  
  echo -e ${COLRED}"$@"${COLDEFAULT}  
  exit 1  
 }  
4    
5  # include all needed files  # include all needed files
6  [ -f /etc/mage.rc.global ] &&  \  [ -f /etc/mage.rc.global ] &&  \
# Line 22  die() Line 14  die()
14   source ${MLIBDIR}/mage4.functions.sh || \   source ${MLIBDIR}/mage4.functions.sh || \
15   die "mage functions missing"   die "mage functions missing"
16    
 ## only for tests -> normally in /etc/rc.d/init.d/functions  
 COLRED="\033[1;6m\033[31m"  
 COLGREEN="\033[1;6m\033[32m"  
 COLYELLOW="\033[1;6m\033[33m"  
 COLBLUE="\033[1;6m\033[34m"  
 COLMAGENTA="\033[1;6m\033[35m"  
 COLWHITE="\033[1;6m\033[37m"  
 COLGRAY="\033[0;6m\033[37m"  
 COLBOLD="\033[1m"  
 COLDEFAULT="\033[0m"  
   
 if [[ ${NOCOLORS} = true ]]  
 then  
  COLRED=""  
  COLGREEN=""  
  COLYELLOW=""  
  COLBLUE=""  
  COLMAGENTA=""  
  COLWHITE=""  
  COLGRAY=""  
  COLBOLD=""  
  COLDEFAULT=""  
 fi  
   
17  # export default path  # export default path
18  export PATH="${PATH}:${MLIBDIR}"  export PATH="${PATH}:${MLIBDIR}"
19    
# Line 55  export LC_ALL=C Line 23  export LC_ALL=C
23  # sanity checks  # sanity checks
24  [ ! -e ${VIRTUALDB_FILE} ] && touch ${VIRTUALDB_FILE}  [ ! -e ${VIRTUALDB_FILE} ] && touch ${VIRTUALDB_FILE}
25    
26  if [ ! -e ${VIRTUALDB_DEFAULTS} ] && [[ $1 != update ]] && [[ $1 != update-tarball ]]  if [ ! -e ${VIRTUALDB_DEFAULTS} ] &&
27     [[ $1 != update ]] &&
28     [[ $1 != update-rsync ]] &&
29     [[ $1 != update-tarball ]]
30  then  then
31   echo   echo
32   echo "Please choose an profile from the mage tree."   echo "Please choose an profile from the mage tree."
# Line 64  then Line 35  then
35  fi  fi
36    
37  # default messages  # default messages
 showversion()  
 {  
  local MAGEVERSION="$(< ${MLIBDIR}/version)"  
   
  echo -en "Magellan Package Manager v${MAGEVERSION} "  
  echo -e  "-- Niels Rogalla (niro@magellan-linux.de)"  
 }  
   
38  print_usage()  print_usage()
39  {  {
40   #showversion   #showversion
# Line 83  print_usage() Line 46  print_usage()
46   echo "    install         - installs a package"   echo "    install         - installs a package"
47   echo "    srcinstall      - installs a package from source"   echo "    srcinstall      - installs a package from source"
48   echo "    uninstall       - removes a package"   echo "    uninstall       - removes a package"
49   echo "    update          - updates the mage-tree via rsync"   echo "    update          - updates the mage-tree via default sync method"
50     echo "    update-rsync    - updates the mage-tree via rsync"
51   echo "    update-tarball  - updates the mage-tree via a tarball"   echo "    update-tarball  - updates the mage-tree via a tarball"
52   echo "    uppretend       - pretend dependencies for a system upgrade"   echo "    uppretend       - pretend dependencies for a system upgrade"
53   echo "    upgrade         - runs a complete system upgrade"   echo "    upgrade         - runs a complete system upgrade"
54   echo "    srcuppretend    - pretend dependencies for a system upgrade from source"   echo "    srcuppretend    - pretend dependencies for a system upgrade from source"
55   echo "    srcupgrade      - runs a complete system upgrade from source"   echo "    srcupgrade      - runs a complete system upgrade from source"
56     echo "    pretend-build-prerequisites - prints build prerequisites"
57     echo "    install-build-prerequisites - install build prerequisites"
58     echo "    run-preinstall  - runs preinstall part of an installed package"
59     echo "    run-postinstall - runs postinstall part of an installed package"
60   echo "    search          - searches mage-tree for a package"   echo "    search          - searches mage-tree for a package"
61   echo "    clean           - removes *all* downloaded packages"   echo "    clean           - removes *all* downloaded packages"
62   echo "    unpack          - unpacks *all* needed package for 'foo'"   echo "    unpack          - unpacks *all* needed package for 'foo'"
63   echo "    download        - downloads *all* needed packages for 'foo'"   echo "    download        - downloads *all* needed packages for 'foo'"
64     echo "    print-features  - prints all enabled mage-features"
65   echo "    version         - prints version info"   echo "    version         - prints version info"
66   echo "    regen-mage-tree - regenerates the whole mage database (for devs only)"   echo "    regen-mage-tree - regenerates the whole mage database (for devs only)"
67   echo   echo
# Line 118  echo Line 87  echo
87  # install method  # install method
88  METHOD="$1"  METHOD="$1"
89    
90  # initial unversionized packagename, gets overridden later  # initial unversionized packagename, gets overridden later on
91  MAGENAME="$2"  MAGENAME="$2"
92    
93  if [[ ${METHOD} != upgrade ]] && \  if [[ ${METHOD} != upgrade ]] &&
94   [[ ${METHOD} != srcupgrade ]] && \   [[ ${METHOD} != srcupgrade ]] &&
95   [[ ${METHOD} != uppretend ]] && \   [[ ${METHOD} != uppretend ]] &&
96   [[ ${METHOD} != srcuppretend ]] && \   [[ ${METHOD} != srcuppretend ]] &&
97   [[ ${METHOD} != update ]] && \   [[ ${METHOD} != update ]] &&
98   [[ ${METHOD} != update-tarball ]] && \   [[ ${METHOD} != update-rsync ]] &&
99   [[ ${METHOD} != clean ]] && \   [[ ${METHOD} != update-tarball ]] &&
100   [[ ${METHOD} != version ]] && \   [[ ${METHOD} != clean ]] &&
101   [[ ${METHOD} != search ]] && \   [[ ${METHOD} != version ]] &&
102   [[ ${METHOD} != regen-mage-tree ]]   [[ ${METHOD} != search ]] &&
103     [[ ${METHOD} != regen-mage-tree ]] &&
104     [[ ${METHOD} != print-features ]]
105  then  then
106   [[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1   [[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1
107  fi  fi
# Line 145  fi Line 116  fi
116  # before anything run mage_setup  # before anything run mage_setup
117  mage_setup || die "error in mage_setup()"  mage_setup || die "error in mage_setup()"
118    
119    # load supported mage features
120    load_mage_features
121    
122    # query debug mode
123    if mqueryfeature "debug"
124    then
125     depwalker_debug="--debug"
126    else
127     depwalker_debug=""
128    fi
129    
130  case ${METHOD} in  case ${METHOD} in
131   download)   download)
132     have_root_privileges || die "You must be root to run this operation."
133    
134   # first of all get the right pkg which going to be installed   # first of all get the right pkg which going to be installed
135   PCAT="$(pname2pcat ${MAGENAME})"   PCAT="$(pname2pcat ${MAGENAME})"
136    
# Line 166  case ${METHOD} in Line 150  case ${METHOD} in
150   PBUILD="$(pkgname2pbuild ${PKGNAME})"   PBUILD="$(pkgname2pbuild ${PKGNAME})"
151    
152   # get all dependencies of this package   # get all dependencies of this package
153   ALLDEPS="$(${MLIBDIR}/depwalker.sh \   ALLDEPS="$(${MLIBDIR}/depwalker \
154   --method install \   --method install \
155   --pcat ${PCAT} \   --pcat ${PCAT} \
156   --pname ${PNAME} \   --pname ${PNAME} \
157   --pver ${PVER} \   --pver ${PVER} \
158   --pbuild ${PBUILD})"   --pbuild ${PBUILD} \
159     ${depwalker_debug})"
160   fetch_packages ${ALLDEPS} || die "fetching packages"   fetch_packages ${ALLDEPS} || die "fetching packages"
161   md5sum_packages ${ALLDEPS} || die "md5 sum packages"   md5sum_packages ${ALLDEPS} || die "md5 sum packages"
162   ;;   ;;
163    
164   srcdownload)   srcdownload)
165     have_root_privileges || die "You must be root to run this operation."
166    
167   # first of all get the right pkg which going to be installed   # first of all get the right pkg which going to be installed
168   PCAT="$(pname2pcat ${MAGENAME})"   PCAT="$(pname2pcat ${MAGENAME})"
169    
# Line 196  case ${METHOD} in Line 183  case ${METHOD} in
183   PBUILD="$(pkgname2pbuild ${PKGNAME})"   PBUILD="$(pkgname2pbuild ${PKGNAME})"
184    
185   # get all dependencies of this package   # get all dependencies of this package
186   ALLDEPS="$(${MLIBDIR}/depwalker.sh \   ALLDEPS="$(${MLIBDIR}/depwalker \
187   --method srcinstall \   --method srcinstall \
188   --pcat ${PCAT} \   --pcat ${PCAT} \
189   --pname ${PNAME} \   --pname ${PNAME} \
190   --pver ${PVER} \   --pver ${PVER} \
191   --pbuild ${PBUILD})"   --pbuild ${PBUILD} \
192     ${depwalker_debug})"
193   fetch_packages ${ALLDEPS} || die "fetching packages"   fetch_packages ${ALLDEPS} || die "fetching packages"
194   ;;   ;;
195    
196   pretend|srcpretend)   pretend|srcpretend|pretend-build-prerequisites)
197   # first of all get the right pkg which going to be installed   # first of all get the right pkg which going to be installed
198   PCAT="$(pname2pcat ${MAGENAME})"   PCAT="$(pname2pcat ${MAGENAME})"
199    
# Line 233  case ${METHOD} in Line 221  case ${METHOD} in
221   exit 3   exit 3
222   fi   fi
223   # get all dependencies of this package   # get all dependencies of this package
224   ${MLIBDIR}/depwalker.sh \   ${MLIBDIR}/depwalker \
225   --method ${METHOD} \   --method ${METHOD} \
226   --pcat ${PCAT} \   --pcat ${PCAT} \
227   --pname ${PNAME} \   --pname ${PNAME} \
228   --pver ${PVER} \   --pver ${PVER} \
229   --pbuild ${PBUILD}   --pbuild ${PBUILD} \
230     ${depwalker_debug}
231   ;;   ;;
232    
233   install)   install|install-build-prerequisites)
234     have_root_privileges || die "You must be root to run this operation."
235    
236   # first of all get the right pkg which going to be installed   # first of all get the right pkg which going to be installed
237   PCAT="$(pname2pcat ${MAGENAME})"   PCAT="$(pname2pcat ${MAGENAME})"
238    
# Line 269  case ${METHOD} in Line 260  case ${METHOD} in
260   fi   fi
261    
262   # get all dependencies of this package   # get all dependencies of this package
263   ALLDEPS="$(${MLIBDIR}/depwalker.sh \   ALLDEPS="$(${MLIBDIR}/depwalker \
264   --method ${METHOD} \   --method ${METHOD} \
265   --pcat ${PCAT} \   --pcat ${PCAT} \
266   --pname ${PNAME} \   --pname ${PNAME} \
267   --pver ${PVER} \   --pver ${PVER} \
268   --pbuild ${PBUILD})"   --pbuild ${PBUILD} \
269     ${depwalker_debug})"
270    
271   # first fetch all packages   # first fetch all packages
272   fetch_packages ${ALLDEPS} || die "fetching packages"   fetch_packages ${ALLDEPS} || die "fetching packages"
273   md5sum_packages ${ALLDEPS} || die "md5 sum packages"   md5sum_packages ${ALLDEPS} || die "md5 sum packages"
  unpack_packages ${ALLDEPS} || die "unpacking packages"  
274   install_packages ${ALLDEPS} || die "installing packages"   install_packages ${ALLDEPS} || die "installing packages"
275   ;;   ;;
276    
277   srcinstall)   srcinstall)
278     have_root_privileges || die "You must be root to run this operation."
279    
280   # first of all get the right pkg which going to be installed   # first of all get the right pkg which going to be installed
281   PCAT="$(pname2pcat ${MAGENAME})"   PCAT="$(pname2pcat ${MAGENAME})"
282    
# Line 311  case ${METHOD} in Line 304  case ${METHOD} in
304   fi   fi
305    
306   # get all dependencies of this package   # get all dependencies of this package
307   ALLDEPS="$(${MLIBDIR}/depwalker.sh \   ALLDEPS="$(${MLIBDIR}/depwalker \
308   --method ${METHOD} \   --method ${METHOD} \
309   --pcat ${PCAT} \   --pcat ${PCAT} \
310   --pname ${PNAME} \   --pname ${PNAME} \
311   --pver ${PVER} \   --pver ${PVER} \
312   --pbuild ${PBUILD})"   --pbuild ${PBUILD} \
313     ${depwalker_debug})"
314    
315   install_packages --src-install ${ALLDEPS} || die "src-installing packages"   install_packages --src-install ${ALLDEPS} || die "src-installing packages"
316   ;;   ;;
317    
318   uninstall)   uninstall)
319   ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})"   have_root_privileges || die "You must be root to run this operation."
320   if [ -z "${ALLDEPS}" ]  
321   then   ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})"
322   die "No package installed named '${MAGENAME}'."   if [ -z "${ALLDEPS}" ]
323   fi   then
324   uninstall_packages ${ALLDEPS}   die "No package installed named '${MAGENAME}'."
325     fi
326     uninstall_packages ${ALLDEPS}
327     ;;
328    
329     run-preinstall|run-postinstall)
330     have_root_privileges || die "You must be root to run this operation."
331    
332     ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})"
333     if [ -z "${ALLDEPS}" ]
334     then
335     die "No package installed named '${MAGENAME}'."
336     fi
337     rerun_pkgfunctions --method "${METHOD//run-}" ${ALLDEPS}
338   ;;   ;;
339    
340   uppretend|srcuppretend)   uppretend|srcuppretend)
341   ${MLIBDIR}/depwalker.sh \   ${MLIBDIR}/depwalker \
342   --method ${METHOD} \   --method ${METHOD} \
343   --pcat ${METHOD} \   --pcat ${METHOD} \
344   --pname ${METHOD} \   --pname ${METHOD} \
345   --pver ${METHOD} \   --pver ${METHOD} \
346   --pbuild ${METHOD}   --pbuild ${METHOD} \
347     ${depwalker_debug}
348   ;;   ;;
349    
350   upgrade)   upgrade)
351     have_root_privileges || die "You must be root to run this operation."
352    
353   # get all dependencies of *all* installed packages   # get all dependencies of *all* installed packages
354   # fake pcat,pname,pver,pbuild ...   # fake pcat,pname,pver,pbuild ...
355   ALLDEPS="$(${MLIBDIR}/depwalker.sh \   ALLDEPS="$(${MLIBDIR}/depwalker \
356   --method ${METHOD} \   --method ${METHOD} \
357   --pcat ${METHOD} \   --pcat ${METHOD} \
358   --pname ${METHOD} \   --pname ${METHOD} \
359   --pver ${METHOD} \   --pver ${METHOD} \
360   --pbuild ${METHOD})"   --pbuild ${METHOD} \
361     ${depwalker_debug})"
362    
363   # first fetch all packages   # first fetch all packages
364   fetch_packages ${ALLDEPS} || die "fetching packages"   fetch_packages ${ALLDEPS} || die "fetching packages"
365   md5sum_packages ${ALLDEPS} || die "md5 sum packages"   md5sum_packages ${ALLDEPS} || die "md5 sum packages"
  unpack_packages ${ALLDEPS} || die "unpacking packages"  
366   install_packages ${ALLDEPS} || die "installing packages"   install_packages ${ALLDEPS} || die "installing packages"
367   ;;   ;;
368    
369   srcupgrade)   srcupgrade)
370     have_root_privileges || die "You must be root to run this operation."
371    
372   # get all dependencies of *all* installed packages   # get all dependencies of *all* installed packages
373   # fake pcat,pname,pver,pbuild ...   # fake pcat,pname,pver,pbuild ...
374   ALLDEPS="$(${MLIBDIR}/depwalker.sh \   ALLDEPS="$(${MLIBDIR}/depwalker \
375   --method ${METHOD} \   --method ${METHOD} \
376   --pcat ${METHOD} \   --pcat ${METHOD} \
377   --pname ${METHOD} \   --pname ${METHOD} \
378   --pver ${METHOD} \   --pver ${METHOD} \
379   --pbuild ${METHOD})"   --pbuild ${METHOD} \
380     ${depwalker_debug})"
381    
382   install_packages --src-install ${ALLDEPS} || die "src-installing packages"   install_packages --src-install ${ALLDEPS} || die "src-installing packages"
383   ;;   ;;
# Line 374  case ${METHOD} in Line 387  case ${METHOD} in
387   ;;   ;;
388    
389   unpack)   unpack)
390     have_root_privileges || die "You must be root to run this operation."
391    
392   # first of all get the right pkg which going to be installed   # first of all get the right pkg which going to be installed
393   PCAT="$(pname2pcat ${MAGENAME})"   PCAT="$(pname2pcat ${MAGENAME})"
394    
# Line 393  case ${METHOD} in Line 408  case ${METHOD} in
408   PBUILD="$(pkgname2pbuild ${PKGNAME})"   PBUILD="$(pkgname2pbuild ${PKGNAME})"
409    
410   # get all dependencies of this package   # get all dependencies of this package
411   ALLDEPS="$(${MLIBDIR}/depwalker.sh \   ALLDEPS="$(${MLIBDIR}/depwalker \
412   --method install \   --method install \
413   --pcat ${PCAT} \   --pcat ${PCAT} \
414   --pname ${PNAME} \   --pname ${PNAME} \
415   --pver ${PVER} \   --pver ${PVER} \
416   --pbuild ${PBUILD})"   --pbuild ${PBUILD} \
417     ${depwalker_debug})"
418    
419   fetch_packages ${ALLDEPS} || die "fetching packages"   fetch_packages ${ALLDEPS} || die "fetching packages"
420   md5sum_packages ${ALLDEPS} || die "md5 sum packages"   md5sum_packages ${ALLDEPS} || die "md5 sum packages"
421   unpack_packages ${ALLDEPS} || die "unpacking packages"   unpack_packages ${ALLDEPS} || die "unpacking packages"
422   ;;   ;;
423    
424   update)   update)
425     have_root_privileges || die "You must be root to run this operation."
426     # default to tarball
427     [[ -z ${MAGE_UPDATE_METHOD} ]] && MAGE_UPDATE_METHOD="tarball"
428     case ${MAGE_UPDATE_METHOD} in
429     rsync) syncmage ;;
430     tarball) syncmage_tarball ;;
431     *) die "Unknown MAGE_UPDATE_METHOD defined." ;;
432     esac
433     ;;
434    
435     update-rsync)
436     have_root_privileges || die "You must be root to run this operation."
437   syncmage   syncmage
438   ;;   ;;
439    
440   update-tarball)   update-tarball)
441     have_root_privileges || die "You must be root to run this operation."
442   syncmage_tarball   syncmage_tarball
443   ;;   ;;
444    
445   clean)   clean)
446     have_root_privileges || die "You must be root to run this operation."
447   cleanpkg   cleanpkg
448   ;;   ;;
449    
# Line 422  case ${METHOD} in Line 453  case ${METHOD} in
453   ;;   ;;
454    
455   regen-mage-tree)   regen-mage-tree)
456     have_root_privileges || die "You must be root to run this operation."
457    
458   if [ -z "${SMAGESCRIPTSDIR}" ] || [ ! -d "${SMAGESCRIPTSDIR}" ]   if [ -z "${SMAGESCRIPTSDIR}" ] || [ ! -d "${SMAGESCRIPTSDIR}" ]
459   then   then
460   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 433  case ${METHOD} in Line 466  case ${METHOD} in
466   done   done
467   ;;   ;;
468    
469     print-features)
470     mprintfeatures
471     ;;
472    
473   *)   *)
474   print_usage   print_usage
475   ;;   ;;

Legend:
Removed from v.1269  
changed lines
  Added in v.2617