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 2275 by niro, Fri Oct 25 07:52:22 2013 UTC branches/mage-next/src/depwalker.in revision 2832 by niro, Fri Sep 19 11:19:35 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, 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  # set some sane defaults
48  DEBUG=0  DEBUG=0
49    SMAGE_DEPEND=0
50    
51  # very basic getops  # very basic getops
52  for i in $*  for i in $*
# Line 56  do Line 58  do
58   --pbuild|-b) shift; PBUILD="$1" ;;   --pbuild|-b) shift; PBUILD="$1" ;;
59   --method|-m) shift; METHOD="$1" ;;   --method|-m) shift; METHOD="$1" ;;
60   --debug|-d) shift; DEBUG=1 ;;   --debug|-d) shift; DEBUG=1 ;;
61     --smage|-s) shift; SMAGEFILE="$1"; SMAGE_DEPEND=1; SILENT=1; FVERBOSE=off ;;
62   --help|-h) usage ;;   --help|-h) usage ;;
63   esac   esac
64   shift   shift
65  done  done
66    
67  # sanity checks; abort if not given  # sanity checks; abort if not given
68  [ -z "${PCAT}" ] && usage  if [[ -z ${SMAGEFILE} ]]
69  [ -z "${PNAME}" ] && usage  then
70  [ -z "${PVER}" ] && usage   [ -z "${PCAT}" ] && usage
71  [ -z "${PBUILD}" ] && usage   [ -z "${PNAME}" ] && usage
72     [ -z "${PVER}" ] && usage
73     [ -z "${PBUILD}" ] && usage
74    fi
75  [ -z "${METHOD}" ] && usage  [ -z "${METHOD}" ] && usage
76    
77  # check needed global vars  # check needed global vars
# Line 75  done Line 81  done
81    
82  # other needed vars  # other needed vars
83  ALLDEPS=""  ALLDEPS=""
84    if [[ -n ${SMAGEFILE} ]]
85    then
86     if [[ -e ${SMAGEFILE} ]]
87     then
88     smagesource "${SMAGEFILE}"
89     else
90     die "Smage file '${SMAGEFILE}' does not exist!"
91     fi
92    fi
93  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
94    
95  # much faster than fgrep  # much faster than fgrep
# Line 127  depwalking() Line 142  depwalking()
142    
143   DFILE="$1"   DFILE="$1"
144    
145     # debug info
146     decho "depwalking magefile '${DFILE}'"
147     decho
148    
149   source ${DFILE}   source ${DFILE}
150    
151   # forced nodeps   # forced nodeps
# Line 139  depwalking() Line 158  depwalking()
158   MY_DEPEND="${DEPEND}"   MY_DEPEND="${DEPEND}"
159    
160   # for srcinstall & srcdepend only; SDEPEND also needed   # for srcinstall & srcdepend only; SDEPEND also needed
161   if [[ ${METHOD} = srcinstall ]] || \   if [[ ${METHOD} = srcinstall ]] ||
162   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] ||
163   [[ ${METHOD} = srcupgrade ]] || \   [[ ${METHOD} = srcupgrade ]] ||
164   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] ||
165     [[ ${METHOD} = install-build-prerequisites ]] ||
166     [[ ${METHOD} = pretend-build-prerequisites ]]
167   then   then
168   # only if SDEPEND is not zero   # only if SDEPEND is not zero
169   if [ -n "${SDEPEND}" ]   if [ -n "${SDEPEND}" ]
# Line 158  depwalking() Line 179  depwalking()
179   fi   fi
180   fi   fi
181    
  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  
   
182   unset DEPEND   unset DEPEND
183   unset SDEPEND   unset SDEPEND
184    
185   if [ -z "${MY_DEPEND}" ]   if [ -z "${MY_DEPEND}" ]
186   then   then
187     decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
188   return 1   return 1
189   fi   fi
190    
191   while read SYM DEPNAME   while read SYM DEPNAME
192   do   do
193   if [[ ${DEBUG} = 1 ]]   # debug info
194   then   decho "DEPNAME='${DEPNAME}'"
  echo "DEBUG: DEPNAME='${DEPNAME}'" >&2  
  fi  
195    
196   # exclude empty depnames   # exclude empty depnames
197   [[ -z ${DEPNAME} ]] && continue   [[ -z ${DEPNAME} ]] && continue
# Line 206  depwalking() Line 204  depwalking()
204    
205   # mark depfile as processed to prevent double runs -without version   # mark depfile as processed to prevent double runs -without version
206   # but do not add any virtuals to PROCESSEDDEPS or their resolved   # but do not add any virtuals to PROCESSEDDEPS or their resolved
207   # pkgnames will be ignored and they are missing on the dependecy-list   # pkgnames will be ignored and they are missing on the dependency-list
208   if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]   if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
209   then   then
210   PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"   PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
# Line 233  depwalking() Line 231  depwalking()
231   ### check if the dependency is already installed ###   ### check if the dependency is already installed ###
232   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
233   then   then
234     # but first get all deps of highest_depfile to catch all dependencies of it
235   depwalking ${HIGHEST_DEPFILE}   depwalking ${HIGHEST_DEPFILE}
236   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
237     decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
238   fi   fi
239   fi   fi
240   done << EOF   done << EOF
# Line 265  then Line 265  then
265   # get the highest mage file from mage-db   # get the highest mage file from mage-db
266   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
267    
268     # debug info
269     decho "dep='${dep}'"
270     decho "PCAT='${PCAT}'"
271     decho "PNAME='${PNAME}'"
272     decho "MAGEFILE='${MAGEFILE}'"
273    
274   # if no install candidate was found, record this   # if no install candidate was found, record this
275   # and process with the next one   # and process with the next one
276   if [[ -z ${MAGEFILE} ]]   if [[ -z ${MAGEFILE} ]]
277   then   then
278   NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"   NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
279     decho "added to NO_UPGRADE_CANDIDATE"
280   continue   continue
281   fi   fi
282    
# Line 277  then Line 284  then
284   PVER="$(magename2pver ${MAGEFILE})"   PVER="$(magename2pver ${MAGEFILE})"
285   PBUILD="$(magename2pbuild ${MAGEFILE})"   PBUILD="$(magename2pbuild ${MAGEFILE})"
286    
287     # debug info
288     decho "PVER='${PVER}'"
289     decho "PBUILD='${PBUILD}'"
290    
291   # do not walk files which are installed   # do not walk files which are installed
292   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
293   then   then
294   # get dependencies the package   # get dependencies the package
295   depwalking ${MAGEFILE}   depwalking ${MAGEFILE}
296    
297     # now add the package itself to the dependencies
298     # (if not exists already)
299     if checklist_alldeps "${MAGEFILE}"
300     then
301     decho "added '${MAGEFILE}' to ALLDEPS"
302     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
303     fi
304     else
305     # debug info
306     decho "ignored package"
307     decho
308   fi   fi
309   done   done
310  else  else
  LOOP_COUNTER=0  
311   # get all dependencies of the package   # get all dependencies of the package
312   depwalking ${MAGEFILE}   if [[ -n ${SMAGEFILE} ]]
313     then
314     depwalking "${SMAGEFILE}"
315     else
316     depwalking "${MAGEFILE}"
317     fi
318  fi  fi
319    
320  if [[ ${METHOD} != install-build-prerequisites ]] &&  if [[ ${METHOD} != install-build-prerequisites ]] &&
321   [[ ${METHOD} != pretend-build-prerequisites ]]   [[ ${METHOD} != pretend-build-prerequisites ]] &&
322     [[ ${METHOD} != upgrade ]] &&
323     [[ ${METHOD} != uppretend ]] &&
324     [[ ${METHOD} != srcupgrade ]] &&
325     [[ ${METHOD} != srcuppretend ]]
326  then  then
327   # now add the package itself to the dependencies   # now add the package itself to the dependencies
328   # (if not exists already)   # (if not exists already)
329   if checklist_alldeps "${MAGEFILE}"   if checklist_alldeps "${MAGEFILE}"
330   then   then
331     decho "added '${MAGEFILE}' to ALLDEPS"
332   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   ALLDEPS="${ALLDEPS} ${MAGEFILE}"
333   fi   fi
334  fi  fi

Legend:
Removed from v.2275  
changed lines
  Added in v.2832