Magellan Linux

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

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

trunk/mage/usr/lib/mage/depwalker.sh revision 2141 by niro, Mon Jul 15 08:04:58 2013 UTC branches/mage-next/src/depwalker.in revision 2627 by niro, Wed Mar 5 08:18:22 2014 UTC
# Line 2  Line 2 
2  # $Id$  # $Id$
3  # dependeny walker  # dependeny walker
4    
5  # default die function  decho()
 die()  
6  {  {
7   echo ${COLRED}"$@"${COLDEFAULT}   if [[ ${DEBUG} = 1 ]]
8   exit 1   then
9     echo "DEBUG: $@" >&2
10     fi
11  }  }
12    
13  # include all needed files  # set default variables
14  [ -f /etc/mage.rc.global ] &&  \  : ${MAGERC="@@SYSCONFDIR@@/mage.rc"}
15   source /etc/mage.rc.global || \  : ${MLIBDIR="@@MAGELIBDIR@@"}
16   die "/etc/mage.rc.global missing"  
17    # first of all include common functions
18  [ -f ${MAGERC} ] && source ${MAGERC} || \  source ${MLIBDIR}/common.functions.sh || exit 1
19   die "Your ${MAGERC} is missing. Aborting."  source @@SYSCONFDIR@@/mage.rc.global || die "@@SYSCONFDIR@@/mage.rc.global missing"
20    source ${MAGERC} || die "Your ${MAGERC} is missing. Aborting."
21  [ -f ${MLIBDIR}/mage4.functions.sh ] && \  source ${MLIBDIR}/mage4.functions.sh || die "mage functions missing"
22   source ${MLIBDIR}/mage4.functions.sh || \  source ${MLIBDIR}/smage2.functions.sh || die "smage functions missing"
  die "mage functions missing"  
23    
24  usage()  usage()
25  {  {
# Line 27  usage() Line 27  usage()
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, pretend, srcpretend"
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 "  -s     --smage         use a smage to calculate dependencies"
41   echo   echo
42   echo "method, name, version and build must be given !"   echo "method, category, name, version and build must be given !"
43   echo   echo
44   exit 1   exit 1
45  }  }
46    
47    # always default debug=0
48    DEBUG=0
49    
50  # very basic getops  # very basic getops
51  for i in $*  for i in $*
52  do  do
# Line 49  do Line 56  do
56   --pver|-v) shift; PVER="$1" ;;   --pver|-v) shift; PVER="$1" ;;
57   --pbuild|-b) shift; PBUILD="$1" ;;   --pbuild|-b) shift; PBUILD="$1" ;;
58   --method|-m) shift; METHOD="$1" ;;   --method|-m) shift; METHOD="$1" ;;
59     --debug|-d) shift; DEBUG=1 ;;
60     --smage|-s) shift; SMAGEFILE="$1"; SILENT=1; FVERBOSE=off ;;
61   --help|-h) usage ;;   --help|-h) usage ;;
62   esac   esac
63   shift   shift
64  done  done
65    
66  # sanity checks; abort if not given  # sanity checks; abort if not given
67  [ -z "${PCAT}" ] && usage  if [[ -z ${SMAGEFILE} ]]
68  [ -z "${PNAME}" ] && usage  then
69  [ -z "${PVER}" ] && usage   [ -z "${PCAT}" ] && usage
70  [ -z "${PBUILD}" ] && usage   [ -z "${PNAME}" ] && usage
71     [ -z "${PVER}" ] && usage
72     [ -z "${PBUILD}" ] && usage
73    fi
74  [ -z "${METHOD}" ] && usage  [ -z "${METHOD}" ] && usage
75    
76  # check needed global vars  # check needed global vars
# Line 68  done Line 80  done
80    
81  # other needed vars  # other needed vars
82  ALLDEPS=""  ALLDEPS=""
83    if [[ -n ${SMAGEFILE} ]]
84    then
85     if [[ -e ${SMAGEFILE} ]]
86     then
87     smagesource "${SMAGEFILE}"
88     else
89     die "Smage file '${SMAGEFILE}' does not exist!"
90     fi
91    fi
92  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
93    
94  # much faster than fgrep  # much faster than fgrep
# Line 120  depwalking() Line 141  depwalking()
141    
142   DFILE="$1"   DFILE="$1"
143    
144     # debug info
145     decho "depwalking magefile '${DFILE}'"
146     decho
147    
148   source ${DFILE}   source ${DFILE}
149    
150   # forced nodeps   # forced nodeps
# Line 132  depwalking() Line 157  depwalking()
157   MY_DEPEND="${DEPEND}"   MY_DEPEND="${DEPEND}"
158    
159   # for srcinstall & srcdepend only; SDEPEND also needed   # for srcinstall & srcdepend only; SDEPEND also needed
160   if [[ ${METHOD} = srcinstall ]] || \   if [[ ${METHOD} = srcinstall ]] ||
161   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] ||
162   [[ ${METHOD} = srcupgrade ]] || \   [[ ${METHOD} = srcupgrade ]] ||
163   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] ||
164     [[ ${METHOD} = install-build-prerequisites ]] ||
165     [[ ${METHOD} = pretend-build-prerequisites ]]
166   then   then
167   # only if SDEPEND is not zero   # only if SDEPEND is not zero
168   if [ -n "${SDEPEND}" ]   if [ -n "${SDEPEND}" ]
# Line 156  depwalking() Line 183  depwalking()
183    
184   if [ -z "${MY_DEPEND}" ]   if [ -z "${MY_DEPEND}" ]
185   then   then
186     decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
187   return 1   return 1
188   fi   fi
189    
190   while read SYM DEPNAME   while read SYM DEPNAME
191   do   do
192     # debug info
193     decho "DEPNAME='${DEPNAME}'"
194    
195   # exclude empty depnames   # exclude empty depnames
196   [[ -z ${DEPNAME} ]] && continue   [[ -z ${DEPNAME} ]] && continue
197    
# Line 201  depwalking() Line 232  depwalking()
232   then   then
233   depwalking ${HIGHEST_DEPFILE}   depwalking ${HIGHEST_DEPFILE}
234   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
235     decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
236   fi   fi
237   fi   fi
238   done << EOF   done << EOF
# Line 212  EOF Line 244  EOF
244  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
245   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
246   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
247   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
248     [[ ${METHOD} = pretend-build-prerequisites ]] && \
249   echo -n "Calculating dependencies ... "   echo -n "Calculating dependencies ... "
250    
251    
# Line 230  then Line 263  then
263   # get the highest mage file from mage-db   # get the highest mage file from mage-db
264   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
265    
266     # debug info
267     decho "dep='${dep}'"
268     decho "PCAT='${PCAT}'"
269     decho "PNAME='${PNAME}'"
270     decho "MAGEFILE='${MAGEFILE}'"
271    
272   # if no install candidate was found, record this   # if no install candidate was found, record this
273   # and process with the next one   # and process with the next one
274   if [[ -z ${MAGEFILE} ]]   if [[ -z ${MAGEFILE} ]]
275   then   then
276   NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"   NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
277     decho "added to NO_UPGRADE_CANDIDATE"
278   continue   continue
279   fi   fi
280    
# Line 242  then Line 282  then
282   PVER="$(magename2pver ${MAGEFILE})"   PVER="$(magename2pver ${MAGEFILE})"
283   PBUILD="$(magename2pbuild ${MAGEFILE})"   PBUILD="$(magename2pbuild ${MAGEFILE})"
284    
285     # debug info
286     decho "PVER='${PVER}'"
287     decho "PBUILD='${PBUILD}'"
288    
289   # do not walk files which are installed   # do not walk files which are installed
290   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
291   then   then
# Line 250  then Line 294  then
294    
295   # now add the package itself to the dependencies   # now add the package itself to the dependencies
296   # (if not exists already)   # (if not exists already)
  #if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ]  
297   if checklist_alldeps "${MAGEFILE}"   if checklist_alldeps "${MAGEFILE}"
298   then   then
299     decho "added '${MAGEFILE}' to ALLDEPS"
300   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   ALLDEPS="${ALLDEPS} ${MAGEFILE}"
301   fi   fi
302     else
303     # debug info
304     decho "ignored package"
305     decho
306   fi   fi
307   done   done
308  else  else
309   # get all dependencies of the package   # get all dependencies of the package
310   depwalking ${MAGEFILE}   if [[ -n ${SMAGEFILE} ]]
311     then
312     depwalking "${SMAGEFILE}"
313     else
314     depwalking "${MAGEFILE}"
315     fi
316    fi
317    
318    if [[ ${METHOD} != install-build-prerequisites ]] &&
319     [[ ${METHOD} != pretend-build-prerequisites ]] &&
320     [[ ${METHOD} != upgrade ]] &&
321     [[ ${METHOD} != uppretend ]] &&
322     [[ ${METHOD} != srcupgrade ]] &&
323     [[ ${METHOD} != srcuppretend ]]
324    then
325   # now add the package itself to the dependencies   # now add the package itself to the dependencies
326   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   # (if not exists already)
327     if checklist_alldeps "${MAGEFILE}"
328     then
329     decho "added '${MAGEFILE}' to ALLDEPS"
330     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
331     fi
332  fi  fi
333    
334  [[ ${METHOD} = pretend ]] || \  [[ ${METHOD} = pretend ]] || \
335   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
336   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
337   [[ ${METHOD} = srcuppretend ]] && \   [[ ${METHOD} = srcuppretend ]] || \
338     [[ ${METHOD} = pretend-build-prerequisites ]] && \
339   echo "done"   echo "done"
340    
341    
# Line 276  fi Line 343  fi
343  if [[ ${METHOD} = pretend ]] || \  if [[ ${METHOD} = pretend ]] || \
344   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
345   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
346   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] || \
347     [[ ${METHOD} = pretend-build-prerequisites ]]
348  then  then
349   # this is a little bit faster   # this is a little bit faster
350   declare -i x=0   declare -i x=0
# Line 293  then Line 361  then
361   PBUILD="$(magename2pbuild ${i})"   PBUILD="$(magename2pbuild ${i})"
362   if [ -z "${list}" ]   if [ -z "${list}" ]
363   then   then
364   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"   list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
365   else   else
366   list="${list}   list="${list}
367  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"  \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
# Line 335  fi Line 403  fi
403  [[ ${METHOD} = install ]] || \  [[ ${METHOD} = install ]] || \
404   [[ ${METHOD} = srcinstall ]] || \   [[ ${METHOD} = srcinstall ]] || \
405   [[ ${METHOD} = upgrade ]] || \   [[ ${METHOD} = upgrade ]] || \
406   [[ ${METHOD} = srcupgrade ]] && \   [[ ${METHOD} = srcupgrade ]] || \
407     [[ ${METHOD} = install-build-prerequisites ]] && \
408   echo "${ALLDEPS}"   echo "${ALLDEPS}"

Legend:
Removed from v.2141  
changed lines
  Added in v.2627