Magellan Linux

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

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

revision 235 by niro, Sat Sep 10 13:34:56 2005 UTC revision 2220 by niro, Wed Oct 16 06:52:01 2013 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2    # $Id$
3  #depwalker  # dependeny walker
 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/depwalker.sh,v 1.3 2005-09-10 13:34:56 niro Exp $  
4    
5  # default die function  # default die function
6  die()  die()
# Line 15  die() Line 14  die()
14   source /etc/mage.rc.global || \   source /etc/mage.rc.global || \
15   die "/etc/mage.rc.global missing"   die "/etc/mage.rc.global missing"
16    
17  [ -f /etc/mage.rc ] && source /etc/mage.rc || \  [ -f ${MAGERC} ] && source ${MAGERC} || \
18   die "Your /etc/mage.rc is missing. Aborting."   die "Your ${MAGERC} is missing. Aborting."
19    
20  [ -f ${MLIBDIR}/mage4.functions.sh ] && \  [ -f ${MLIBDIR}/mage4.functions.sh ] && \
21   source ${MLIBDIR}/mage4.functions.sh || \   source ${MLIBDIR}/mage4.functions.sh || \
22   die "mage functions missing"   die "mage functions missing"
23    
 # 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
# Line 55  usage() Line 33  usage()
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, depend, srcdepend"
36   echo "                         upgrade, srcupgrade"   echo "                         upgrade, srcupgrade,"
37     echo "                         install-build-prerequisites, pretend-build-prerequisites"
38   echo   echo
39   echo "method,name, version and build must be given !"   echo "method, name, version and build must be given !"
40   echo   echo
41   exit 1   exit 1
42  }  }
# Line 92  done Line 71  done
71  ALLDEPS=""  ALLDEPS=""
72  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
73    
74    # much faster than fgrep
75    checklist_alldeps()
76    {
77     local i
78     local item="$1"
79    
80     for i in ${ALLDEPS}
81     do
82     [[ ${i} = ${item} ]] && return 1
83     done
84    
85     return 0
86    }
87    
88    checklist_processeddeps()
89    {
90     local i
91     local item="$1"
92    
93     for i in ${PROCESSEDDEPS}
94     do
95     [[ ${i} = ${item} ]] && return 1
96     done
97    
98     return 0
99    }
100    
101  #####################  #####################
102  ##  rumwandern /path/to/mage/file/.mage  ##  depwalking /path/to/mage/file/.mage
103  rumwandern()  depwalking()
104  {  {
105   unset DEPEND   unset DEPEND
106   unset SDEPEND   unset SDEPEND
# Line 110  rumwandern() Line 116  rumwandern()
116   local INSTALL_VIRTUAL   local INSTALL_VIRTUAL
117   local PNAME   local PNAME
118   local PCAT   local PCAT
119     local PVER
120     local PBUILD
121    
122   DFILE="$1"   DFILE="$1"
123    
124   source ${DFILE}   source ${DFILE}
125    
126     # forced nodeps
127     if [[ ${NODEPS} = true ]]
128     then
129     DEPEND=""
130     SDEPEND=""
131     fi
132    
133   MY_DEPEND="${DEPEND}"   MY_DEPEND="${DEPEND}"
134    
135   # for srcinstall & srcdepend only; SDEPEND also needed   # for srcinstall & srcdepend only; SDEPEND also needed
# Line 136  rumwandern() Line 152  rumwandern()
152   fi   fi
153   fi   fi
154    
155     if [[ ${METHOD} = install-build-prerequisites ]] || \
156     [[ ${METHOD} = pretend-build-prerequisites ]]
157     then
158     # only one time
159     if [[ ${LOOP_COUNTER} -lt 1 ]]
160     then
161     # only if SDEPEND is not zero
162     if [ -n "${SDEPEND}" ]
163     then
164     # crlf is substantly needed !!
165     if [ -n "${MY_DEPEND}" ]
166     then
167     MY_DEPEND="${MY_DEPEND}
168     ${SDEPEND}"
169     else
170     MY_DEPEND="${SDEPEND}"
171     fi
172     fi
173     fi
174     LOOP_COUNTER=${LOOP_COUNTER}+1
175     fi
176    
177   unset DEPEND   unset DEPEND
178   unset SDEPEND   unset SDEPEND
179    
# Line 146  rumwandern() Line 184  rumwandern()
184    
185   while read SYM DEPNAME   while read SYM DEPNAME
186   do   do
187     # exclude empty depnames
188     [[ -z ${DEPNAME} ]] && continue
189    
190     # exclude all already processed deps -without version
191     if ! checklist_processeddeps "${DEPNAME%-*}"
192     then
193     continue
194     fi
195    
196     # mark depfile as processed to prevent double runs -without version
197     # but do not add any virtuals to PROCESSEDDEPS or their resolved
198     # pkgnames will be ignored and they are missing on the dependecy-list
199     if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
200     then
201     PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
202     fi
203    
204   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
205     if [[ -z ${HIGHEST_DEPFILE} ]]
206     then
207     INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
208     continue
209     fi
210    
211   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
212   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
213   PVER="$(magename2pver ${HIGHEST_DEPFILE})"   PVER="$(magename2pver ${HIGHEST_DEPFILE})"
214   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
215    
216   ## check ob schon in ALLDEPS enthalten dann mach weiter   ## dep already in ALLDEPS? then going on
217   if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]  
218     # usage of fgrep is extremly slow and consumes a lot of cpu power
219     #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
220     if checklist_alldeps "${HIGHEST_DEPFILE}"
221   then   then
222   ### check ob DFILE schon installiert ist ###   ### check if the dependency is already installed ###
223   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
224   then   then
225   rumwandern ${HIGHEST_DEPFILE}   depwalking ${HIGHEST_DEPFILE}
226   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
227   fi   fi
228   fi   fi
# Line 169  EOF Line 232  EOF
232   return 0   return 0
233  }  }
234    
   
 ### abort if this package is already installed (retval 3)  
 # maybe later ?  
 #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3  
   
235  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
236   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
237   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
238   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
239     [[ ${METHOD} = pretend-build-prerequisites ]] && \
240   echo -n "Calculating dependencies ... "   echo -n "Calculating dependencies ... "
241    
242    
# Line 191  then Line 250  then
250   do   do
251   PCAT="$(magename2pcat ${dep} installdb)"   PCAT="$(magename2pcat ${dep} installdb)"
252   PNAME="$(magename2pname ${dep})"   PNAME="$(magename2pname ${dep})"
  PVER="$(magename2pver ${dep})"  
  PBUILD="$(magename2pbuild ${dep})"  
253    
254   # fake a mage file   # get the highest mage file from mage-db
255   MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
256    
257     # if no install candidate was found, record this
258     # and process with the next one
259     if [[ -z ${MAGEFILE} ]]
260     then
261     NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
262     continue
263     fi
264    
265     # now get the pver&pbuild from the new file
266     PVER="$(magename2pver ${MAGEFILE})"
267     PBUILD="$(magename2pbuild ${MAGEFILE})"
268    
269   rumwandern ${MAGEFILE}   # do not walk files which are installed
270     if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
271     then
272     # get dependencies the package
273     depwalking ${MAGEFILE}
274     fi
275   done   done
276  else  else
277   # get dependencies the package   LOOP_COUNTER=0
278   rumwandern ${MAGEFILE}   # get all dependencies of the package
279     depwalking ${MAGEFILE}
280    fi
281    
282    if [[ ${METHOD} != install-build-prerequisites ]] &&
283     [[ ${METHOD} != pretend-build-prerequisites ]]
284    then
285   # now add the package itself to the dependencies   # now add the package itself to the dependencies
286   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   # (if not exists already)
287     if checklist_alldeps "${MAGEFILE}"
288     then
289     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
290     fi
291  fi  fi
292    
293  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
294   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
295   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
296   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
297     [[ ${METHOD} = pretend-build-prerequisites ]] && \
298   echo "done"   echo "done"
299    
300    
# Line 218  fi Line 302  fi
302  if [[ ${METHOD} = pretend ]] || \  if [[ ${METHOD} = pretend ]] || \
303   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
304   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
305   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] || \
306     [[ ${METHOD} = pretend-build-prerequisites ]]
307  then  then
308   # this is a little bit faster   # this is a little bit faster
309   declare -i x=0   declare -i x=0
# Line 235  then Line 320  then
320   PBUILD="$(magename2pbuild ${i})"   PBUILD="$(magename2pbuild ${i})"
321   if [ -z "${list}" ]   if [ -z "${list}" ]
322   then   then
323   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
324   else   else
325   list="${list}   list="${list}
326  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
# Line 245  then Line 330  then
330   echo "done"   echo "done"
331   echo -e "${list}"   echo -e "${list}"
332   echo   echo
333    
334     if [[ ! -z ${INVALID_DEPS} ]]
335     then
336     echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}"
337     for i in ${INVALID_DEPS}
338     do
339     _dep="${i%%:*}"
340     _mage="${i##*:}"
341     echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}"
342     done
343     echo
344     fi
345    
346     if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
347     then
348     echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
349     for i in ${NO_UPGRADE_CANDIDATE}
350     do
351     echo -e "${COLRED}    ${i}${COLDEFAULT}"
352     done
353     echo
354     echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"
355     echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"
356     echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
357     echo
358     fi
359  fi  fi
360    
361  ## return output from src/install deps  ## return output from src/install deps
362  [[ ${METHOD} = install ]] || \  [[ ${METHOD} = install ]] || \
363   [[ ${METHOD} = srcinstall ]] || \   [[ ${METHOD} = srcinstall ]] || \
364   [[ ${METHOD} = upgrade ]] || \   [[ ${METHOD} = upgrade ]] || \
365   [[ ${METHOD} = srcupgrade ]] && \   [[ ${METHOD} = srcupgrade ]] || \
366     [[ ${METHOD} = install-build-prerequisites ]] && \
367   echo "${ALLDEPS}"   echo "${ALLDEPS}"
   
 # delete ${BUILDDIR}/virtuals if exists as not needed anymore  
 #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals  

Legend:
Removed from v.235  
changed lines
  Added in v.2220