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 2281 by niro, Wed Nov 20 12:21:28 2013 UTC branches/mage-next/src/depwalker.in revision 2829 by niro, Wed Sep 17 11:20:37 2014 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # $Id$  # $Id$
3  # dependeny walker  # dependency walker
4    
5  # default die function  # set default variables
6  die()  : ${MAGERC="@@SYSCONFDIR@@/mage.rc"}
7    : ${MLIBDIR="@@MAGELIBDIR@@"}
8    
9    # first of all include common functions
10    source ${MLIBDIR}/common.functions.sh || exit 1
11    source @@SYSCONFDIR@@/mage.rc.global || die "@@SYSCONFDIR@@/mage.rc.global missing"
12    source ${MAGERC} || die "Your ${MAGERC} is missing. Aborting."
13    source ${MLIBDIR}/mage4.functions.sh || die "mage functions missing"
14    source ${MLIBDIR}/smage2.functions.sh || die "smage functions missing"
15    
16    decho()
17  {  {
18   echo ${COLRED}"$@"${COLDEFAULT}   if [[ ${DEBUG} = 1 ]]
19   exit 1   then
20     echo "DEBUG: $@" >&2
21     fi
22  }  }
23    
 # include all needed files  
 [ -f /etc/mage.rc.global ] &&  \  
  source /etc/mage.rc.global || \  
  die "/etc/mage.rc.global missing"  
   
 [ -f ${MAGERC} ] && source ${MAGERC} || \  
  die "Your ${MAGERC} is missing. Aborting."  
   
 [ -f ${MLIBDIR}/mage4.functions.sh ] && \  
  source ${MLIBDIR}/mage4.functions.sh || \  
  die "mage functions missing"  
   
24  usage()  usage()
25  {  {
26   echo   echo
# Line 32  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, pretend, srcpretend"
36   echo "                         upgrade, srcupgrade,"   echo "                         upgrade, srcupgrade,"
37   echo "                         install-build-prerequisites,"   echo "                         install-build-prerequisites,"
38   echo "                         pretend-build-prerequisites"   echo "                         pretend-build-prerequisites"
39   echo "  -d     --debug         enable debug mode"   echo "  -d     --debug         enable debug mode"
40     echo "  -s     --smage         use a smage to calculate dependencies"
41   echo   echo
42   echo "method, category, name, version and build must be given !"   echo "method, category, name, version and build must be given !"
43   echo   echo
# Line 56  do Line 57  do
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 ;;   --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 75  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 127  depwalking() Line 141  depwalking()
141    
142   DFILE="$1"   DFILE="$1"
143    
144   if [[ ${DEBUG} = 1 ]]   # debug info
145   then   decho "depwalking magefile '${DFILE}'"
146   echo "DEBUG: depwalking magefile '${DFILE}'" >&2   decho
  echo >&2  
  fi  
147    
148   source ${DFILE}   source ${DFILE}
149    
# Line 145  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 164  depwalking() Line 178  depwalking()
178   fi   fi
179   fi   fi
180    
  if [[ ${METHOD} = install-build-prerequisites ]] || \  
  [[ ${METHOD} = pretend-build-prerequisites ]]  
  then  
  # only one time  
  if [[ ${LOOP_COUNTER} -lt 1 ]]  
  then  
  # only if SDEPEND is not zero  
  if [ -n "${SDEPEND}" ]  
  then  
  # crlf is substantly needed !!  
  if [ -n "${MY_DEPEND}" ]  
  then  
  MY_DEPEND="${MY_DEPEND}  
  ${SDEPEND}"  
  else  
  MY_DEPEND="${SDEPEND}"  
  fi  
  fi  
  fi  
  LOOP_COUNTER=${LOOP_COUNTER}+1  
  fi  
   
181   unset DEPEND   unset DEPEND
182   unset SDEPEND   unset SDEPEND
183    
184   if [ -z "${MY_DEPEND}" ]   if [ -z "${MY_DEPEND}" ]
185   then   then
186   if [[ ${DEBUG} = 1 ]]   decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
  then  
  echo "DEBUG: MY_DEPEND is empty; deps of '${DFILE}' ignored" >&2  
  fi  
187   return 1   return 1
188   fi   fi
189    
190   while read SYM DEPNAME   while read SYM DEPNAME
191   do   do
192   if [[ ${DEBUG} = 1 ]]   # debug info
193   then   decho "DEPNAME='${DEPNAME}'"
  echo "DEBUG: DEPNAME='${DEPNAME}'" >&2  
  fi  
194    
195   # exclude empty depnames   # exclude empty depnames
196   [[ -z ${DEPNAME} ]] && continue   [[ -z ${DEPNAME} ]] && continue
# Line 216  depwalking() Line 203  depwalking()
203    
204   # mark depfile as processed to prevent double runs -without version   # mark depfile as processed to prevent double runs -without version
205   # but do not add any virtuals to PROCESSEDDEPS or their resolved   # but do not add any virtuals to PROCESSEDDEPS or their resolved
206   # pkgnames will be ignored and they are missing on the dependecy-list   # pkgnames will be ignored and they are missing on the dependency-list
207   if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]   if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
208   then   then
209   PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"   PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
# Line 243  depwalking() Line 230  depwalking()
230   ### check if the dependency is already installed ###   ### check if the dependency is already installed ###
231   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
232   then   then
233     # but first get all deps of highest_depfile to catch all dependencies of it
234   depwalking ${HIGHEST_DEPFILE}   depwalking ${HIGHEST_DEPFILE}
235   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
236   if [[ ${DEBUG} = 1 ]]   decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
  then  
  echo "DEBUG: added '${HIGHEST_DEPFILE}' to ALLDEPS" >&2  
  fi  
237   fi   fi
238   fi   fi
239   done << EOF   done << EOF
# Line 279  then Line 264  then
264   # get the highest mage file from mage-db   # get the highest mage file from mage-db
265   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
266    
267   if [[ ${DEBUG} = 1 ]]   # debug info
268   then   decho "dep='${dep}'"
269   echo "DEBUG: dep='${dep}'" >&2   decho "PCAT='${PCAT}'"
270   echo "DEBUG: PCAT='${PCAT}'" >&2   decho "PNAME='${PNAME}'"
271   echo "DEBUG: PNAME='${PNAME}'" >&2   decho "MAGEFILE='${MAGEFILE}'"
  echo "DEBUG: MAGEFILE='${MAGEFILE}'" >&2  
  fi  
272    
273   # if no install candidate was found, record this   # if no install candidate was found, record this
274   # and process with the next one   # and process with the next one
275   if [[ -z ${MAGEFILE} ]]   if [[ -z ${MAGEFILE} ]]
276   then   then
277   NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"   NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
278   if [[ ${DEBUG} = 1 ]]   decho "added to NO_UPGRADE_CANDIDATE"
  then  
  echo "DEBUG: added to NO_UPGRADE_CANDIDATE" >&2  
  fi  
279   continue   continue
280   fi   fi
281    
# Line 303  then Line 283  then
283   PVER="$(magename2pver ${MAGEFILE})"   PVER="$(magename2pver ${MAGEFILE})"
284   PBUILD="$(magename2pbuild ${MAGEFILE})"   PBUILD="$(magename2pbuild ${MAGEFILE})"
285    
286   if [[ ${DEBUG} = 1 ]]   # debug info
287   then   decho "PVER='${PVER}'"
288   echo "DEBUG: PVER='${PVER}'" >&2   decho "PBUILD='${PBUILD}'"
  echo "DEBUG: PBUILD='${PBUILD}'" >&2  
  fi  
289    
290   # do not walk files which are installed   # do not walk files which are installed
291   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
# Line 319  then Line 297  then
297   # (if not exists already)   # (if not exists already)
298   if checklist_alldeps "${MAGEFILE}"   if checklist_alldeps "${MAGEFILE}"
299   then   then
300   if [[ ${DEBUG} = 1 ]]   decho "added '${MAGEFILE}' to ALLDEPS"
  then  
  echo "DEBUG: added '${MAGEFILE}' to ALLDEPS" >&2  
  fi  
301   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   ALLDEPS="${ALLDEPS} ${MAGEFILE}"
302   fi   fi
303   else   else
304   if [[ ${DEBUG} = 1 ]]   # debug info
305   then   decho "ignored package"
306   echo "DEBUG: ignored package" >&2   decho
  echo >&2  
  fi  
307   fi   fi
308   done   done
309  else  else
  LOOP_COUNTER=0  
310   # get all dependencies of the package   # get all dependencies of the package
311   depwalking ${MAGEFILE}   if [[ -n ${SMAGEFILE} ]]
312     then
313     depwalking "${SMAGEFILE}"
314     else
315     depwalking "${MAGEFILE}"
316     fi
317  fi  fi
318    
319  if [[ ${METHOD} != install-build-prerequisites ]] &&  if [[ ${METHOD} != install-build-prerequisites ]] &&
# Line 350  then Line 327  then
327   # (if not exists already)   # (if not exists already)
328   if checklist_alldeps "${MAGEFILE}"   if checklist_alldeps "${MAGEFILE}"
329   then   then
330   if [[ ${DEBUG} = 1 ]]   decho "added '${MAGEFILE}' to ALLDEPS"
  then  
  echo "DEBUG: added '${MAGEFILE}' to ALLDEPS" >&2  
  fi  
331   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   ALLDEPS="${ALLDEPS} ${MAGEFILE}"
332   fi   fi
333  fi  fi

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