Magellan Linux

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

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

revision 231 by niro, Fri Sep 9 17:50:03 2005 UTC revision 2360 by niro, Mon Jan 6 12:36:37 2014 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.2 2005-09-09 17:50:03 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    decho()
13    {
14     if [[ ${DEBUG} = 1 ]]
15     then
16     echo "DEBUG: $@" >&2
17     fi
18    }
19    
20  # include all needed files  # include all needed files
21  [ -f ${MLIBDIR}/conf/mage.rc.global ] &&  \  [ -f /etc/mage.rc.global ] &&  \
22   source ${MLIBDIR}/conf/mage.rc.global || \   source /etc/mage.rc.global || \
23   die "${MLIBDIR}/conf/mage.rc.global missing"   die "/etc/mage.rc.global missing"
24    
25  [ -f /etc/mage.rc ] && source /etc/mage.rc || \  [ -f ${MAGERC} ] && source ${MAGERC} || \
26   die "Your /etc/mage.rc is missing. Aborting."   die "Your ${MAGERC} is missing. Aborting."
27    
28  [ -f ${MLIBDIR}/mage.functions.sh ] && \  [ -f ${MLIBDIR}/mage4.functions.sh ] && \
29   source ${MLIBDIR}/mage.functions.sh || \   source ${MLIBDIR}/mage4.functions.sh || \
30   die "mage functions missing"   die "mage functions missing"
31    
32  # for tests only  [ -f ${MLIBDIR}/smage2.functions.sh ] && \
33  # source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage.rc.global   source ${MLIBDIR}/smage2.functions.sh || \
34  # source /etc/mage.rc   die "smage functions missing"
 # 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  
35    
36  usage()  usage()
37  {  {
# Line 49  usage() Line 39  usage()
39   echo "Usage: $(basename $0) [command] [arg] ..."   echo "Usage: $(basename $0) [command] [arg] ..."
40   echo   echo
41   echo "  -h     --help          shows this help"   echo "  -h     --help          shows this help"
42   echo "  -c     --pcat          categorie of the package"   echo "  -c     --pcat          category of the package"
43   echo "  -n     --pname         name of the package"   echo "  -n     --pname         name of the package"
44   echo "  -v     --pver          version number of the package"   echo "  -v     --pver          version number of the package"
45   echo "  -b     --pbuild        build number of the package"   echo "  -b     --pbuild        build number of the package"
46   echo "  -m     --method        which calc method should be used:"   echo "  -m     --method        which calc method should be used:"
47   echo "                         install, srcinstall, depend, srcdepend"   echo "                         install, srcinstall, pretend, srcpretend"
48   echo "                         upgrade, srcupgrade"   echo "                         upgrade, srcupgrade,"
49     echo "                         install-build-prerequisites,"
50     echo "                         pretend-build-prerequisites"
51     echo "  -d     --debug         enable debug mode"
52     echo "  -s     --smage         use a smage to calculate dependencies"
53   echo   echo
54   echo "method,name, version and build must be given !"   echo "method, category, name, version and build must be given !"
55   echo   echo
56   exit 1   exit 1
57  }  }
58    
59    # always default debug=0
60    DEBUG=0
61    
62  # very basic getops  # very basic getops
63  for i in $*  for i in $*
64  do  do
# Line 71  do Line 68  do
68   --pver|-v) shift; PVER="$1" ;;   --pver|-v) shift; PVER="$1" ;;
69   --pbuild|-b) shift; PBUILD="$1" ;;   --pbuild|-b) shift; PBUILD="$1" ;;
70   --method|-m) shift; METHOD="$1" ;;   --method|-m) shift; METHOD="$1" ;;
71     --debug|-d) shift; DEBUG=1 ;;
72     --smage|-s) shift; SMAGEFILE="$1"; SILENT=1; FVERBOSE=off ;;
73   --help|-h) usage ;;   --help|-h) usage ;;
74   esac   esac
75   shift   shift
76  done  done
77    
78  # sanity checks; abort if not given  # sanity checks; abort if not given
79  [ -z "${PCAT}" ] && usage  if [[ -z ${SMAGEFILE} ]]
80  [ -z "${PNAME}" ] && usage  then
81  [ -z "${PVER}" ] && usage   [ -z "${PCAT}" ] && usage
82  [ -z "${PBUILD}" ] && usage   [ -z "${PNAME}" ] && usage
83     [ -z "${PVER}" ] && usage
84     [ -z "${PBUILD}" ] && usage
85    fi
86  [ -z "${METHOD}" ] && usage  [ -z "${METHOD}" ] && usage
87    
88  # check needed global vars  # check needed global vars
# Line 90  done Line 92  done
92    
93  # other needed vars  # other needed vars
94  ALLDEPS=""  ALLDEPS=""
95    if [[ -n ${SMAGEFILE} ]]
96    then
97     if [[ -e ${SMAGEFILE} ]]
98     then
99     smagesource "${SMAGEFILE}"
100     else
101     die "Smage file '${SMAGEFILE}' does not exist!"
102     fi
103    fi
104  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
105    
106    # much faster than fgrep
107    checklist_alldeps()
108    {
109     local i
110     local item="$1"
111    
112     for i in ${ALLDEPS}
113     do
114     [[ ${i} = ${item} ]] && return 1
115     done
116    
117     return 0
118    }
119    
120    checklist_processeddeps()
121    {
122     local i
123     local item="$1"
124    
125     for i in ${PROCESSEDDEPS}
126     do
127     [[ ${i} = ${item} ]] && return 1
128     done
129    
130     return 0
131    }
132    
133  #####################  #####################
134  ##  rumwandern /path/to/mage/file/.mage  ##  depwalking /path/to/mage/file/.mage
135  rumwandern()  depwalking()
136  {  {
137   unset DEPEND   unset DEPEND
138   unset SDEPEND   unset SDEPEND
# Line 110  rumwandern() Line 148  rumwandern()
148   local INSTALL_VIRTUAL   local INSTALL_VIRTUAL
149   local PNAME   local PNAME
150   local PCAT   local PCAT
151     local PVER
152     local PBUILD
153    
154   DFILE="$1"   DFILE="$1"
155    
156     # debug info
157     decho "depwalking magefile '${DFILE}'"
158     decho
159    
160   source ${DFILE}   source ${DFILE}
161    
162     # forced nodeps
163     if [[ ${NODEPS} = true ]]
164     then
165     DEPEND=""
166     SDEPEND=""
167     fi
168    
169   MY_DEPEND="${DEPEND}"   MY_DEPEND="${DEPEND}"
170    
171   # for srcinstall & srcdepend only; SDEPEND also needed   # for srcinstall & srcdepend only; SDEPEND also needed
172   if [[ ${METHOD} = srcinstall ]] || \   if [[ ${METHOD} = srcinstall ]] ||
173   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] ||
174   [[ ${METHOD} = srcupgrade ]] || \   [[ ${METHOD} = srcupgrade ]] ||
175   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] ||
176     [[ ${METHOD} = install-build-prerequisites ]] ||
177     [[ ${METHOD} = pretend-build-prerequisites ]]
178   then   then
179   # only if SDEPEND is not zero   # only if SDEPEND is not zero
180   if [ -n "${SDEPEND}" ]   if [ -n "${SDEPEND}" ]
# Line 141  rumwandern() Line 195  rumwandern()
195    
196   if [ -z "${MY_DEPEND}" ]   if [ -z "${MY_DEPEND}" ]
197   then   then
198     decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
199   return 1   return 1
200   fi   fi
201    
202   while read SYM DEPNAME   while read SYM DEPNAME
203   do   do
204     # debug info
205     decho "DEPNAME='${DEPNAME}'"
206    
207     # exclude empty depnames
208     [[ -z ${DEPNAME} ]] && continue
209    
210     # exclude all already processed deps -without version
211     if ! checklist_processeddeps "${DEPNAME%-*}"
212     then
213     continue
214     fi
215    
216     # mark depfile as processed to prevent double runs -without version
217     # but do not add any virtuals to PROCESSEDDEPS or their resolved
218     # pkgnames will be ignored and they are missing on the dependecy-list
219     if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
220     then
221     PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
222     fi
223    
224   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
225     if [[ -z ${HIGHEST_DEPFILE} ]]
226     then
227     INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
228     continue
229     fi
230    
231   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
232   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
233   PVER="$(magename2pver ${HIGHEST_DEPFILE})"   PVER="$(magename2pver ${HIGHEST_DEPFILE})"
234   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
235    
236   ## check ob schon in ALLDEPS enthalten dann mach weiter   ## dep already in ALLDEPS? then going on
237   if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]  
238     # usage of fgrep is extremly slow and consumes a lot of cpu power
239     #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
240     if checklist_alldeps "${HIGHEST_DEPFILE}"
241   then   then
242   ### check ob DFILE schon installiert ist ###   ### check if the dependency is already installed ###
243   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
244   then   then
245   rumwandern ${HIGHEST_DEPFILE}   depwalking ${HIGHEST_DEPFILE}
246   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
247     decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
248   fi   fi
249   fi   fi
250   done << EOF   done << EOF
# Line 169  EOF Line 253  EOF
253   return 0   return 0
254  }  }
255    
   
 ### abort if this package is already installed (retval 3)  
 # maybe later ?  
 #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3  
   
256  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
257   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
258   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
259   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
260     [[ ${METHOD} = pretend-build-prerequisites ]] && \
261   echo -n "Calculating dependencies ... "   echo -n "Calculating dependencies ... "
262    
263    
# Line 191  then Line 271  then
271   do   do
272   PCAT="$(magename2pcat ${dep} installdb)"   PCAT="$(magename2pcat ${dep} installdb)"
273   PNAME="$(magename2pname ${dep})"   PNAME="$(magename2pname ${dep})"
  PVER="$(magename2pver ${dep})"  
  PBUILD="$(magename2pbuild ${dep})"  
274    
275   # fake a mage file   # get the highest mage file from mage-db
276   MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
277    
278     # debug info
279     decho "dep='${dep}'"
280     decho "PCAT='${PCAT}'"
281     decho "PNAME='${PNAME}'"
282     decho "MAGEFILE='${MAGEFILE}'"
283    
284     # if no install candidate was found, record this
285     # and process with the next one
286     if [[ -z ${MAGEFILE} ]]
287     then
288     NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
289     decho "added to NO_UPGRADE_CANDIDATE"
290     continue
291     fi
292    
293     # now get the pver&pbuild from the new file
294     PVER="$(magename2pver ${MAGEFILE})"
295     PBUILD="$(magename2pbuild ${MAGEFILE})"
296    
297     # debug info
298     decho "PVER='${PVER}'"
299     decho "PBUILD='${PBUILD}'"
300    
301   rumwandern ${MAGEFILE}   # do not walk files which are installed
302     if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
303     then
304     # get dependencies the package
305     depwalking ${MAGEFILE}
306    
307     # now add the package itself to the dependencies
308     # (if not exists already)
309     if checklist_alldeps "${MAGEFILE}"
310     then
311     decho "added '${MAGEFILE}' to ALLDEPS"
312     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
313     fi
314     else
315     # debug info
316     decho "ignored package"
317     decho
318     fi
319     fi
320   done   done
321  else  else
322   # get dependencies the package   # get all dependencies of the package
323   rumwandern ${MAGEFILE}   if [[ -n ${SMAGEFILE} ]]
324     then
325     depwalking "${SMAGEFILE}"
326     else
327     depwalking "${MAGEFILE}"
328     fi
329    fi
330    
331    if [[ ${METHOD} != install-build-prerequisites ]] &&
332     [[ ${METHOD} != pretend-build-prerequisites ]] &&
333     [[ ${METHOD} != upgrade ]] &&
334     [[ ${METHOD} != uppretend ]] &&
335     [[ ${METHOD} != srcupgrade ]] &&
336     [[ ${METHOD} != srcuppretend ]]
337    then
338   # now add the package itself to the dependencies   # now add the package itself to the dependencies
339   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   # (if not exists already)
340     if checklist_alldeps "${MAGEFILE}"
341     then
342     decho "added '${MAGEFILE}' to ALLDEPS"
343     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
344     fi
345  fi  fi
346    
347  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
348   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
349   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
350   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
351     [[ ${METHOD} = pretend-build-prerequisites ]] && \
352   echo "done"   echo "done"
353    
354    
# Line 218  fi Line 356  fi
356  if [[ ${METHOD} = pretend ]] || \  if [[ ${METHOD} = pretend ]] || \
357   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
358   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
359   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] || \
360     [[ ${METHOD} = pretend-build-prerequisites ]]
361  then  then
362   # this is a little bit faster   # this is a little bit faster
363   declare -i x=0   declare -i x=0
# Line 235  then Line 374  then
374   PBUILD="$(magename2pbuild ${i})"   PBUILD="$(magename2pbuild ${i})"
375   if [ -z "${list}" ]   if [ -z "${list}" ]
376   then   then
377   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
378   else   else
379   list="${list}   list="${list}
380  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
# Line 245  then Line 384  then
384   echo "done"   echo "done"
385   echo -e "${list}"   echo -e "${list}"
386   echo   echo
387    
388     if [[ ! -z ${INVALID_DEPS} ]]
389     then
390     echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}"
391     for i in ${INVALID_DEPS}
392     do
393     _dep="${i%%:*}"
394     _mage="${i##*:}"
395     echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}"
396     done
397     echo
398     fi
399    
400     if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
401     then
402     echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
403     for i in ${NO_UPGRADE_CANDIDATE}
404     do
405     echo -e "${COLRED}    ${i}${COLDEFAULT}"
406     done
407     echo
408     echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"
409     echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"
410     echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
411     echo
412     fi
413  fi  fi
414    
415  ## return output from src/install deps  ## return output from src/install deps
416  [[ ${METHOD} = install ]] || \  [[ ${METHOD} = install ]] || \
417   [[ ${METHOD} = srcinstall ]] || \   [[ ${METHOD} = srcinstall ]] || \
418   [[ ${METHOD} = upgrade ]] || \   [[ ${METHOD} = upgrade ]] || \
419   [[ ${METHOD} = srcupgrade ]] && \   [[ ${METHOD} = srcupgrade ]] || \
420     [[ ${METHOD} = install-build-prerequisites ]] && \
421   echo "${ALLDEPS}"   echo "${ALLDEPS}"
   
 # delete ${BUILDDIR}/virtuals if exists as not needed anymore  
 #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals  

Legend:
Removed from v.231  
changed lines
  Added in v.2360