Magellan Linux

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

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

revision 419 by niro, Mon Jan 22 00:24:14 2007 UTC revision 2838 by niro, Wed Oct 22 12:26:49 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.5 2007-01-22 00:24:14 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 "  -d     --debug         enable debug mode"
52     echo "  -s     --smage         use a smage to calculate dependencies"
53   echo   echo
54   echo "method,name, version and build must be given !"   echo "method, category, name, version and build must be given !"
55   echo   echo
56   exit 1   exit 1
57  }  }
58    
59    # set some sane defaults
60    DEBUG=0
61    SMAGE_DEPEND=0
62    
63  # very basic getops  # very basic getops
64  for i in $*  for i in $*
65  do  do
# Line 71  do Line 69  do
69   --pver|-v) shift; PVER="$1" ;;   --pver|-v) shift; PVER="$1" ;;
70   --pbuild|-b) shift; PBUILD="$1" ;;   --pbuild|-b) shift; PBUILD="$1" ;;
71   --method|-m) shift; METHOD="$1" ;;   --method|-m) shift; METHOD="$1" ;;
72     --debug|-d) shift; DEBUG=1 ;;
73     --smage|-s) shift; SMAGEFILE="$1"; SMAGE_DEPEND=1; SILENT=1; FVERBOSE=off ;;
74   --help|-h) usage ;;   --help|-h) usage ;;
75   esac   esac
76   shift   shift
77  done  done
78    
79  # sanity checks; abort if not given  # sanity checks; abort if not given
80  [ -z "${PCAT}" ] && usage  if [[ -z ${SMAGEFILE} ]]
81  [ -z "${PNAME}" ] && usage  then
82  [ -z "${PVER}" ] && usage   [ -z "${PCAT}" ] && usage
83  [ -z "${PBUILD}" ] && usage   [ -z "${PNAME}" ] && usage
84     [ -z "${PVER}" ] && usage
85     [ -z "${PBUILD}" ] && usage
86    fi
87  [ -z "${METHOD}" ] && usage  [ -z "${METHOD}" ] && usage
88    
89  # check needed global vars  # check needed global vars
# Line 88  done Line 91  done
91  [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set."  [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set."
92  [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set."  [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set."
93    
94    # load mage-features to support them with smagesource()
95    load_mage_features
96    
97  # other needed vars  # other needed vars
98  ALLDEPS=""  ALLDEPS=""
99    if [[ -n ${SMAGEFILE} ]]
100    then
101     if [[ -e ${SMAGEFILE} ]]
102     then
103     smagesource "${SMAGEFILE}"
104     else
105     die "Smage file '${SMAGEFILE}' does not exist!"
106     fi
107    fi
108  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
109    
110    # much faster than fgrep
111    checklist_alldeps()
112    {
113     local i
114     local item="$1"
115    
116     for i in ${ALLDEPS}
117     do
118     [[ ${i} = ${item} ]] && return 1
119     done
120    
121     return 0
122    }
123    
124    checklist_processeddeps()
125    {
126     local i
127     local item="$1"
128    
129     for i in ${PROCESSEDDEPS}
130     do
131     [[ ${i} = ${item} ]] && return 1
132     done
133    
134     return 0
135    }
136    
137  #####################  #####################
138  ##  rumwandern /path/to/mage/file/.mage  ##  depwalking /path/to/mage/file/.mage
139  rumwandern()  depwalking()
140  {  {
141   unset DEPEND   unset DEPEND
142   unset SDEPEND   unset SDEPEND
# Line 115  rumwandern() Line 157  rumwandern()
157    
158   DFILE="$1"   DFILE="$1"
159    
160     # debug info
161     decho "depwalking magefile '${DFILE}'"
162     decho
163    
164   source ${DFILE}   source ${DFILE}
165    
166     # forced nodeps
167     if [[ ${NODEPS} = true ]]
168     then
169     DEPEND=""
170     SDEPEND=""
171     fi
172    
173   MY_DEPEND="${DEPEND}"   MY_DEPEND="${DEPEND}"
174    
175   # for srcinstall & srcdepend only; SDEPEND also needed   # for srcinstall & srcdepend only; SDEPEND also needed
176   if [[ ${METHOD} = srcinstall ]] || \   if [[ ${METHOD} = srcinstall ]] ||
177   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] ||
178   [[ ${METHOD} = srcupgrade ]] || \   [[ ${METHOD} = srcupgrade ]] ||
179   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] ||
180     [[ ${METHOD} = install-build-prerequisites ]] ||
181     [[ ${METHOD} = pretend-build-prerequisites ]]
182   then   then
183   # only if SDEPEND is not zero   # only if SDEPEND is not zero
184   if [ -n "${SDEPEND}" ]   if [ -n "${SDEPEND}" ]
# Line 143  rumwandern() Line 199  rumwandern()
199    
200   if [ -z "${MY_DEPEND}" ]   if [ -z "${MY_DEPEND}" ]
201   then   then
202     decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
203   return 1   return 1
204   fi   fi
205    
206   while read SYM DEPNAME   while read SYM DEPNAME
207   do   do
208     # debug info
209     decho "DEPNAME='${DEPNAME}'"
210    
211     # exclude empty depnames
212     [[ -z ${DEPNAME} ]] && continue
213    
214     # exclude all already processed deps -without version
215     if ! checklist_processeddeps "${DEPNAME%-*}"
216     then
217     continue
218     fi
219    
220     # mark depfile as processed to prevent double runs -without version
221     # but do not add any virtuals to PROCESSEDDEPS or their resolved
222     # pkgnames will be ignored and they are missing on the dependency-list
223     if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
224     then
225     PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
226     fi
227    
228   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
229     if [[ -z ${HIGHEST_DEPFILE} ]]
230     then
231     INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
232     continue
233     fi
234    
235   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
236   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
237   PVER="$(magename2pver ${HIGHEST_DEPFILE})"   PVER="$(magename2pver ${HIGHEST_DEPFILE})"
238   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
239    
240   ## check ob schon in ALLDEPS enthalten dann mach weiter   ## dep already in ALLDEPS? then going on
241   if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]  
242     # usage of fgrep is extremly slow and consumes a lot of cpu power
243     #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
244     if checklist_alldeps "${HIGHEST_DEPFILE}"
245   then   then
246   ### check ob DFILE schon installiert ist ###   ### check if the dependency is already installed ###
247   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
248   then   then
249   rumwandern ${HIGHEST_DEPFILE}   # but first get all deps of highest_depfile to catch all dependencies of it
250     depwalking ${HIGHEST_DEPFILE}
251   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
252     decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
253   fi   fi
254   fi   fi
255   done << EOF   done << EOF
# Line 171  EOF Line 258  EOF
258   return 0   return 0
259  }  }
260    
   
 ### abort if this package is already installed (retval 3)  
 # maybe later ?  
 #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3  
   
261  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
262   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
263   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
264   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
265     [[ ${METHOD} = pretend-build-prerequisites ]] && \
266   echo -n "Calculating dependencies ... "   echo -n "Calculating dependencies ... "
267    
268    
# Line 197  then Line 280  then
280   # get the highest mage file from mage-db   # get the highest mage file from mage-db
281   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
282    
283     # debug info
284     decho "dep='${dep}'"
285     decho "PCAT='${PCAT}'"
286     decho "PNAME='${PNAME}'"
287     decho "MAGEFILE='${MAGEFILE}'"
288    
289     # if no install candidate was found, record this
290     # and process with the next one
291     if [[ -z ${MAGEFILE} ]]
292     then
293     NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
294     decho "added to NO_UPGRADE_CANDIDATE"
295     continue
296     fi
297    
298   # now get the pver&pbuild from the new file   # now get the pver&pbuild from the new file
299   PVER="$(magename2pver ${MAGEFILE})"   PVER="$(magename2pver ${MAGEFILE})"
300   PBUILD="$(magename2pbuild ${MAGEFILE})"   PBUILD="$(magename2pbuild ${MAGEFILE})"
301    
302   # do not wander files which are installed   # debug info
303     decho "PVER='${PVER}'"
304     decho "PBUILD='${PBUILD}'"
305    
306     # do not walk files which are installed
307   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
308   then   then
309   # get dependencies the package   # get dependencies the package
310   rumwandern ${MAGEFILE}   depwalking ${MAGEFILE}
311    
312   # now add the package itself to the dependencies   # now add the package itself to the dependencies
313   # (if not exists already)   # (if not exists already)
314   if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ]   if checklist_alldeps "${MAGEFILE}"
315   then   then
316     decho "added '${MAGEFILE}' to ALLDEPS"
317   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   ALLDEPS="${ALLDEPS} ${MAGEFILE}"
318   fi   fi
319     else
320     # debug info
321     decho "ignored package"
322     decho
323   fi   fi
324   done   done
325  else  else
326   # get dependencies the package   # get all dependencies of the package
327   rumwandern ${MAGEFILE}   if [[ -n ${SMAGEFILE} ]]
328     then
329     depwalking "${SMAGEFILE}"
330     else
331     depwalking "${MAGEFILE}"
332     fi
333    fi
334    
335    if [[ ${METHOD} != install-build-prerequisites ]] &&
336     [[ ${METHOD} != pretend-build-prerequisites ]] &&
337     [[ ${METHOD} != upgrade ]] &&
338     [[ ${METHOD} != uppretend ]] &&
339     [[ ${METHOD} != srcupgrade ]] &&
340     [[ ${METHOD} != srcuppretend ]]
341    then
342   # now add the package itself to the dependencies   # now add the package itself to the dependencies
343   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   # (if not exists already)
344     if checklist_alldeps "${MAGEFILE}"
345     then
346     decho "added '${MAGEFILE}' to ALLDEPS"
347     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
348     fi
349  fi  fi
350    
351  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
352   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
353   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
354   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
355     [[ ${METHOD} = pretend-build-prerequisites ]] && \
356   echo "done"   echo "done"
357    
358    
# Line 234  fi Line 360  fi
360  if [[ ${METHOD} = pretend ]] || \  if [[ ${METHOD} = pretend ]] || \
361   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
362   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
363   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] || \
364     [[ ${METHOD} = pretend-build-prerequisites ]]
365  then  then
366   # this is a little bit faster   # this is a little bit faster
367   declare -i x=0   declare -i x=0
# Line 251  then Line 378  then
378   PBUILD="$(magename2pbuild ${i})"   PBUILD="$(magename2pbuild ${i})"
379   if [ -z "${list}" ]   if [ -z "${list}" ]
380   then   then
381   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
382   else   else
383   list="${list}   list="${list}
384  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
# Line 261  then Line 388  then
388   echo "done"   echo "done"
389   echo -e "${list}"   echo -e "${list}"
390   echo   echo
391    
392     if [[ ! -z ${INVALID_DEPS} ]]
393     then
394     echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}"
395     for i in ${INVALID_DEPS}
396     do
397     _dep="${i%%:*}"
398     _mage="${i##*:}"
399     echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}"
400     done
401     echo
402     fi
403    
404     if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
405     then
406     echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
407     for i in ${NO_UPGRADE_CANDIDATE}
408     do
409     echo -e "${COLRED}    ${i}${COLDEFAULT}"
410     done
411     echo
412     echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"
413     echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"
414     echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
415     echo
416     fi
417  fi  fi
418    
419  ## return output from src/install deps  ## return output from src/install deps
420  [[ ${METHOD} = install ]] || \  [[ ${METHOD} = install ]] || \
421   [[ ${METHOD} = srcinstall ]] || \   [[ ${METHOD} = srcinstall ]] || \
422   [[ ${METHOD} = upgrade ]] || \   [[ ${METHOD} = upgrade ]] || \
423   [[ ${METHOD} = srcupgrade ]] && \   [[ ${METHOD} = srcupgrade ]] || \
424     [[ ${METHOD} = install-build-prerequisites ]] && \
425   echo "${ALLDEPS}"   echo "${ALLDEPS}"
   
 # delete ${BUILDDIR}/virtuals if exists as not needed anymore  
 #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals  

Legend:
Removed from v.419  
changed lines
  Added in v.2838