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 226 by niro, Fri Sep 9 16:35:46 2005 UTC branches/mage-next/src/depwalker.in revision 2832 by niro, Fri Sep 19 11:19:35 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.1 2005-09-09 16:35:27 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 ${MLIBDIR}/conf/mage.rc.global ] &&  \  
 # source ${MLIBDIR}/conf/mage.rc.global || \  
 # die "${MLIBDIR}/conf/mage.rc.global missing"  
 #  
 # [ -f /etc/mage.rc ] && source /etc/mage.rc || \  
 # die "Your /etc/mage.rc is missing. Aborting."  
 #  
 # [ -f ${MLIBDIR}/mage.functions.sh ] && \  
 # source ${MLIBDIR}/mage.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  
   
 # not serios if missing, only 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,"
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    # set some sane defaults
48    DEBUG=0
49    SMAGE_DEPEND=0
50    
51  # very basic getops  # very basic getops
52  for i in $*  for i in $*
53  do  do
# Line 69  do Line 57  do
57   --pver|-v) shift; PVER="$1" ;;   --pver|-v) shift; PVER="$1" ;;
58   --pbuild|-b) shift; PBUILD="$1" ;;   --pbuild|-b) shift; PBUILD="$1" ;;
59   --method|-m) shift; METHOD="$1" ;;   --method|-m) shift; METHOD="$1" ;;
60     --debug|-d) shift; DEBUG=1 ;;
61     --smage|-s) shift; SMAGEFILE="$1"; SMAGE_DEPEND=1; SILENT=1; FVERBOSE=off ;;
62   --help|-h) usage ;;   --help|-h) usage ;;
63   esac   esac
64   shift   shift
65  done  done
66    
67  # sanity checks; abort if not given  # sanity checks; abort if not given
68  [ -z "${PCAT}" ] && usage  if [[ -z ${SMAGEFILE} ]]
69  [ -z "${PNAME}" ] && usage  then
70  [ -z "${PVER}" ] && usage   [ -z "${PCAT}" ] && usage
71  [ -z "${PBUILD}" ] && usage   [ -z "${PNAME}" ] && usage
72     [ -z "${PVER}" ] && usage
73     [ -z "${PBUILD}" ] && usage
74    fi
75  [ -z "${METHOD}" ] && usage  [ -z "${METHOD}" ] && usage
76    
77  # check needed global vars  # check needed global vars
# Line 88  done Line 81  done
81    
82  # other needed vars  # other needed vars
83  ALLDEPS=""  ALLDEPS=""
84    if [[ -n ${SMAGEFILE} ]]
85    then
86     if [[ -e ${SMAGEFILE} ]]
87     then
88     smagesource "${SMAGEFILE}"
89     else
90     die "Smage file '${SMAGEFILE}' does not exist!"
91     fi
92    fi
93  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
94    
95    # much faster than fgrep
96    checklist_alldeps()
97    {
98     local i
99     local item="$1"
100    
101     for i in ${ALLDEPS}
102     do
103     [[ ${i} = ${item} ]] && return 1
104     done
105    
106     return 0
107    }
108    
109    checklist_processeddeps()
110    {
111     local i
112     local item="$1"
113    
114     for i in ${PROCESSEDDEPS}
115     do
116     [[ ${i} = ${item} ]] && return 1
117     done
118    
119     return 0
120    }
121    
122  #####################  #####################
123  ##  rumwandern /path/to/mage/file/.mage  ##  depwalking /path/to/mage/file/.mage
124  rumwandern()  depwalking()
125  {  {
126   unset DEPEND   unset DEPEND
127   unset SDEPEND   unset SDEPEND
# Line 108  rumwandern() Line 137  rumwandern()
137   local INSTALL_VIRTUAL   local INSTALL_VIRTUAL
138   local PNAME   local PNAME
139   local PCAT   local PCAT
140     local PVER
141     local PBUILD
142    
143   DFILE="$1"   DFILE="$1"
144    
145     # debug info
146     decho "depwalking magefile '${DFILE}'"
147     decho
148    
149   source ${DFILE}   source ${DFILE}
150    
151     # forced nodeps
152     if [[ ${NODEPS} = true ]]
153     then
154     DEPEND=""
155     SDEPEND=""
156     fi
157    
158   MY_DEPEND="${DEPEND}"   MY_DEPEND="${DEPEND}"
159    
160   # for srcinstall & srcdepend only; SDEPEND also needed   # for srcinstall & srcdepend only; SDEPEND also needed
161   if [[ ${METHOD} = srcinstall ]] || [[ ${METHOD} = srcpretend ]]   if [[ ${METHOD} = srcinstall ]] ||
162     [[ ${METHOD} = srcpretend ]] ||
163     [[ ${METHOD} = srcupgrade ]] ||
164     [[ ${METHOD} = srcuppretend ]] ||
165     [[ ${METHOD} = install-build-prerequisites ]] ||
166     [[ ${METHOD} = pretend-build-prerequisites ]]
167   then   then
168   # only if SDEPEND is not zero   # only if SDEPEND is not zero
169   if [ -n "${SDEPEND}" ]   if [ -n "${SDEPEND}" ]
# Line 136  rumwandern() Line 184  rumwandern()
184    
185   if [ -z "${MY_DEPEND}" ]   if [ -z "${MY_DEPEND}" ]
186   then   then
187     decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
188   return 1   return 1
189   fi   fi
190    
191   while read SYM DEPNAME   while read SYM DEPNAME
192   do   do
193     # debug info
194     decho "DEPNAME='${DEPNAME}'"
195    
196     # exclude empty depnames
197     [[ -z ${DEPNAME} ]] && continue
198    
199     # exclude all already processed deps -without version
200     if ! checklist_processeddeps "${DEPNAME%-*}"
201     then
202     continue
203     fi
204    
205     # mark depfile as processed to prevent double runs -without version
206     # but do not add any virtuals to PROCESSEDDEPS or their resolved
207     # pkgnames will be ignored and they are missing on the dependency-list
208     if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
209     then
210     PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
211     fi
212    
213   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
214     if [[ -z ${HIGHEST_DEPFILE} ]]
215     then
216     INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
217     continue
218     fi
219    
220   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
221   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
222   PVER="$(magename2pver ${HIGHEST_DEPFILE})"   PVER="$(magename2pver ${HIGHEST_DEPFILE})"
223   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
224    
225   ## check ob schon in ALLDEPS enthalten dann mach weiter   ## dep already in ALLDEPS? then going on
226   if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]  
227     # usage of fgrep is extremly slow and consumes a lot of cpu power
228     #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
229     if checklist_alldeps "${HIGHEST_DEPFILE}"
230   then   then
231   ### check ob DFILE schon installiert ist ###   ### check if the dependency is already installed ###
232   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
233   then   then
234   rumwandern ${HIGHEST_DEPFILE}   # but first get all deps of highest_depfile to catch all dependencies of it
235     depwalking ${HIGHEST_DEPFILE}
236   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
237     decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
238   fi   fi
239   fi   fi
240   done << EOF   done << EOF
# Line 164  EOF Line 243  EOF
243   return 0   return 0
244  }  }
245    
246    [[ ${METHOD} = pretend ]] || \
247     [[ ${METHOD} = srcpretend ]] || \
248     [[ ${METHOD} = uppretend ]] || \
249     [[ ${METHOD} = srcuppretend ]] || \
250     [[ ${METHOD} = pretend-build-prerequisites ]] && \
251     echo -n "Calculating dependencies ... "
252    
 ### abort if this package is already installed (retval 3)  
 # maybe later ?  
 #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3  
253    
254  [[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]] && \  if [[ ${METHOD} = upgrade ]] || \
255   echo -n "Calculating dependencies ... "   [[ ${METHOD} = srcupgrade ]] || \
256     [[ ${METHOD} = uppretend ]] || \
257     [[ ${METHOD} = srcuppretend ]]
258    then
259     INSTDEPS="$(${MLIBDIR}/magequery.sh -i)"
260     for dep in ${INSTDEPS}
261     do
262     PCAT="$(magename2pcat ${dep} installdb)"
263     PNAME="$(magename2pname ${dep})"
264    
265  # get dependencies the package   # get the highest mage file from mage-db
266  rumwandern ${MAGEFILE}   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
267    
268  [[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]] && echo "done"   # debug info
269     decho "dep='${dep}'"
270     decho "PCAT='${PCAT}'"
271     decho "PNAME='${PNAME}'"
272     decho "MAGEFILE='${MAGEFILE}'"
273    
274     # if no install candidate was found, record this
275     # and process with the next one
276     if [[ -z ${MAGEFILE} ]]
277     then
278     NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
279     decho "added to NO_UPGRADE_CANDIDATE"
280     continue
281     fi
282    
283     # now get the pver&pbuild from the new file
284     PVER="$(magename2pver ${MAGEFILE})"
285     PBUILD="$(magename2pbuild ${MAGEFILE})"
286    
287     # debug info
288     decho "PVER='${PVER}'"
289     decho "PBUILD='${PBUILD}'"
290    
291     # do not walk files which are installed
292     if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
293     then
294     # get dependencies the package
295     depwalking ${MAGEFILE}
296    
297     # now add the package itself to the dependencies
298     # (if not exists already)
299     if checklist_alldeps "${MAGEFILE}"
300     then
301     decho "added '${MAGEFILE}' to ALLDEPS"
302     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
303     fi
304     else
305     # debug info
306     decho "ignored package"
307     decho
308     fi
309     done
310    else
311     # get all dependencies of the package
312     if [[ -n ${SMAGEFILE} ]]
313     then
314     depwalking "${SMAGEFILE}"
315     else
316     depwalking "${MAGEFILE}"
317     fi
318    fi
319    
320    if [[ ${METHOD} != install-build-prerequisites ]] &&
321     [[ ${METHOD} != pretend-build-prerequisites ]] &&
322     [[ ${METHOD} != upgrade ]] &&
323     [[ ${METHOD} != uppretend ]] &&
324     [[ ${METHOD} != srcupgrade ]] &&
325     [[ ${METHOD} != srcuppretend ]]
326    then
327     # now add the package itself to the dependencies
328     # (if not exists already)
329     if checklist_alldeps "${MAGEFILE}"
330     then
331     decho "added '${MAGEFILE}' to ALLDEPS"
332     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
333     fi
334    fi
335    
336    [[ ${METHOD} = pretend ]] || \
337     [[ ${METHOD} = srcpretend ]] || \
338     [[ ${METHOD} = uppretend ]] || \
339     [[ ${METHOD} = srcuppretend ]] || \
340     [[ ${METHOD} = pretend-build-prerequisites ]] && \
341     echo "done"
342    
 # now add the package itself to the dependencies  
 ALLDEPS="${ALLDEPS} ${MAGEFILE}"  
343    
344  ## show output of pretend  ## show output of pretend
345  if [[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]]  if [[ ${METHOD} = pretend ]] || \
346     [[ ${METHOD} = srcpretend ]] || \
347     [[ ${METHOD} = uppretend ]] || \
348     [[ ${METHOD} = srcuppretend ]] || \
349     [[ ${METHOD} = pretend-build-prerequisites ]]
350  then  then
351   # this is a little bit faster   # this is a little bit faster
352   declare -i x=0   declare -i x=0
# Line 199  then Line 363  then
363   PBUILD="$(magename2pbuild ${i})"   PBUILD="$(magename2pbuild ${i})"
364   if [ -z "${list}" ]   if [ -z "${list}" ]
365   then   then
366   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
367   else   else
368   list="${list}   list="${list}
369  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
# Line 209  then Line 373  then
373   echo "done"   echo "done"
374   echo -e "${list}"   echo -e "${list}"
375   echo   echo
376    
377     if [[ ! -z ${INVALID_DEPS} ]]
378     then
379     echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}"
380     for i in ${INVALID_DEPS}
381     do
382     _dep="${i%%:*}"
383     _mage="${i##*:}"
384     echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}"
385     done
386     echo
387     fi
388    
389     if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
390     then
391     echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
392     for i in ${NO_UPGRADE_CANDIDATE}
393     do
394     echo -e "${COLRED}    ${i}${COLDEFAULT}"
395     done
396     echo
397     echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"
398     echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"
399     echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
400     echo
401     fi
402  fi  fi
403    
404  ## return output from src/install deps  ## return output from src/install deps
405  [[ ${METHOD} = install ]] || [[ ${METHOD} = srcinstall ]] && echo "${ALLDEPS}"  [[ ${METHOD} = install ]] || \
406     [[ ${METHOD} = srcinstall ]] || \
407  # delete ${BUILDDIR}/virtuals if exists as not needed anymore   [[ ${METHOD} = upgrade ]] || \
408  #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals   [[ ${METHOD} = srcupgrade ]] || \
409     [[ ${METHOD} = install-build-prerequisites ]] && \
410     echo "${ALLDEPS}"

Legend:
Removed from v.226  
changed lines
  Added in v.2832