Magellan Linux

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

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

trunk/mage/usr/lib/mage/depwalker.sh revision 701 by niro, Wed Mar 26 15:58:25 2008 UTC branches/mage-next/src/depwalker.in revision 2829 by niro, Wed Sep 17 11:20:37 2014 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2    # $Id$
3    # dependency walker
4    
5  #depwalker  # set default variables
6  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/depwalker.sh,v 1.10 2008-03-26 15:58:25 niro Exp $  : ${MAGERC="@@SYSCONFDIR@@/mage.rc"}
7    : ${MLIBDIR="@@MAGELIBDIR@@"}
8    
9    # first of all include common functions
10    source ${MLIBDIR}/common.functions.sh || exit 1
11    source @@SYSCONFDIR@@/mage.rc.global || die "@@SYSCONFDIR@@/mage.rc.global missing"
12    source ${MAGERC} || die "Your ${MAGERC} is missing. Aborting."
13    source ${MLIBDIR}/mage4.functions.sh || die "mage functions missing"
14    source ${MLIBDIR}/smage2.functions.sh || die "smage functions missing"
15    
16  # default die function  decho()
 die()  
17  {  {
18   echo ${COLRED}"$@"${COLDEFAULT}   if [[ ${DEBUG} = 1 ]]
19   exit 1   then
20     echo "DEBUG: $@" >&2
21     fi
22  }  }
23    
 # include all needed files  
 [ -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"  
   
 # 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  
   
 # 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  
   
24  usage()  usage()
25  {  {
26   echo   echo
27   echo "Usage: $(basename $0) [command] [arg] ..."   echo "Usage: $(basename $0) [command] [arg] ..."
28   echo   echo
29   echo "  -h     --help          shows this help"   echo "  -h     --help          shows this help"
30   echo "  -c     --pcat          categorie of the package"   echo "  -c     --pcat          category of the package"
31   echo "  -n     --pname         name of the package"   echo "  -n     --pname         name of the package"
32   echo "  -v     --pver          version number of the package"   echo "  -v     --pver          version number of the package"
33   echo "  -b     --pbuild        build number of the package"   echo "  -b     --pbuild        build number of the package"
34   echo "  -m     --method        which calc method should be used:"   echo "  -m     --method        which calc method should be used:"
35   echo "                         install, srcinstall, depend, srcdepend"   echo "                         install, srcinstall, pretend, srcpretend"
36   echo "                         upgrade, srcupgrade"   echo "                         upgrade, srcupgrade,"
37     echo "                         install-build-prerequisites,"
38     echo "                         pretend-build-prerequisites"
39     echo "  -d     --debug         enable debug mode"
40     echo "  -s     --smage         use a smage to calculate dependencies"
41   echo   echo
42   echo "method, name, version and build must be given !"   echo "method, category, name, version and build must be given !"
43   echo   echo
44   exit 1   exit 1
45  }  }
46    
47    # always default debug=0
48    DEBUG=0
49    
50  # very basic getops  # very basic getops
51  for i in $*  for i in $*
52  do  do
# Line 71  do Line 56  do
56   --pver|-v) shift; PVER="$1" ;;   --pver|-v) shift; PVER="$1" ;;
57   --pbuild|-b) shift; PBUILD="$1" ;;   --pbuild|-b) shift; PBUILD="$1" ;;
58   --method|-m) shift; METHOD="$1" ;;   --method|-m) shift; METHOD="$1" ;;
59     --debug|-d) shift; DEBUG=1 ;;
60     --smage|-s) shift; SMAGEFILE="$1"; SILENT=1; FVERBOSE=off ;;
61   --help|-h) usage ;;   --help|-h) usage ;;
62   esac   esac
63   shift   shift
64  done  done
65    
66  # sanity checks; abort if not given  # sanity checks; abort if not given
67  [ -z "${PCAT}" ] && usage  if [[ -z ${SMAGEFILE} ]]
68  [ -z "${PNAME}" ] && usage  then
69  [ -z "${PVER}" ] && usage   [ -z "${PCAT}" ] && usage
70  [ -z "${PBUILD}" ] && usage   [ -z "${PNAME}" ] && usage
71     [ -z "${PVER}" ] && usage
72     [ -z "${PBUILD}" ] && usage
73    fi
74  [ -z "${METHOD}" ] && usage  [ -z "${METHOD}" ] && usage
75    
76  # check needed global vars  # check needed global vars
# Line 90  done Line 80  done
80    
81  # other needed vars  # other needed vars
82  ALLDEPS=""  ALLDEPS=""
83    if [[ -n ${SMAGEFILE} ]]
84    then
85     if [[ -e ${SMAGEFILE} ]]
86     then
87     smagesource "${SMAGEFILE}"
88     else
89     die "Smage file '${SMAGEFILE}' does not exist!"
90     fi
91    fi
92  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
93    
94  # much faster than fgrep  # much faster than fgrep
# Line 120  checklist_processeddeps() Line 119  checklist_processeddeps()
119  }  }
120    
121  #####################  #####################
122  ##  rumwandern /path/to/mage/file/.mage  ##  depwalking /path/to/mage/file/.mage
123  rumwandern()  depwalking()
124  {  {
125   unset DEPEND   unset DEPEND
126   unset SDEPEND   unset SDEPEND
# Line 142  rumwandern() Line 141  rumwandern()
141    
142   DFILE="$1"   DFILE="$1"
143    
144     # debug info
145     decho "depwalking magefile '${DFILE}'"
146     decho
147    
148   source ${DFILE}   source ${DFILE}
149    
150     # forced nodeps
151     if [[ ${NODEPS} = true ]]
152     then
153     DEPEND=""
154     SDEPEND=""
155     fi
156    
157   MY_DEPEND="${DEPEND}"   MY_DEPEND="${DEPEND}"
158    
159   # for srcinstall & srcdepend only; SDEPEND also needed   # for srcinstall & srcdepend only; SDEPEND also needed
160   if [[ ${METHOD} = srcinstall ]] || \   if [[ ${METHOD} = srcinstall ]] ||
161   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] ||
162   [[ ${METHOD} = srcupgrade ]] || \   [[ ${METHOD} = srcupgrade ]] ||
163   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] ||
164     [[ ${METHOD} = install-build-prerequisites ]] ||
165     [[ ${METHOD} = pretend-build-prerequisites ]]
166   then   then
167   # only if SDEPEND is not zero   # only if SDEPEND is not zero
168   if [ -n "${SDEPEND}" ]   if [ -n "${SDEPEND}" ]
# Line 170  rumwandern() Line 183  rumwandern()
183    
184   if [ -z "${MY_DEPEND}" ]   if [ -z "${MY_DEPEND}" ]
185   then   then
186     decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
187   return 1   return 1
188   fi   fi
189    
190   while read SYM DEPNAME   while read SYM DEPNAME
191   do   do
192     # debug info
193     decho "DEPNAME='${DEPNAME}'"
194    
195   # exclude empty depnames   # exclude empty depnames
196   [[ -z ${DEPNAME} ]] && continue   [[ -z ${DEPNAME} ]] && continue
197    
# Line 186  rumwandern() Line 203  rumwandern()
203    
204   # mark depfile as processed to prevent double runs -without version   # mark depfile as processed to prevent double runs -without version
205   # but do not add any virtuals to PROCESSEDDEPS or their resolved   # but do not add any virtuals to PROCESSEDDEPS or their resolved
206   # pkgnames will be ignored and they are missing on the dependecy-list   # pkgnames will be ignored and they are missing on the dependency-list
207   if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]   if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
208   then   then
209   PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"   PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
210   fi   fi
211    
212   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
213     if [[ -z ${HIGHEST_DEPFILE} ]]
214     then
215     INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
216     continue
217     fi
218    
219   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
220   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
221   PVER="$(magename2pver ${HIGHEST_DEPFILE})"   PVER="$(magename2pver ${HIGHEST_DEPFILE})"
222   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
223    
224   ## check ob schon in ALLDEPS enthalten dann mach weiter   ## dep already in ALLDEPS? then going on
225    
226   # 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
227   #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]   #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
228   if checklist_alldeps "${HIGHEST_DEPFILE}"   if checklist_alldeps "${HIGHEST_DEPFILE}"
229   then   then
230   ### check ob DFILE schon installiert ist ###   ### check if the dependency is already installed ###
231   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
232   then   then
233   rumwandern ${HIGHEST_DEPFILE}   # but first get all deps of highest_depfile to catch all dependencies of it
234     depwalking ${HIGHEST_DEPFILE}
235   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
236     decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
237   fi   fi
238   fi   fi
239   done << EOF   done << EOF
# Line 218  EOF Line 242  EOF
242   return 0   return 0
243  }  }
244    
   
 ### abort if this package is already installed (retval 3)  
 # maybe later ?  
 #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3  
   
245  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
246   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
247   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
248   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
249     [[ ${METHOD} = pretend-build-prerequisites ]] && \
250   echo -n "Calculating dependencies ... "   echo -n "Calculating dependencies ... "
251    
252    
# Line 244  then Line 264  then
264   # get the highest mage file from mage-db   # get the highest mage file from mage-db
265   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
266    
267     # debug info
268     decho "dep='${dep}'"
269     decho "PCAT='${PCAT}'"
270     decho "PNAME='${PNAME}'"
271     decho "MAGEFILE='${MAGEFILE}'"
272    
273   # if no install candidate was found, record this   # if no install candidate was found, record this
274   # and process with the next one   # and process with the next one
275   if [[ -z ${MAGEFILE} ]]   if [[ -z ${MAGEFILE} ]]
276   then   then
277   NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"   NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
278     decho "added to NO_UPGRADE_CANDIDATE"
279   continue   continue
280   fi   fi
281    
# Line 256  then Line 283  then
283   PVER="$(magename2pver ${MAGEFILE})"   PVER="$(magename2pver ${MAGEFILE})"
284   PBUILD="$(magename2pbuild ${MAGEFILE})"   PBUILD="$(magename2pbuild ${MAGEFILE})"
285    
286   # do not wander files which are installed   # debug info
287     decho "PVER='${PVER}'"
288     decho "PBUILD='${PBUILD}'"
289    
290     # do not walk files which are installed
291   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
292   then   then
293   # get dependencies the package   # get dependencies the package
294   rumwandern ${MAGEFILE}   depwalking ${MAGEFILE}
295    
296   # now add the package itself to the dependencies   # now add the package itself to the dependencies
297   # (if not exists already)   # (if not exists already)
  #if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ]  
298   if checklist_alldeps "${MAGEFILE}"   if checklist_alldeps "${MAGEFILE}"
299   then   then
300     decho "added '${MAGEFILE}' to ALLDEPS"
301   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   ALLDEPS="${ALLDEPS} ${MAGEFILE}"
302   fi   fi
303     else
304     # debug info
305     decho "ignored package"
306     decho
307   fi   fi
308   done   done
309  else  else
310   # get dependencies the package   # get all dependencies of the package
311   rumwandern ${MAGEFILE}   if [[ -n ${SMAGEFILE} ]]
312     then
313     depwalking "${SMAGEFILE}"
314     else
315     depwalking "${MAGEFILE}"
316     fi
317    fi
318    
319    if [[ ${METHOD} != install-build-prerequisites ]] &&
320     [[ ${METHOD} != pretend-build-prerequisites ]] &&
321     [[ ${METHOD} != upgrade ]] &&
322     [[ ${METHOD} != uppretend ]] &&
323     [[ ${METHOD} != srcupgrade ]] &&
324     [[ ${METHOD} != srcuppretend ]]
325    then
326   # now add the package itself to the dependencies   # now add the package itself to the dependencies
327   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   # (if not exists already)
328     if checklist_alldeps "${MAGEFILE}"
329     then
330     decho "added '${MAGEFILE}' to ALLDEPS"
331     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
332     fi
333  fi  fi
334    
335  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
336   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
337   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
338   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
339     [[ ${METHOD} = pretend-build-prerequisites ]] && \
340   echo "done"   echo "done"
341    
342    
# Line 290  fi Line 344  fi
344  if [[ ${METHOD} = pretend ]] || \  if [[ ${METHOD} = pretend ]] || \
345   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
346   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
347   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] || \
348     [[ ${METHOD} = pretend-build-prerequisites ]]
349  then  then
350   # this is a little bit faster   # this is a little bit faster
351   declare -i x=0   declare -i x=0
# Line 307  then Line 362  then
362   PBUILD="$(magename2pbuild ${i})"   PBUILD="$(magename2pbuild ${i})"
363   if [ -z "${list}" ]   if [ -z "${list}" ]
364   then   then
365   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
366   else   else
367   list="${list}   list="${list}
368  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
# Line 318  then Line 373  then
373   echo -e "${list}"   echo -e "${list}"
374   echo   echo
375    
376     if [[ ! -z ${INVALID_DEPS} ]]
377     then
378     echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}"
379     for i in ${INVALID_DEPS}
380     do
381     _dep="${i%%:*}"
382     _mage="${i##*:}"
383     echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}"
384     done
385     echo
386     fi
387    
388   if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]   if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
389   then   then
390   echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"   echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
# Line 328  then Line 395  then
395   echo   echo
396   echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"   echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"
397   echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"   echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"
398   echo -e "${COLRED}and there will be no further updates or support for them.${COLDEFAULT}"   echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
399   echo   echo
400   fi   fi
401  fi  fi
# Line 337  fi Line 404  fi
404  [[ ${METHOD} = install ]] || \  [[ ${METHOD} = install ]] || \
405   [[ ${METHOD} = srcinstall ]] || \   [[ ${METHOD} = srcinstall ]] || \
406   [[ ${METHOD} = upgrade ]] || \   [[ ${METHOD} = upgrade ]] || \
407   [[ ${METHOD} = srcupgrade ]] && \   [[ ${METHOD} = srcupgrade ]] || \
408     [[ ${METHOD} = install-build-prerequisites ]] && \
409   echo "${ALLDEPS}"   echo "${ALLDEPS}"
   
 # delete ${BUILDDIR}/virtuals if exists as not needed anymore  
 #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals  

Legend:
Removed from v.701  
changed lines
  Added in v.2829