Magellan Linux

Diff of /trunk/mage/usr/lib/mage/depwalker.sh

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

revision 598 by niro, Mon Nov 5 16:49:33 2007 UTC revision 2281 by niro, Wed Nov 20 12:21:28 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.6 2007-11-05 16:49:33 niro Exp $  
4    
5  # default die function  # default die function
6  die()  die()
# Line 22  die() Line 21  die()
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
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, depend, srcdepend"
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   echo
41   echo "method,name, version and build must be given !"   echo "method, category, name, version and build must be given !"
42   echo   echo
43   exit 1   exit 1
44  }  }
45    
46    # always default debug=0
47    DEBUG=0
48    
49  # very basic getops  # very basic getops
50  for i in $*  for i in $*
51  do  do
# Line 71  do Line 55  do
55   --pver|-v) shift; PVER="$1" ;;   --pver|-v) shift; PVER="$1" ;;
56   --pbuild|-b) shift; PBUILD="$1" ;;   --pbuild|-b) shift; PBUILD="$1" ;;
57   --method|-m) shift; METHOD="$1" ;;   --method|-m) shift; METHOD="$1" ;;
58     --debug|-d) shift; DEBUG=1 ;;
59   --help|-h) usage ;;   --help|-h) usage ;;
60   esac   esac
61   shift   shift
# Line 106  checklist_alldeps() Line 91  checklist_alldeps()
91   return 0   return 0
92  }  }
93    
94    checklist_processeddeps()
95    {
96     local i
97     local item="$1"
98    
99     for i in ${PROCESSEDDEPS}
100     do
101     [[ ${i} = ${item} ]] && return 1
102     done
103    
104     return 0
105    }
106    
107  #####################  #####################
108  ##  rumwandern /path/to/mage/file/.mage  ##  depwalking /path/to/mage/file/.mage
109  rumwandern()  depwalking()
110  {  {
111   unset DEPEND   unset DEPEND
112   unset SDEPEND   unset SDEPEND
# Line 129  rumwandern() Line 127  rumwandern()
127    
128   DFILE="$1"   DFILE="$1"
129    
130     if [[ ${DEBUG} = 1 ]]
131     then
132     echo "DEBUG: depwalking magefile '${DFILE}'" >&2
133     echo >&2
134     fi
135    
136   source ${DFILE}   source ${DFILE}
137    
138     # forced nodeps
139     if [[ ${NODEPS} = true ]]
140     then
141     DEPEND=""
142     SDEPEND=""
143     fi
144    
145   MY_DEPEND="${DEPEND}"   MY_DEPEND="${DEPEND}"
146    
147   # for srcinstall & srcdepend only; SDEPEND also needed   # for srcinstall & srcdepend only; SDEPEND also needed
# Line 152  rumwandern() Line 164  rumwandern()
164   fi   fi
165   fi   fi
166    
167     if [[ ${METHOD} = install-build-prerequisites ]] || \
168     [[ ${METHOD} = pretend-build-prerequisites ]]
169     then
170     # only one time
171     if [[ ${LOOP_COUNTER} -lt 1 ]]
172     then
173     # only if SDEPEND is not zero
174     if [ -n "${SDEPEND}" ]
175     then
176     # crlf is substantly needed !!
177     if [ -n "${MY_DEPEND}" ]
178     then
179     MY_DEPEND="${MY_DEPEND}
180     ${SDEPEND}"
181     else
182     MY_DEPEND="${SDEPEND}"
183     fi
184     fi
185     fi
186     LOOP_COUNTER=${LOOP_COUNTER}+1
187     fi
188    
189   unset DEPEND   unset DEPEND
190   unset SDEPEND   unset SDEPEND
191    
192   if [ -z "${MY_DEPEND}" ]   if [ -z "${MY_DEPEND}" ]
193   then   then
194     if [[ ${DEBUG} = 1 ]]
195     then
196     echo "DEBUG: MY_DEPEND is empty; deps of '${DFILE}' ignored" >&2
197     fi
198   return 1   return 1
199   fi   fi
200    
201   while read SYM DEPNAME   while read SYM DEPNAME
202   do   do
203     if [[ ${DEBUG} = 1 ]]
204     then
205     echo "DEBUG: DEPNAME='${DEPNAME}'" >&2
206     fi
207    
208     # exclude empty depnames
209     [[ -z ${DEPNAME} ]] && continue
210    
211     # exclude all already processed deps -without version
212     if ! checklist_processeddeps "${DEPNAME%-*}"
213     then
214     continue
215     fi
216    
217     # mark depfile as processed to prevent double runs -without version
218     # but do not add any virtuals to PROCESSEDDEPS or their resolved
219     # pkgnames will be ignored and they are missing on the dependecy-list
220     if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
221     then
222     PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
223     fi
224    
225   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
226     if [[ -z ${HIGHEST_DEPFILE} ]]
227     then
228     INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
229     continue
230     fi
231    
232   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
233   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
234   PVER="$(magename2pver ${HIGHEST_DEPFILE})"   PVER="$(magename2pver ${HIGHEST_DEPFILE})"
235   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
236    
237   ## check ob schon in ALLDEPS enthalten dann mach weiter   ## dep already in ALLDEPS? then going on
238    
239   # 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
240   #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]   #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
241   if checklist_alldeps "${HIGHEST_DEPFILE}"   if checklist_alldeps "${HIGHEST_DEPFILE}"
242   then   then
243   ### check ob DFILE schon installiert ist ###   ### check if the dependency is already installed ###
244   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
245   then   then
246   rumwandern ${HIGHEST_DEPFILE}   depwalking ${HIGHEST_DEPFILE}
247   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
248     if [[ ${DEBUG} = 1 ]]
249     then
250     echo "DEBUG: added '${HIGHEST_DEPFILE}' to ALLDEPS" >&2
251     fi
252   fi   fi
253   fi   fi
254   done << EOF   done << EOF
# Line 188  EOF Line 257  EOF
257   return 0   return 0
258  }  }
259    
   
 ### abort if this package is already installed (retval 3)  
 # maybe later ?  
 #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3  
   
260  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
261   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
262   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
263   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
264     [[ ${METHOD} = pretend-build-prerequisites ]] && \
265   echo -n "Calculating dependencies ... "   echo -n "Calculating dependencies ... "
266    
267    
# Line 214  then Line 279  then
279   # get the highest mage file from mage-db   # get the highest mage file from mage-db
280   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
281    
282     if [[ ${DEBUG} = 1 ]]
283     then
284     echo "DEBUG: dep='${dep}'" >&2
285     echo "DEBUG: PCAT='${PCAT}'" >&2
286     echo "DEBUG: PNAME='${PNAME}'" >&2
287     echo "DEBUG: MAGEFILE='${MAGEFILE}'" >&2
288     fi
289    
290     # if no install candidate was found, record this
291     # and process with the next one
292     if [[ -z ${MAGEFILE} ]]
293     then
294     NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
295     if [[ ${DEBUG} = 1 ]]
296     then
297     echo "DEBUG: added to NO_UPGRADE_CANDIDATE" >&2
298     fi
299     continue
300     fi
301    
302   # now get the pver&pbuild from the new file   # now get the pver&pbuild from the new file
303   PVER="$(magename2pver ${MAGEFILE})"   PVER="$(magename2pver ${MAGEFILE})"
304   PBUILD="$(magename2pbuild ${MAGEFILE})"   PBUILD="$(magename2pbuild ${MAGEFILE})"
305    
306   # do not wander files which are installed   if [[ ${DEBUG} = 1 ]]
307     then
308     echo "DEBUG: PVER='${PVER}'" >&2
309     echo "DEBUG: PBUILD='${PBUILD}'" >&2
310     fi
311    
312     # do not walk files which are installed
313   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
314   then   then
315   # get dependencies the package   # get dependencies the package
316   rumwandern ${MAGEFILE}   depwalking ${MAGEFILE}
317    
318   # now add the package itself to the dependencies   # now add the package itself to the dependencies
319   # (if not exists already)   # (if not exists already)
  #if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ]  
320   if checklist_alldeps "${MAGEFILE}"   if checklist_alldeps "${MAGEFILE}"
321   then   then
322     if [[ ${DEBUG} = 1 ]]
323     then
324     echo "DEBUG: added '${MAGEFILE}' to ALLDEPS" >&2
325     fi
326   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   ALLDEPS="${ALLDEPS} ${MAGEFILE}"
327   fi   fi
328     else
329     if [[ ${DEBUG} = 1 ]]
330     then
331     echo "DEBUG: ignored package" >&2
332     echo >&2
333     fi
334   fi   fi
335   done   done
336  else  else
337   # get dependencies the package   LOOP_COUNTER=0
338   rumwandern ${MAGEFILE}   # get all dependencies of the package
339     depwalking ${MAGEFILE}
340    fi
341    
342    if [[ ${METHOD} != install-build-prerequisites ]] &&
343     [[ ${METHOD} != pretend-build-prerequisites ]] &&
344     [[ ${METHOD} != upgrade ]] &&
345     [[ ${METHOD} != uppretend ]] &&
346     [[ ${METHOD} != srcupgrade ]] &&
347     [[ ${METHOD} != srcuppretend ]]
348    then
349   # now add the package itself to the dependencies   # now add the package itself to the dependencies
350   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   # (if not exists already)
351     if checklist_alldeps "${MAGEFILE}"
352     then
353     if [[ ${DEBUG} = 1 ]]
354     then
355     echo "DEBUG: added '${MAGEFILE}' to ALLDEPS" >&2
356     fi
357     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
358     fi
359  fi  fi
360    
361  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
362   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
363   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
364   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
365     [[ ${METHOD} = pretend-build-prerequisites ]] && \
366   echo "done"   echo "done"
367    
368    
# Line 252  fi Line 370  fi
370  if [[ ${METHOD} = pretend ]] || \  if [[ ${METHOD} = pretend ]] || \
371   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
372   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
373   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] || \
374     [[ ${METHOD} = pretend-build-prerequisites ]]
375  then  then
376   # this is a little bit faster   # this is a little bit faster
377   declare -i x=0   declare -i x=0
# Line 269  then Line 388  then
388   PBUILD="$(magename2pbuild ${i})"   PBUILD="$(magename2pbuild ${i})"
389   if [ -z "${list}" ]   if [ -z "${list}" ]
390   then   then
391   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
392   else   else
393   list="${list}   list="${list}
394  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
# Line 279  then Line 398  then
398   echo "done"   echo "done"
399   echo -e "${list}"   echo -e "${list}"
400   echo   echo
401    
402     if [[ ! -z ${INVALID_DEPS} ]]
403     then
404     echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}"
405     for i in ${INVALID_DEPS}
406     do
407     _dep="${i%%:*}"
408     _mage="${i##*:}"
409     echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}"
410     done
411     echo
412     fi
413    
414     if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
415     then
416     echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
417     for i in ${NO_UPGRADE_CANDIDATE}
418     do
419     echo -e "${COLRED}    ${i}${COLDEFAULT}"
420     done
421     echo
422     echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"
423     echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"
424     echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
425     echo
426     fi
427  fi  fi
428    
429  ## return output from src/install deps  ## return output from src/install deps
430  [[ ${METHOD} = install ]] || \  [[ ${METHOD} = install ]] || \
431   [[ ${METHOD} = srcinstall ]] || \   [[ ${METHOD} = srcinstall ]] || \
432   [[ ${METHOD} = upgrade ]] || \   [[ ${METHOD} = upgrade ]] || \
433   [[ ${METHOD} = srcupgrade ]] && \   [[ ${METHOD} = srcupgrade ]] || \
434     [[ ${METHOD} = install-build-prerequisites ]] && \
435   echo "${ALLDEPS}"   echo "${ALLDEPS}"
   
 # delete ${BUILDDIR}/virtuals if exists as not needed anymore  
 #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals  

Legend:
Removed from v.598  
changed lines
  Added in v.2281