Magellan Linux

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

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

revision 226 by niro, Fri Sep 9 16:35:46 2005 UTC revision 2269 by niro, Fri Oct 25 06:55:11 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.1 2005-09-09 16:35:27 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  # # include all needed files  # include all needed files
13  # [ -f ${MLIBDIR}/conf/mage.rc.global ] &&  \  [ -f /etc/mage.rc.global ] &&  \
14  # source ${MLIBDIR}/conf/mage.rc.global || \   source /etc/mage.rc.global || \
15  # die "${MLIBDIR}/conf/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}/mage.functions.sh ] && \  [ -f ${MLIBDIR}/mage4.functions.sh ] && \
21  # source ${MLIBDIR}/mage.functions.sh || \   source ${MLIBDIR}/mage4.functions.sh || \
22  # die "mage functions missing"   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  
23    
24  usage()  usage()
25  {  {
# Line 53  usage() Line 32  usage()
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, depend, srcdepend"
36     echo "                         upgrade, srcupgrade,"
37     echo "                         install-build-prerequisites, pretend-build-prerequisites"
38     echo "  -d     --debug         enable debug mode"
39   echo   echo
40   echo "method,name, version and build must be given !"   echo "method, name, version and build must be given !"
41   echo   echo
42   exit 1   exit 1
43  }  }
44    
45    # always default debug=0
46    DEBUG=0
47    
48  # very basic getops  # very basic getops
49  for i in $*  for i in $*
50  do  do
# Line 69  do Line 54  do
54   --pver|-v) shift; PVER="$1" ;;   --pver|-v) shift; PVER="$1" ;;
55   --pbuild|-b) shift; PBUILD="$1" ;;   --pbuild|-b) shift; PBUILD="$1" ;;
56   --method|-m) shift; METHOD="$1" ;;   --method|-m) shift; METHOD="$1" ;;
57     --debug|-d) shift; DEBUG=1 ;;
58   --help|-h) usage ;;   --help|-h) usage ;;
59   esac   esac
60   shift   shift
# Line 90  done Line 76  done
76  ALLDEPS=""  ALLDEPS=""
77  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
78    
79    # much faster than fgrep
80    checklist_alldeps()
81    {
82     local i
83     local item="$1"
84    
85     for i in ${ALLDEPS}
86     do
87     [[ ${i} = ${item} ]] && return 1
88     done
89    
90     return 0
91    }
92    
93    checklist_processeddeps()
94    {
95     local i
96     local item="$1"
97    
98     for i in ${PROCESSEDDEPS}
99     do
100     [[ ${i} = ${item} ]] && return 1
101     done
102    
103     return 0
104    }
105    
106  #####################  #####################
107  ##  rumwandern /path/to/mage/file/.mage  ##  depwalking /path/to/mage/file/.mage
108  rumwandern()  depwalking()
109  {  {
110   unset DEPEND   unset DEPEND
111   unset SDEPEND   unset SDEPEND
# Line 108  rumwandern() Line 121  rumwandern()
121   local INSTALL_VIRTUAL   local INSTALL_VIRTUAL
122   local PNAME   local PNAME
123   local PCAT   local PCAT
124     local PVER
125     local PBUILD
126    
127   DFILE="$1"   DFILE="$1"
128    
129   source ${DFILE}   source ${DFILE}
130    
131     # forced nodeps
132     if [[ ${NODEPS} = true ]]
133     then
134     DEPEND=""
135     SDEPEND=""
136     fi
137    
138   MY_DEPEND="${DEPEND}"   MY_DEPEND="${DEPEND}"
139    
140   # for srcinstall & srcdepend only; SDEPEND also needed   # for srcinstall & srcdepend only; SDEPEND also needed
141   if [[ ${METHOD} = srcinstall ]] || [[ ${METHOD} = srcpretend ]]   if [[ ${METHOD} = srcinstall ]] || \
142     [[ ${METHOD} = srcpretend ]] || \
143     [[ ${METHOD} = srcupgrade ]] || \
144     [[ ${METHOD} = srcuppretend ]]
145   then   then
146   # only if SDEPEND is not zero   # only if SDEPEND is not zero
147   if [ -n "${SDEPEND}" ]   if [ -n "${SDEPEND}" ]
# Line 131  rumwandern() Line 157  rumwandern()
157   fi   fi
158   fi   fi
159    
160     if [[ ${METHOD} = install-build-prerequisites ]] || \
161     [[ ${METHOD} = pretend-build-prerequisites ]]
162     then
163     # only one time
164     if [[ ${LOOP_COUNTER} -lt 1 ]]
165     then
166     # only if SDEPEND is not zero
167     if [ -n "${SDEPEND}" ]
168     then
169     # crlf is substantly needed !!
170     if [ -n "${MY_DEPEND}" ]
171     then
172     MY_DEPEND="${MY_DEPEND}
173     ${SDEPEND}"
174     else
175     MY_DEPEND="${SDEPEND}"
176     fi
177     fi
178     fi
179     LOOP_COUNTER=${LOOP_COUNTER}+1
180     fi
181    
182   unset DEPEND   unset DEPEND
183   unset SDEPEND   unset SDEPEND
184    
# Line 141  rumwandern() Line 189  rumwandern()
189    
190   while read SYM DEPNAME   while read SYM DEPNAME
191   do   do
192     if [[ ${DEBUG} = 1 ]]
193     then
194     echo "DEBUG: DEPNAME='${DEPNAME}'" >&2
195     fi
196    
197     # exclude empty depnames
198     [[ -z ${DEPNAME} ]] && continue
199    
200     # exclude all already processed deps -without version
201     if ! checklist_processeddeps "${DEPNAME%-*}"
202     then
203     continue
204     fi
205    
206     # mark depfile as processed to prevent double runs -without version
207     # but do not add any virtuals to PROCESSEDDEPS or their resolved
208     # pkgnames will be ignored and they are missing on the dependecy-list
209     if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
210     then
211     PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
212     fi
213    
214   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
215     if [[ -z ${HIGHEST_DEPFILE} ]]
216     then
217     INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
218     continue
219     fi
220    
221   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
222   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
223   PVER="$(magename2pver ${HIGHEST_DEPFILE})"   PVER="$(magename2pver ${HIGHEST_DEPFILE})"
224   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
225    
226   ## check ob schon in ALLDEPS enthalten dann mach weiter   ## dep already in ALLDEPS? then going on
227   if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]  
228     # usage of fgrep is extremly slow and consumes a lot of cpu power
229     #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
230     if checklist_alldeps "${HIGHEST_DEPFILE}"
231   then   then
232   ### check ob DFILE schon installiert ist ###   ### check if the dependency is already installed ###
233   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
234   then   then
235   rumwandern ${HIGHEST_DEPFILE}   depwalking ${HIGHEST_DEPFILE}
236   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
237   fi   fi
238   fi   fi
# Line 164  EOF Line 242  EOF
242   return 0   return 0
243  }  }
244    
245    [[ ${METHOD} = pretend ]] || \
246     [[ ${METHOD} = srcpretend ]] || \
247     [[ ${METHOD} = uppretend ]] || \
248     [[ ${METHOD} = srcuppretend ]] || \
249     [[ ${METHOD} = pretend-build-prerequisites ]] && \
250     echo -n "Calculating dependencies ... "
251    
 ### abort if this package is already installed (retval 3)  
 # maybe later ?  
 #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3  
252    
253  [[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]] && \  if [[ ${METHOD} = upgrade ]] || \
254   echo -n "Calculating dependencies ... "   [[ ${METHOD} = srcupgrade ]] || \
255     [[ ${METHOD} = uppretend ]] || \
256     [[ ${METHOD} = srcuppretend ]]
257    then
258     INSTDEPS="$(${MLIBDIR}/magequery.sh -i)"
259     for dep in ${INSTDEPS}
260     do
261     PCAT="$(magename2pcat ${dep} installdb)"
262     PNAME="$(magename2pname ${dep})"
263    
264     # get the highest mage file from mage-db
265     MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
266    
267     # if no install candidate was found, record this
268     # and process with the next one
269     if [[ -z ${MAGEFILE} ]]
270     then
271     NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
272     continue
273     fi
274    
275  # get dependencies the package   # now get the pver&pbuild from the new file
276  rumwandern ${MAGEFILE}   PVER="$(magename2pver ${MAGEFILE})"
277     PBUILD="$(magename2pbuild ${MAGEFILE})"
278    
279  [[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]] && echo "done"   # do not walk files which are installed
280     if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
281     then
282     # get dependencies the package
283     depwalking ${MAGEFILE}
284     fi
285     done
286    else
287     LOOP_COUNTER=0
288     # get all dependencies of the package
289     depwalking ${MAGEFILE}
290    fi
291    
292    if [[ ${METHOD} != install-build-prerequisites ]] &&
293     [[ ${METHOD} != pretend-build-prerequisites ]]
294    then
295     # now add the package itself to the dependencies
296     # (if not exists already)
297     if checklist_alldeps "${MAGEFILE}"
298     then
299     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
300     fi
301    fi
302    
303    [[ ${METHOD} = pretend ]] || \
304     [[ ${METHOD} = srcpretend ]] || \
305     [[ ${METHOD} = uppretend ]] || \
306     [[ ${METHOD} = srcuppretend ]] || \
307     [[ ${METHOD} = pretend-build-prerequisites ]] && \
308     echo "done"
309    
 # now add the package itself to the dependencies  
 ALLDEPS="${ALLDEPS} ${MAGEFILE}"  
310    
311  ## show output of pretend  ## show output of pretend
312  if [[ ${METHOD} = pretend ]] || [[ ${METHOD} = srcpretend ]]  if [[ ${METHOD} = pretend ]] || \
313     [[ ${METHOD} = srcpretend ]] || \
314     [[ ${METHOD} = uppretend ]] || \
315     [[ ${METHOD} = srcuppretend ]] || \
316     [[ ${METHOD} = pretend-build-prerequisites ]]
317  then  then
318   # this is a little bit faster   # this is a little bit faster
319   declare -i x=0   declare -i x=0
# Line 199  then Line 330  then
330   PBUILD="$(magename2pbuild ${i})"   PBUILD="$(magename2pbuild ${i})"
331   if [ -z "${list}" ]   if [ -z "${list}" ]
332   then   then
333   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
334   else   else
335   list="${list}   list="${list}
336  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
# Line 209  then Line 340  then
340   echo "done"   echo "done"
341   echo -e "${list}"   echo -e "${list}"
342   echo   echo
343    
344     if [[ ! -z ${INVALID_DEPS} ]]
345     then
346     echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}"
347     for i in ${INVALID_DEPS}
348     do
349     _dep="${i%%:*}"
350     _mage="${i##*:}"
351     echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}"
352     done
353     echo
354     fi
355    
356     if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
357     then
358     echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
359     for i in ${NO_UPGRADE_CANDIDATE}
360     do
361     echo -e "${COLRED}    ${i}${COLDEFAULT}"
362     done
363     echo
364     echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"
365     echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"
366     echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
367     echo
368     fi
369  fi  fi
370    
371  ## return output from src/install deps  ## return output from src/install deps
372  [[ ${METHOD} = install ]] || [[ ${METHOD} = srcinstall ]] && echo "${ALLDEPS}"  [[ ${METHOD} = install ]] || \
373     [[ ${METHOD} = srcinstall ]] || \
374  # delete ${BUILDDIR}/virtuals if exists as not needed anymore   [[ ${METHOD} = upgrade ]] || \
375  #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals   [[ ${METHOD} = srcupgrade ]] || \
376     [[ ${METHOD} = install-build-prerequisites ]] && \
377     echo "${ALLDEPS}"

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