Magellan Linux

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

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

revision 1559 by niro, Wed Dec 28 09:54:25 2011 UTC revision 2285 by niro, Mon Dec 2 10:11:10 2013 UTC
# Line 9  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 /etc/mage.rc.global ] &&  \  [ -f /etc/mage.rc.global ] &&  \
22   source /etc/mage.rc.global || \   source /etc/mage.rc.global || \
# Line 21  die() Line 29  die()
29   source ${MLIBDIR}/mage4.functions.sh || \   source ${MLIBDIR}/mage4.functions.sh || \
30   die "mage functions missing"   die "mage functions missing"
31    
 # 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  
   
32  usage()  usage()
33  {  {
34   echo   echo
35   echo "Usage: $(basename $0) [command] [arg] ..."   echo "Usage: $(basename $0) [command] [arg] ..."
36   echo   echo
37   echo "  -h     --help          shows this help"   echo "  -h     --help          shows this help"
38   echo "  -c     --pcat          categorie of the package"   echo "  -c     --pcat          category of the package"
39   echo "  -n     --pname         name of the package"   echo "  -n     --pname         name of the package"
40   echo "  -v     --pver          version number of the package"   echo "  -v     --pver          version number of the package"
41   echo "  -b     --pbuild        build number of the package"   echo "  -b     --pbuild        build number of the package"
42   echo "  -m     --method        which calc method should be used:"   echo "  -m     --method        which calc method should be used:"
43   echo "                         install, srcinstall, depend, srcdepend"   echo "                         install, srcinstall, depend, srcdepend"
44   echo "                         upgrade, srcupgrade"   echo "                         upgrade, srcupgrade,"
45     echo "                         install-build-prerequisites,"
46     echo "                         pretend-build-prerequisites"
47     echo "  -d     --debug         enable debug mode"
48   echo   echo
49   echo "method, name, version and build must be given !"   echo "method, category, name, version and build must be given !"
50   echo   echo
51   exit 1   exit 1
52  }  }
53    
54    # always default debug=0
55    DEBUG=0
56    
57  # very basic getops  # very basic getops
58  for i in $*  for i in $*
59  do  do
# Line 70  do Line 63  do
63   --pver|-v) shift; PVER="$1" ;;   --pver|-v) shift; PVER="$1" ;;
64   --pbuild|-b) shift; PBUILD="$1" ;;   --pbuild|-b) shift; PBUILD="$1" ;;
65   --method|-m) shift; METHOD="$1" ;;   --method|-m) shift; METHOD="$1" ;;
66     --debug|-d) shift; DEBUG=1 ;;
67   --help|-h) usage ;;   --help|-h) usage ;;
68   esac   esac
69   shift   shift
# Line 119  checklist_processeddeps() Line 113  checklist_processeddeps()
113  }  }
114    
115  #####################  #####################
116  ##  rumwandern /path/to/mage/file/.mage  ##  depwalking /path/to/mage/file/.mage
117  rumwandern()  depwalking()
118  {  {
119   unset DEPEND   unset DEPEND
120   unset SDEPEND   unset SDEPEND
# Line 141  rumwandern() Line 135  rumwandern()
135    
136   DFILE="$1"   DFILE="$1"
137    
138     # debug info
139     decho "depwalking magefile '${DFILE}'"
140     decho
141    
142   source ${DFILE}   source ${DFILE}
143    
144   # forced nodeps   # forced nodeps
# Line 172  rumwandern() Line 170  rumwandern()
170   fi   fi
171   fi   fi
172    
173     if [[ ${METHOD} = install-build-prerequisites ]] || \
174     [[ ${METHOD} = pretend-build-prerequisites ]]
175     then
176     # only one time
177     if [[ ${LOOP_COUNTER} -lt 1 ]]
178     then
179     # only if SDEPEND is not zero
180     if [ -n "${SDEPEND}" ]
181     then
182     # crlf is substantly needed !!
183     if [ -n "${MY_DEPEND}" ]
184     then
185     MY_DEPEND="${MY_DEPEND}
186     ${SDEPEND}"
187     else
188     MY_DEPEND="${SDEPEND}"
189     fi
190     fi
191     fi
192     LOOP_COUNTER=${LOOP_COUNTER}+1
193     fi
194    
195   unset DEPEND   unset DEPEND
196   unset SDEPEND   unset SDEPEND
197    
198   if [ -z "${MY_DEPEND}" ]   if [ -z "${MY_DEPEND}" ]
199   then   then
200     decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
201   return 1   return 1
202   fi   fi
203    
204   while read SYM DEPNAME   while read SYM DEPNAME
205   do   do
206     # debug info
207     decho "DEPNAME='${DEPNAME}'"
208    
209   # exclude empty depnames   # exclude empty depnames
210   [[ -z ${DEPNAME} ]] && continue   [[ -z ${DEPNAME} ]] && continue
211    
# Line 200  rumwandern() Line 224  rumwandern()
224   fi   fi
225    
226   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")   HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
227     if [[ -z ${HIGHEST_DEPFILE} ]]
228     then
229     INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
230     continue
231     fi
232    
233   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"   PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
234   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"   PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
235   PVER="$(magename2pver ${HIGHEST_DEPFILE})"   PVER="$(magename2pver ${HIGHEST_DEPFILE})"
236   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"   PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
237    
238   ## check ob schon in ALLDEPS enthalten dann mach weiter   ## dep already in ALLDEPS? then going on
239    
240   # 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
241   #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]   #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
242   if checklist_alldeps "${HIGHEST_DEPFILE}"   if checklist_alldeps "${HIGHEST_DEPFILE}"
243   then   then
244   ### check ob DFILE schon installiert ist ###   ### check if the dependency is already installed ###
245   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
246   then   then
247   rumwandern ${HIGHEST_DEPFILE}   depwalking ${HIGHEST_DEPFILE}
248   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
249     decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
250   fi   fi
251   fi   fi
252   done << EOF   done << EOF
# Line 225  EOF Line 255  EOF
255   return 0   return 0
256  }  }
257    
   
 ### abort if this package is already installed (retval 3)  
 # maybe later ?  
 #[ -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] && exit 3  
   
258  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
259   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
260   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
261   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
262     [[ ${METHOD} = pretend-build-prerequisites ]] && \
263   echo -n "Calculating dependencies ... "   echo -n "Calculating dependencies ... "
264    
265    
# Line 251  then Line 277  then
277   # get the highest mage file from mage-db   # get the highest mage file from mage-db
278   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
279    
280     # debug info
281     decho "dep='${dep}'"
282     decho "PCAT='${PCAT}'"
283     decho "PNAME='${PNAME}'"
284     decho "MAGEFILE='${MAGEFILE}'"
285    
286   # if no install candidate was found, record this   # if no install candidate was found, record this
287   # and process with the next one   # and process with the next one
288   if [[ -z ${MAGEFILE} ]]   if [[ -z ${MAGEFILE} ]]
289   then   then
290   NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"   NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
291     decho "added to NO_UPGRADE_CANDIDATE"
292   continue   continue
293   fi   fi
294    
# Line 263  then Line 296  then
296   PVER="$(magename2pver ${MAGEFILE})"   PVER="$(magename2pver ${MAGEFILE})"
297   PBUILD="$(magename2pbuild ${MAGEFILE})"   PBUILD="$(magename2pbuild ${MAGEFILE})"
298    
299   # do not wander files which are installed   # debug info
300     decho "PVER='${PVER}'"
301     decho "PBUILD='${PBUILD}'"
302    
303     # do not walk files which are installed
304   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
305   then   then
306   # get dependencies the package   # get dependencies the package
307   rumwandern ${MAGEFILE}   depwalking ${MAGEFILE}
308    
309   # now add the package itself to the dependencies   # now add the package itself to the dependencies
310   # (if not exists already)   # (if not exists already)
  #if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ]  
311   if checklist_alldeps "${MAGEFILE}"   if checklist_alldeps "${MAGEFILE}"
312   then   then
313     decho "added '${MAGEFILE}' to ALLDEPS"
314   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   ALLDEPS="${ALLDEPS} ${MAGEFILE}"
315   fi   fi
316     else
317     # debug info
318     decho "ignored package"
319     decho
320     fi
321   fi   fi
322   done   done
323  else  else
324   # get dependencies the package   LOOP_COUNTER=0
325   rumwandern ${MAGEFILE}   # get all dependencies of the package
326     depwalking ${MAGEFILE}
327    fi
328    
329    if [[ ${METHOD} != install-build-prerequisites ]] &&
330     [[ ${METHOD} != pretend-build-prerequisites ]] &&
331     [[ ${METHOD} != upgrade ]] &&
332     [[ ${METHOD} != uppretend ]] &&
333     [[ ${METHOD} != srcupgrade ]] &&
334     [[ ${METHOD} != srcuppretend ]]
335    then
336   # now add the package itself to the dependencies   # now add the package itself to the dependencies
337   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   # (if not exists already)
338     if checklist_alldeps "${MAGEFILE}"
339     then
340     decho "added '${MAGEFILE}' to ALLDEPS"
341     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
342     fi
343  fi  fi
344    
345  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
346   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
347   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
348   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
349     [[ ${METHOD} = pretend-build-prerequisites ]] && \
350   echo "done"   echo "done"
351    
352    
# Line 297  fi Line 354  fi
354  if [[ ${METHOD} = pretend ]] || \  if [[ ${METHOD} = pretend ]] || \
355   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
356   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
357   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] || \
358     [[ ${METHOD} = pretend-build-prerequisites ]]
359  then  then
360   # this is a little bit faster   # this is a little bit faster
361   declare -i x=0   declare -i x=0
# Line 314  then Line 372  then
372   PBUILD="$(magename2pbuild ${i})"   PBUILD="$(magename2pbuild ${i})"
373   if [ -z "${list}" ]   if [ -z "${list}" ]
374   then   then
375   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
376   else   else
377   list="${list}   list="${list}
378  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
# Line 325  then Line 383  then
383   echo -e "${list}"   echo -e "${list}"
384   echo   echo
385    
386     if [[ ! -z ${INVALID_DEPS} ]]
387     then
388     echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}"
389     for i in ${INVALID_DEPS}
390     do
391     _dep="${i%%:*}"
392     _mage="${i##*:}"
393     echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}"
394     done
395     echo
396     fi
397    
398   if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]   if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
399   then   then
400   echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"   echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
# Line 344  fi Line 414  fi
414  [[ ${METHOD} = install ]] || \  [[ ${METHOD} = install ]] || \
415   [[ ${METHOD} = srcinstall ]] || \   [[ ${METHOD} = srcinstall ]] || \
416   [[ ${METHOD} = upgrade ]] || \   [[ ${METHOD} = upgrade ]] || \
417   [[ ${METHOD} = srcupgrade ]] && \   [[ ${METHOD} = srcupgrade ]] || \
418     [[ ${METHOD} = install-build-prerequisites ]] && \
419   echo "${ALLDEPS}"   echo "${ALLDEPS}"
   
 # delete ${BUILDDIR}/virtuals if exists as not needed anymore  
 #[ -d ${BUILDDIR}/virtuals ] && rm -rf ${BUILDDIR}/virtuals  

Legend:
Removed from v.1559  
changed lines
  Added in v.2285