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 419 by niro, Mon Jan 22 00:24:14 2007 UTC branches/mage-next/src/depwalker.in revision 2839 by niro, Wed Oct 22 12:27:17 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.5 2007-01-22 00:24:14 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    # 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 71  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 79  done
79  [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set."  [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set."
80  [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set."  [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set."
81    
82    # load mage-features to support them with smagesource()
83    load_mage_features
84    
85  # other needed vars  # other needed vars
86  ALLDEPS=""  ALLDEPS=""
87    if [[ -n ${SMAGEFILE} ]]
88    then
89     if [[ -e ${SMAGEFILE} ]]
90     then
91     smagesource "${SMAGEFILE}"
92     else
93     die "Smage file '${SMAGEFILE}' does not exist!"
94     fi
95    fi
96  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
97    
98    # much faster than fgrep
99    checklist_alldeps()
100    {
101     local i
102     local item="$1"
103    
104     for i in ${ALLDEPS}
105     do
106     [[ ${i} = ${item} ]] && return 1
107     done
108    
109     return 0
110    }
111    
112    checklist_processeddeps()
113    {
114     local i
115     local item="$1"
116    
117     for i in ${PROCESSEDDEPS}
118     do
119     [[ ${i} = ${item} ]] && return 1
120     done
121    
122     return 0
123    }
124    
125  #####################  #####################
126  ##  rumwandern /path/to/mage/file/.mage  ##  depwalking /path/to/mage/file/.mage
127  rumwandern()  depwalking()
128  {  {
129   unset DEPEND   unset DEPEND
130   unset SDEPEND   unset SDEPEND
# Line 115  rumwandern() Line 145  rumwandern()
145    
146   DFILE="$1"   DFILE="$1"
147    
148     # debug info
149     decho "depwalking magefile '${DFILE}'"
150     decho
151    
152   source ${DFILE}   source ${DFILE}
153    
154     # forced nodeps
155     if [[ ${NODEPS} = true ]]
156     then
157     DEPEND=""
158     SDEPEND=""
159     fi
160    
161   MY_DEPEND="${DEPEND}"   MY_DEPEND="${DEPEND}"
162    
163   # for srcinstall & srcdepend only; SDEPEND also needed   # for srcinstall & srcdepend only; SDEPEND also needed
164   if [[ ${METHOD} = srcinstall ]] || \   if [[ ${METHOD} = srcinstall ]] ||
165   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] ||
166   [[ ${METHOD} = srcupgrade ]] || \   [[ ${METHOD} = srcupgrade ]] ||
167   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] ||
168     [[ ${METHOD} = install-build-prerequisites ]] ||
169     [[ ${METHOD} = pretend-build-prerequisites ]]
170   then   then
171   # only if SDEPEND is not zero   # only if SDEPEND is not zero
172   if [ -n "${SDEPEND}" ]   if [ -n "${SDEPEND}" ]
# Line 143  rumwandern() Line 187  rumwandern()
187    
188   if [ -z "${MY_DEPEND}" ]   if [ -z "${MY_DEPEND}" ]
189   then   then
190     decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
191   return 1   return 1
192   fi   fi
193    
194   while read SYM DEPNAME   while read SYM DEPNAME
195   do   do
196     # debug info
197     decho "DEPNAME='${DEPNAME}'"
198    
199     # exclude empty depnames
200     [[ -z ${DEPNAME} ]] && continue
201    
202     # exclude all already processed deps -without version
203     if ! checklist_processeddeps "${DEPNAME%-*}"
204     then
205     continue
206     fi
207    
208     # mark depfile as processed to prevent double runs -without version
209     # but do not add any virtuals to PROCESSEDDEPS or their resolved
210     # pkgnames will be ignored and they are missing on the dependency-list
211     if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
212     then
213     PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
214     fi
215    
216   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
217     if [[ -z ${HIGHEST_DEPFILE} ]]
218     then
219     INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
220     continue
221     fi
222    
223   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
224   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
225   PVER="$(magename2pver ${HIGHEST_DEPFILE})"   PVER="$(magename2pver ${HIGHEST_DEPFILE})"
226   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
227    
228   ## check ob schon in ALLDEPS enthalten dann mach weiter   ## dep already in ALLDEPS? then going on
229   if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]  
230     # usage of fgrep is extremly slow and consumes a lot of cpu power
231     #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
232     if checklist_alldeps "${HIGHEST_DEPFILE}"
233   then   then
234   ### check ob DFILE schon installiert ist ###   ### check if the dependency is already installed ###
235   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
236   then   then
237   rumwandern ${HIGHEST_DEPFILE}   # but first get all deps of highest_depfile to catch all dependencies of it
238     depwalking ${HIGHEST_DEPFILE}
239   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
240     decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
241   fi   fi
242   fi   fi
243   done << EOF   done << EOF
# Line 171  EOF Line 246  EOF
246   return 0   return 0
247  }  }
248    
   
 ### abort if this package is already installed (retval 3)  
 # maybe later ?  
 #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3  
   
249  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
250   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
251   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
252   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
253     [[ ${METHOD} = pretend-build-prerequisites ]] && \
254   echo -n "Calculating dependencies ... "   echo -n "Calculating dependencies ... "
255    
256    
# Line 197  then Line 268  then
268   # get the highest mage file from mage-db   # get the highest mage file from mage-db
269   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
270    
271     # debug info
272     decho "dep='${dep}'"
273     decho "PCAT='${PCAT}'"
274     decho "PNAME='${PNAME}'"
275     decho "MAGEFILE='${MAGEFILE}'"
276    
277     # if no install candidate was found, record this
278     # and process with the next one
279     if [[ -z ${MAGEFILE} ]]
280     then
281     NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
282     decho "added to NO_UPGRADE_CANDIDATE"
283     continue
284     fi
285    
286   # now get the pver&pbuild from the new file   # now get the pver&pbuild from the new file
287   PVER="$(magename2pver ${MAGEFILE})"   PVER="$(magename2pver ${MAGEFILE})"
288   PBUILD="$(magename2pbuild ${MAGEFILE})"   PBUILD="$(magename2pbuild ${MAGEFILE})"
289    
290   # do not wander files which are installed   # debug info
291     decho "PVER='${PVER}'"
292     decho "PBUILD='${PBUILD}'"
293    
294     # do not walk files which are installed
295   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
296   then   then
297   # get dependencies the package   # get dependencies the package
298   rumwandern ${MAGEFILE}   depwalking ${MAGEFILE}
299    
300   # now add the package itself to the dependencies   # now add the package itself to the dependencies
301   # (if not exists already)   # (if not exists already)
302   if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ]   if checklist_alldeps "${MAGEFILE}"
303   then   then
304     decho "added '${MAGEFILE}' to ALLDEPS"
305   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   ALLDEPS="${ALLDEPS} ${MAGEFILE}"
306   fi   fi
307     else
308     # debug info
309     decho "ignored package"
310     decho
311   fi   fi
312   done   done
313  else  else
314   # get dependencies the package   # get all dependencies of the package
315   rumwandern ${MAGEFILE}   if [[ -n ${SMAGEFILE} ]]
316     then
317     depwalking "${SMAGEFILE}"
318     else
319     depwalking "${MAGEFILE}"
320     fi
321    fi
322    
323    if [[ ${METHOD} != install-build-prerequisites ]] &&
324     [[ ${METHOD} != pretend-build-prerequisites ]] &&
325     [[ ${METHOD} != upgrade ]] &&
326     [[ ${METHOD} != uppretend ]] &&
327     [[ ${METHOD} != srcupgrade ]] &&
328     [[ ${METHOD} != srcuppretend ]]
329    then
330   # now add the package itself to the dependencies   # now add the package itself to the dependencies
331   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   # (if not exists already)
332     if checklist_alldeps "${MAGEFILE}"
333     then
334     decho "added '${MAGEFILE}' to ALLDEPS"
335     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
336     fi
337  fi  fi
338    
339  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
340   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
341   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
342   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
343     [[ ${METHOD} = pretend-build-prerequisites ]] && \
344   echo "done"   echo "done"
345    
346    
# Line 234  fi Line 348  fi
348  if [[ ${METHOD} = pretend ]] || \  if [[ ${METHOD} = pretend ]] || \
349   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
350   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
351   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] || \
352     [[ ${METHOD} = pretend-build-prerequisites ]]
353  then  then
354   # this is a little bit faster   # this is a little bit faster
355   declare -i x=0   declare -i x=0
# Line 251  then Line 366  then
366   PBUILD="$(magename2pbuild ${i})"   PBUILD="$(magename2pbuild ${i})"
367   if [ -z "${list}" ]   if [ -z "${list}" ]
368   then   then
369   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
370   else   else
371   list="${list}   list="${list}
372  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
# Line 261  then Line 376  then
376   echo "done"   echo "done"
377   echo -e "${list}"   echo -e "${list}"
378   echo   echo
379    
380     if [[ ! -z ${INVALID_DEPS} ]]
381     then
382     echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}"
383     for i in ${INVALID_DEPS}
384     do
385     _dep="${i%%:*}"
386     _mage="${i##*:}"
387     echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}"
388     done
389     echo
390     fi
391    
392     if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
393     then
394     echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
395     for i in ${NO_UPGRADE_CANDIDATE}
396     do
397     echo -e "${COLRED}    ${i}${COLDEFAULT}"
398     done
399     echo
400     echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"
401     echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"
402     echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
403     echo
404     fi
405  fi  fi
406    
407  ## return output from src/install deps  ## return output from src/install deps
408  [[ ${METHOD} = install ]] || \  [[ ${METHOD} = install ]] || \
409   [[ ${METHOD} = srcinstall ]] || \   [[ ${METHOD} = srcinstall ]] || \
410   [[ ${METHOD} = upgrade ]] || \   [[ ${METHOD} = upgrade ]] || \
411   [[ ${METHOD} = srcupgrade ]] && \   [[ ${METHOD} = srcupgrade ]] || \
412     [[ ${METHOD} = install-build-prerequisites ]] && \
413   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.2839