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

Legend:
Removed from v.739  
changed lines
  Added in v.2618