Magellan Linux

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

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

revision 677 by niro, Tue Feb 26 19:51:40 2008 UTC revision 2840 by niro, Fri Oct 24 08:23:22 2014 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2    # $Id$
3  #depwalker  # dependency walker
 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/depwalker.sh,v 1.9 2008-02-26 19:51:40 niro Exp $  
4    
5  # default die function  # default die function
6  die()  die()
# Line 10  die() Line 9  die()
9   exit 1   exit 1
10  }  }
11    
12    decho()
13    {
14     if [[ ${DEBUG} = 1 ]]
15     then
16     echo "DEBUG: $@" >&2
17     fi
18    }
19    
20  # include all needed files  # include all needed files
21  [ -f /etc/mage.rc.global ] &&  \  [ -f /etc/mage.rc.global ] &&  \
22   source /etc/mage.rc.global || \   source /etc/mage.rc.global || \
# Line 22  die() Line 29  die()
29   source ${MLIBDIR}/mage4.functions.sh || \   source ${MLIBDIR}/mage4.functions.sh || \
30   die "mage functions missing"   die "mage functions missing"
31    
32  # for tests only  [ -f ${MLIBDIR}/smage2.functions.sh ] && \
33  # source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage.rc.global   source ${MLIBDIR}/smage2.functions.sh || \
34  # source /etc/mage.rc   die "smage functions missing"
 # 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  
   
 # not serious if missing, only needed for colors  
 [ -f /etc/init.d/functions ] && source /etc/init.d/functions  
   
 # disable colors if wanted  
 if [[ ${NOCOLORS} = true ]]  
 then  
  COLRED=""  
  COLGREEN=""  
  COLYELLOW=""  
  COLBLUE=""  
  COLMAGENTA=""  
  COLWHITE=""  
  COLDEFAULT=""  
 fi  
35    
36  usage()  usage()
37  {  {
# Line 49  usage() Line 39  usage()
39   echo "Usage: $(basename $0) [command] [arg] ..."   echo "Usage: $(basename $0) [command] [arg] ..."
40   echo   echo
41   echo "  -h     --help          shows this help"   echo "  -h     --help          shows this help"
42   echo "  -c     --pcat          categorie of the package"   echo "  -c     --pcat          category of the package"
43   echo "  -n     --pname         name of the package"   echo "  -n     --pname         name of the package"
44   echo "  -v     --pver          version number of the package"   echo "  -v     --pver          version number of the package"
45   echo "  -b     --pbuild        build number of the package"   echo "  -b     --pbuild        build number of the package"
46   echo "  -m     --method        which calc method should be used:"   echo "  -m     --method        which calc method should be used:"
47   echo "                         install, srcinstall, depend, srcdepend"   echo "                         install, srcinstall, pretend, srcpretend"
48   echo "                         upgrade, srcupgrade"   echo "                         upgrade, srcupgrade,"
49     echo "                         install-build-prerequisites,"
50     echo "                         pretend-build-prerequisites"
51     echo "                         install-deep-build-prerequisites,"
52     echo "                         pretend-deep-build-prerequisites"
53     echo "  -d     --debug         enable debug mode"
54     echo "  -s     --smage         use a smage to calculate dependencies"
55   echo   echo
56   echo "method,name, version and build must be given !"   echo "method, category, name, version and build must be given !"
57   echo   echo
58   exit 1   exit 1
59  }  }
60    
61    # set some sane defaults
62    DEBUG=0
63    SMAGE_DEPEND=0
64    SDEPEND_ONETIME=0
65    
66  # very basic getops  # very basic getops
67  for i in $*  for i in $*
68  do  do
# Line 71  do Line 72  do
72   --pver|-v) shift; PVER="$1" ;;   --pver|-v) shift; PVER="$1" ;;
73   --pbuild|-b) shift; PBUILD="$1" ;;   --pbuild|-b) shift; PBUILD="$1" ;;
74   --method|-m) shift; METHOD="$1" ;;   --method|-m) shift; METHOD="$1" ;;
75     --debug|-d) shift; DEBUG=1 ;;
76     --smage|-s) shift; SMAGEFILE="$1"; SMAGE_DEPEND=1; SILENT=1; FVERBOSE=off ;;
77   --help|-h) usage ;;   --help|-h) usage ;;
78   esac   esac
79   shift   shift
80  done  done
81    
82  # sanity checks; abort if not given  # sanity checks; abort if not given
83  [ -z "${PCAT}" ] && usage  if [[ -z ${SMAGEFILE} ]]
84  [ -z "${PNAME}" ] && usage  then
85  [ -z "${PVER}" ] && usage   [ -z "${PCAT}" ] && usage
86  [ -z "${PBUILD}" ] && usage   [ -z "${PNAME}" ] && usage
87     [ -z "${PVER}" ] && usage
88     [ -z "${PBUILD}" ] && usage
89    fi
90  [ -z "${METHOD}" ] && usage  [ -z "${METHOD}" ] && usage
91    
92  # check needed global vars  # check needed global vars
# Line 88  done Line 94  done
94  [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set."  [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set."
95  [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set."  [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set."
96    
97    # load mage-features to support them with smagesource()
98    load_mage_features
99    
100  # other needed vars  # other needed vars
101  ALLDEPS=""  ALLDEPS=""
102    if [[ -n ${SMAGEFILE} ]]
103    then
104     if [[ -e ${SMAGEFILE} ]]
105     then
106     smagesource "${SMAGEFILE}"
107     else
108     die "Smage file '${SMAGEFILE}' does not exist!"
109     fi
110    fi
111  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
112    
113  # much faster than fgrep  # much faster than fgrep
# Line 120  checklist_processeddeps() Line 138  checklist_processeddeps()
138  }  }
139    
140  #####################  #####################
141  ##  rumwandern /path/to/mage/file/.mage  ##  depwalking /path/to/mage/file/.mage
142  rumwandern()  depwalking()
143  {  {
144   unset DEPEND   unset DEPEND
145   unset SDEPEND   unset SDEPEND
# Line 142  rumwandern() Line 160  rumwandern()
160    
161   DFILE="$1"   DFILE="$1"
162    
163     # debug info
164     decho "depwalking magefile '${DFILE}'"
165     decho
166    
167   source ${DFILE}   source ${DFILE}
168    
169     # forced nodeps
170     if [[ ${NODEPS} = true ]]
171     then
172     DEPEND=""
173     SDEPEND=""
174     fi
175    
176   MY_DEPEND="${DEPEND}"   MY_DEPEND="${DEPEND}"
177    
178   # for srcinstall & srcdepend only; SDEPEND also needed   # for srcinstall & srcdepend only; SDEPEND also needed
179   if [[ ${METHOD} = srcinstall ]] || \   if [[ ${METHOD} = srcinstall ]] ||
180   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] ||
181   [[ ${METHOD} = srcupgrade ]] || \   [[ ${METHOD} = srcupgrade ]] ||
182   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] ||
183     [[ ${METHOD} = install-deep-build-prerequisites ]] ||
184     [[ ${METHOD} = pretend-deep-build-prerequisites ]]
185   then   then
186   # only if SDEPEND is not zero   # only if SDEPEND is not zero
187   if [ -n "${SDEPEND}" ]   if [ -n "${SDEPEND}" ]
# Line 165  rumwandern() Line 197  rumwandern()
197   fi   fi
198   fi   fi
199    
200     # add sdepend for the smage/mage file only for the first time
201     # to catch sdepend only from the target
202     if [[ ${METHOD} = install-build-prerequisites ]] ||
203     [[ ${METHOD} = pretend-build-prerequisites ]]
204     then
205     if [[ ${SDEPEND_ONETIME} = 0 ]]
206     then
207     # only if SDEPEND is not zero
208     if [ -n "${SDEPEND}" ]
209     then
210     # crlf is substantly needed !!
211     if [ -n "${MY_DEPEND}" ]
212     then
213     MY_DEPEND="${MY_DEPEND}
214     ${SDEPEND}"
215     else
216     MY_DEPEND="${SDEPEND}"
217     fi
218     fi
219     SDEPEND_ONETIME=1
220     fi
221     fi
222    
223   unset DEPEND   unset DEPEND
224   unset SDEPEND   unset SDEPEND
225    
226   if [ -z "${MY_DEPEND}" ]   if [ -z "${MY_DEPEND}" ]
227   then   then
228     decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
229   return 1   return 1
230   fi   fi
231    
232   while read SYM DEPNAME   while read SYM DEPNAME
233   do   do
234     # debug info
235     decho "DEPNAME='${DEPNAME}'"
236    
237   # exclude empty depnames   # exclude empty depnames
238   [[ -z ${DEPNAME} ]] && continue   [[ -z ${DEPNAME} ]] && continue
239    
# Line 186  rumwandern() Line 245  rumwandern()
245    
246   # mark depfile as processed to prevent double runs -without version   # mark depfile as processed to prevent double runs -without version
247   # but do not add any virtuals to PROCESSEDDEPS or their resolved   # but do not add any virtuals to PROCESSEDDEPS or their resolved
248   # pkgnames will be ignored and they are missing on the dependecy-list   # pkgnames will be ignored and they are missing on the dependency-list
249   if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]   if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
250   then   then
251   PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"   PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
252   fi   fi
253    
254   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
255     if [[ -z ${HIGHEST_DEPFILE} ]]
256     then
257     INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
258     continue
259     fi
260    
261   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
262   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
263   PVER="$(magename2pver ${HIGHEST_DEPFILE})"   PVER="$(magename2pver ${HIGHEST_DEPFILE})"
264   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
265    
266   ## check ob schon in ALLDEPS enthalten dann mach weiter   ## dep already in ALLDEPS? then going on
267    
268   # usage of fgrep is extremly slow and consumes a lot of cpu power   # usage of fgrep is extremly slow and consumes a lot of cpu power
269   #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]   #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
270   if checklist_alldeps "${HIGHEST_DEPFILE}"   if checklist_alldeps "${HIGHEST_DEPFILE}"
271   then   then
272   ### check ob DFILE schon installiert ist ###   ### check if the dependency is already installed ###
273   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
274   then   then
275   rumwandern ${HIGHEST_DEPFILE}   # but first get all deps of highest_depfile to catch all dependencies of it
276     depwalking ${HIGHEST_DEPFILE}
277   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
278     decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
279   fi   fi
280   fi   fi
281   done << EOF   done << EOF
# Line 218  EOF Line 284  EOF
284   return 0   return 0
285  }  }
286    
   
 ### abort if this package is already installed (retval 3)  
 # maybe later ?  
 #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3  
   
287  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
288   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
289   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
290   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
291     [[ ${METHOD} = pretend-build-prerequisites ]] && \
292   echo -n "Calculating dependencies ... "   echo -n "Calculating dependencies ... "
293    
294    
# Line 244  then Line 306  then
306   # get the highest mage file from mage-db   # get the highest mage file from mage-db
307   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
308    
309     # debug info
310     decho "dep='${dep}'"
311     decho "PCAT='${PCAT}'"
312     decho "PNAME='${PNAME}'"
313     decho "MAGEFILE='${MAGEFILE}'"
314    
315     # if no install candidate was found, record this
316     # and process with the next one
317     if [[ -z ${MAGEFILE} ]]
318     then
319     NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
320     decho "added to NO_UPGRADE_CANDIDATE"
321     continue
322     fi
323    
324   # now get the pver&pbuild from the new file   # now get the pver&pbuild from the new file
325   PVER="$(magename2pver ${MAGEFILE})"   PVER="$(magename2pver ${MAGEFILE})"
326   PBUILD="$(magename2pbuild ${MAGEFILE})"   PBUILD="$(magename2pbuild ${MAGEFILE})"
327    
328   # do not wander files which are installed   # debug info
329     decho "PVER='${PVER}'"
330     decho "PBUILD='${PBUILD}'"
331    
332     # do not walk files which are installed
333   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
334   then   then
335   # get dependencies the package   # get dependencies the package
336   rumwandern ${MAGEFILE}   depwalking ${MAGEFILE}
337    
338   # now add the package itself to the dependencies   # now add the package itself to the dependencies
339   # (if not exists already)   # (if not exists already)
  #if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ]  
340   if checklist_alldeps "${MAGEFILE}"   if checklist_alldeps "${MAGEFILE}"
341   then   then
342     decho "added '${MAGEFILE}' to ALLDEPS"
343   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   ALLDEPS="${ALLDEPS} ${MAGEFILE}"
344   fi   fi
345     else
346     # debug info
347     decho "ignored package"
348     decho
349   fi   fi
350   done   done
351  else  else
352   # get dependencies the package   # get all dependencies of the package
353   rumwandern ${MAGEFILE}   if [[ -n ${SMAGEFILE} ]]
354     then
355     depwalking "${SMAGEFILE}"
356     else
357     depwalking "${MAGEFILE}"
358     fi
359    fi
360    
361    if [[ ${METHOD} != install-build-prerequisites ]] &&
362     [[ ${METHOD} != pretend-build-prerequisites ]] &&
363     [[ ${METHOD} != install-deep-build-prerequisites ]] &&
364     [[ ${METHOD} != pretend-deep-build-prerequisites ]] &&
365     [[ ${METHOD} != upgrade ]] &&
366     [[ ${METHOD} != uppretend ]] &&
367     [[ ${METHOD} != srcupgrade ]] &&
368     [[ ${METHOD} != srcuppretend ]]
369    then
370   # now add the package itself to the dependencies   # now add the package itself to the dependencies
371   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   # (if not exists already)
372     if checklist_alldeps "${MAGEFILE}"
373     then
374     decho "added '${MAGEFILE}' to ALLDEPS"
375     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
376     fi
377  fi  fi
378    
379  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
380   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
381   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
382   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
383     [[ ${METHOD} = pretend-build-prerequisites ]] || \
384     [[ ${METHOD} = pretend-deep-build-prerequisites ]] && \
385   echo "done"   echo "done"
386    
387    
# Line 282  fi Line 389  fi
389  if [[ ${METHOD} = pretend ]] || \  if [[ ${METHOD} = pretend ]] || \
390   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
391   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
392   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] || \
393     [[ ${METHOD} = pretend-build-prerequisites ]] || \
394     [[ ${METHOD} = pretend-deep-build-prerequisites ]]
395  then  then
396   # this is a little bit faster   # this is a little bit faster
397   declare -i x=0   declare -i x=0
# Line 299  then Line 408  then
408   PBUILD="$(magename2pbuild ${i})"   PBUILD="$(magename2pbuild ${i})"
409   if [ -z "${list}" ]   if [ -z "${list}" ]
410   then   then
411   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
412   else   else
413   list="${list}   list="${list}
414  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
# Line 309  then Line 418  then
418   echo "done"   echo "done"
419   echo -e "${list}"   echo -e "${list}"
420   echo   echo
421    
422     if [[ ! -z ${INVALID_DEPS} ]]
423     then
424     echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}"
425     for i in ${INVALID_DEPS}
426     do
427     _dep="${i%%:*}"
428     _mage="${i##*:}"
429     echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}"
430     done
431     echo
432     fi
433    
434     if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
435     then
436     echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
437     for i in ${NO_UPGRADE_CANDIDATE}
438     do
439     echo -e "${COLRED}    ${i}${COLDEFAULT}"
440     done
441     echo
442     echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"
443     echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"
444     echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
445     echo
446     fi
447  fi  fi
448    
449  ## return output from src/install deps  ## return output from src/install deps
450  [[ ${METHOD} = install ]] || \  [[ ${METHOD} = install ]] || \
451   [[ ${METHOD} = srcinstall ]] || \   [[ ${METHOD} = srcinstall ]] || \
452   [[ ${METHOD} = upgrade ]] || \   [[ ${METHOD} = upgrade ]] || \
453   [[ ${METHOD} = srcupgrade ]] && \   [[ ${METHOD} = srcupgrade ]] || \
454     [[ ${METHOD} = install-build-prerequisites ]] || \
455     [[ ${METHOD} = install-deep-build-prerequisites ]] && \
456   echo "${ALLDEPS}"   echo "${ALLDEPS}"
   
 # delete ${BUILDDIR}/virtuals if exists as not needed anymore  
 #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals  

Legend:
Removed from v.677  
changed lines
  Added in v.2840