Magellan Linux

Diff of /branches/mage-next/src/mage4.functions.sh.in

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

trunk/mage/usr/lib/mage/mage4.functions.sh revision 1273 by niro, Wed Apr 27 09:45:07 2011 UTC branches/mage-next/src/mage4.functions.sh.in revision 2613 by niro, Tue Mar 4 15:26:05 2014 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # Magellan Linux Installer Functions (mage.functions.sh)  # Magellan Linux Installer Functions (mage.functions.sh)
3  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.38 2008-10-05 10:32:24 niro Exp $  # $Id$
4    
5  mage_setup()  mage_setup()
6  {  {
# Line 15  mage_setup() Line 15  mage_setup()
15   return 0   return 0
16  }  }
17    
18    mchecksum()
19    {
20     local i
21     local rundir
22     local file
23     local method
24     local cmd
25     local retval
26     local sum
27     local dest
28    
29     # very basic getops
30     for i in $*
31     do
32     case $1 in
33     --rundir|-r) shift; rundir="$1" ;;
34     --file|-f) shift; file="$1" ;;
35     --method|-m) shift; method="$1" ;;
36     esac
37     shift
38     done
39    
40     # sanity checks
41     [[ -z ${rundir} ]] && die "mchecksum(): rundir missing"
42     [[ -z ${file} ]] && die "mchecksum(): file missing"
43     [[ -z ${method} ]] && die "mchecksum(): method missing"
44    
45     case ${method} in
46     md5) cmd="md5sum" ;;
47     sha256) cmd="sha256sum" ;;
48     *) die "mchecksum(): unknown method '${method}'" ;;
49     esac
50    
51     if [[ -d ${rundir} ]]
52     then
53     pushd ${rundir} &> /dev/null
54    
55     # all file must be non-zero
56     retval=0
57     while read sum dest
58     do
59     if [ ! -s ${dest} ]
60     then
61     echo "${dest}: file is empty ;("
62     retval=127
63     fi
64     done < ${file}
65     if [[ ${retval} != 127 ]]
66     then
67     # be verbose here
68     ${cmd} -c ${file} #&> /dev/null
69     retval="$?"
70     fi
71    
72     popd &> /dev/null
73     else
74     retval=1
75     fi
76    
77     return "${retval}"
78    }
79    
80    mcheckemptydir()
81    {
82     local dir="$1"
83     local retval=1
84    
85     if [[ ! -d ${dir} ]]
86     then
87     echo "mcheckemptydir(): '${dir}' is not a directory!"
88     retval=3
89     else
90     shopt -s nullglob dotglob
91     files=( ${dir}/* )
92     (( ${#files[*]} )) || retval=0
93     shopt -u nullglob dotglob
94     fi
95    
96     return ${retval}
97    }
98    
99    unpack_package()
100    {
101     local magefile="$1"
102     local pkgname
103     local pkgfile
104     local pkgtype
105     local tar_opts
106    
107     pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
108     pkgfile="${pkgname}.${PKGSUFFIX}"
109     pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
110    
111     xtitle "[ Unpacking ${pkg} ]"
112    
113     # abort on virtual pkg
114     if [[ ${pkgtype} = virtual ]]
115     then
116     echo -ne " ${COLBLUE}---${COLDEFAULT}"
117     echo " !unpack virtual ${pkgname} ... "
118     continue
119     fi
120    
121     # abort on sources pkg
122     if [[ ${pkgtype} = sources ]]
123     then
124     echo -ne " ${COLBLUE}---${COLDEFAULT}"
125     echo " !unpack sources ${pkgname} ... "
126     continue
127     fi
128    
129     # busybox?
130     if need_busybox_support tar
131     then
132     tar_opts="xjf"
133     else
134     tar_opts="xjmf"
135     fi
136    
137     echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkgfile} ... "
138     tar ${tar_opts} ${PKGDIR}/${pkgfile} -C ${BUILDDIR} || die "Unpacking package ${pkgfile}"
139    }
140    
141  unpack_packages()  unpack_packages()
142  {  {
143   local list="$@"   local list="$@"
144   local magefile   local magefile
  local pkg  
  local pkgtype  
145   local count_current   local count_current
146   local count_total   local count_total
147   local tar_opts   local tar_opts
# Line 33  unpack_packages() Line 154  unpack_packages()
154    
155   for magefile in ${list}   for magefile in ${list}
156   do   do
157   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   unpack_package "${magefile}"
  pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"  
   
158   (( count_current++ ))   (( count_current++ ))
  xtitle "[ (${count_current}/${count_total}) Unpacking ${pkg} ]"  
   
  # abort on virtual pkg  
  if [[ ${pkgtype} = virtual ]]  
  then  
  echo -ne " ${COLBLUE}---${COLDEFAULT}"  
  echo " !unpack virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "  
  continue  
  fi  
   
  # abort on sources pkg  
  if [[ ${pkgtype} = sources ]]  
  then  
  echo -ne " ${COLBLUE}---${COLDEFAULT}"  
  echo " !unpack sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "  
  continue  
  fi  
   
  # busybox?  
  if need_busybox_support tar  
  then  
  tar_opts="xjf"  
  else  
  tar_opts="xjmf"  
  fi  
   
  echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "  
  tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"  
159   done   done
160    
161   # add a crlf for a better view   # add a crlf for a better view
# Line 84  fix_mtime() Line 175  fix_mtime()
175   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
176   touch \   touch \
177   --no-create \   --no-create \
178     --no-dereference \
179   --time=mtime \   --time=mtime \
180   --reference "${reference}" \   --reference="${reference}" \
181   "${pathto}"   "${pathto}"
182    
183   echo "${mtime}"   echo "${mtime}"
# Line 139  install_directories() Line 231  install_directories()
231   while read pathto posix user group   while read pathto posix user group
232   do   do
233   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
234   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
   
235    
236   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
237   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 216  install_files() Line 307  install_files()
307   case ${retval} in   case ${retval} in
308   # file is not protected - (over)write it   # file is not protected - (over)write it
309   0|3)   0|3)
310   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
311   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
312   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
313   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 228  install_files() Line 319  install_files()
319   "${user}" \   "${user}" \
320   "${group}" \   "${group}" \
321   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
322   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
323   "${md5sum}"   "${md5sum}"
324   ;;   ;;
325    
326   # file is protected, write backup file   # file is protected, write backup file
327   2)   2)
328   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
329   then   then
330   echo -en "${COLRED}"   echo -en "${COLRED}"
331   echo -n "! prot "   echo -n "! prot "
# Line 255  install_files() Line 346  install_files()
346   "${user}" \   "${user}" \
347   "${group}" \   "${group}" \
348   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
349   "${dest_protected}")" \   "${dest_protected}")" \
350   "${md5sum}"   "${md5sum}"
351    
352   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
# Line 265  install_files() Line 356  install_files()
356    
357   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
358   4)   4)
359   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
360   then   then
361   echo -en "${COLRED}"   echo -en "${COLRED}"
362   echo -n "! ignr "   echo -n "! ignr "
363   echo -en "${COLDEFAULT}"   echo -en "${COLDEFAULT}"
364   echo " === FILE: ${MROOT}${pathto}"   echo " === FILE: ${MROOT}${pathto}"
365   fi   fi
366   # simply do nothing here   # simply do nothing here - only fix mtime
367     fix_descriptor ${pkgname}/.files \
368     "${pathto}" \
369     "${posix}" \
370     "${user}" \
371     "${group}" \
372     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
373     "${MROOT}${pathto}")" \
374     "${md5sum}"
375   ;;   ;;
376   esac   esac
377   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
# Line 316  install_symlinks() Line 415  install_symlinks()
415   while read pathto posix link mtime   while read pathto posix link mtime
416   do   do
417   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
418   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
419    
420   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
421    
422  # # fix mtime and db   # fix mtime and db
423  # fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
424  # "${pathto}" \   "${pathto}" \
425  # "${posix}" \   "${posix}" \
426  # "${link}" \   "${link}" \
427  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
428  # "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
429    
430   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
431    
# Line 366  install_blockdevices() Line 465  install_blockdevices()
465   while read pathto posix major minor user group   while read pathto posix major minor user group
466   do   do
467   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
468   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
469    
470   mknod -m "${posix}" "${MROOT}${pathto}"   mknod -m "${posix}" "${MROOT}${pathto}"
471   # make it optional atm !!   # make it optional atm !!
# Line 410  install_characterdevices() Line 509  install_characterdevices()
509   while read pathto posix major minor user group   while read pathto posix major minor user group
510   do   do
511   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
512   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
513    
514   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
515    
# Line 454  install_fifos() Line 553  install_fifos()
553   while read pathto posix user group   while read pathto posix user group
554   do   do
555   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
556   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FIFO: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
557    
558   mkfifo -m "${posix}" "${MROOT}${pathto}"   mkfifo -m "${posix}" "${MROOT}${pathto}"
559   chown "${user}:${group}" "${MROOT}${pathto}"   chown "${user}:${group}" "${MROOT}${pathto}"
# Line 476  build_doinstall() Line 575  build_doinstall()
575    
576   # sanity checks; abort if not given   # sanity checks; abort if not given
577   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
578    
579   # this is only a wrapper   # this is only a wrapper
580    
581   # NOTE:   # NOTE:
# Line 713  compare_mtime() Line 812  compare_mtime()
812    
813   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
814    
815   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
816   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
817   then   x=$(stat -c %Y "${MROOT}${pathto}")
  # readlink -f resolves full path of linked file  
  x="$(readlink -f "${MROOT}${pathto}")"  
   
  # abort if target does not exists  
  # we keep safe here, theoretically the link can removed  
  [ ! -e "${x}" ] && return 1  
   
  x=$(stat -c %Y "${x}")  
  else  
  x=$(stat -c %Y "${MROOT}${pathto}")  
  fi  
818    
819   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
820    
# Line 788  remove_symlinks() Line 876  remove_symlinks()
876   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
877   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
878   then   then
879   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
880   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
881   continue   continue
882   fi   fi
# Line 800  remove_symlinks() Line 888  remove_symlinks()
888   # 1=keep me   #   # 1=keep me   #
889   case ${retval} in   case ${retval} in
890   0)   0)
891   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
892   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
893   ;;   ;;
894    
895   1)   1)
896   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
897   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
898   ;;   ;;
899   esac   esac
# Line 872  remove_files() Line 960  remove_files()
960    
961   if [ ! -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
962   then   then
963   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
964   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
965   continue   continue
966   fi   fi
# Line 898  remove_files() Line 986  remove_files()
986   case ${retval} in   case ${retval} in
987   # file is not protected - delete it   # file is not protected - delete it
988   0|3)   0|3)
989   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
990   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
991   ;;   ;;
992    
993   # file is protected, do not delete   # file is protected, do not delete
994   2)   2)
995   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
996   then   then
997   echo -en "${COLRED}"   echo -en "${COLRED}"
998   echo -n "! prot "   echo -n "! prot "
# Line 915  remove_files() Line 1003  remove_files()
1003    
1004   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
1005   4)   4)
1006   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1007   then   then
1008   echo -en "${COLRED}"   echo -en "${COLRED}"
1009   echo -n "! ignr "   echo -n "! ignr "
# Line 927  remove_files() Line 1015  remove_files()
1015   esac   esac
1016   ;;   ;;
1017   1)   1)
1018   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1019   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1020   ;;   ;;
1021   esac   esac
# Line 989  remove_blockdevices() Line 1077  remove_blockdevices()
1077   do   do
1078   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1079    
1080   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1081   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1082   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1083    
# Line 1049  remove_characterdevices() Line 1137  remove_characterdevices()
1137   do   do
1138   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1139    
1140   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1141   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1142   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1143    
# Line 1111  remove_fifos() Line 1199  remove_fifos()
1199   do   do
1200   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1201    
1202   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1203   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1204   done < ${MROOT}${INSTALLDB}/${pfull}/.fifo   done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1205    
# Line 1172  remove_directories() Line 1260  remove_directories()
1260    
1261   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1262   then   then
1263   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1264   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1265   continue   continue
1266   fi   fi
# Line 1180  remove_directories() Line 1268  remove_directories()
1268   # exclude .keep directories   # exclude .keep directories
1269   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1270   then   then
1271   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1272   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1273   continue   continue
1274   fi   fi
# Line 1193  remove_directories() Line 1281  remove_directories()
1281    
1282   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1283   then   then
1284   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1285   else   else
1286   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1287   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1288   fi   fi
1289   done   done
# Line 1253  build_douninstall() Line 1341  build_douninstall()
1341   done   done
1342  }  }
1343    
1344    # convertmirrors [uri]
1345    convertmirrors()
1346    {
1347     local uri="$1"
1348     local scheme
1349     local mirror
1350     local mirrors
1351     local addon
1352     local real_uri
1353     local output
1354    
1355     # needs
1356     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1357     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1358     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1359     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1360     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1361    
1362     # check known uri schemes
1363     case ${uri} in
1364     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1365     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1366     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1367     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1368     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1369     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1370     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1371     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1372     esac
1373    
1374     if [[ ! -z ${mirrors} ]]
1375     then
1376     for mirror in ${mirrors}
1377     do
1378     # add a whitespace to the output
1379     [[ -z ${output} ]] || output+=" "
1380     output+="${mirror}${addon}/${uri/${scheme}/}"
1381     done
1382     else
1383     output="${uri}"
1384     fi
1385    
1386     echo "${output}"
1387    }
1388    
1389    mdownload()
1390    {
1391     local i
1392     local uri
1393     local real_uris
1394     local mirror
1395     local outputfile
1396     local outputdir
1397     local retval
1398     local wget_opts
1399    
1400     # very basic getops
1401     for i in $*
1402     do
1403     case $1 in
1404     --uri|-u) shift; uri="$1" ;;
1405     --dir|-d) shift; outputdir="$1" ;;
1406     esac
1407     shift
1408     done
1409    
1410     # sanity checks; abort if not given
1411     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1412     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1413    
1414     # convert mirrored uris to the real ones
1415     real_uris="$(convertmirrors ${uri})"
1416    
1417     # verbose or not
1418     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1419    
1420     # filter wget options if busybox was found
1421     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1422    
1423     # create outputdir
1424     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1425    
1426     for mirror in ${real_uris}
1427     do
1428     # get the name of the output file
1429     outputfile="${mirror##*/}"
1430    
1431     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1432     retval="$?"
1433     if [[ ${retval} = 0 ]]
1434     then
1435     break
1436     else
1437     continue
1438     fi
1439     done
1440    
1441     # return wget retval
1442     return "${retval}"
1443    }
1444    
1445  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1446  fetch_packages()  fetch_packages()
1447  {  {
1448     local i
1449   local list="$@"   local list="$@"
1450   local pkg   local pkgname
1451     local pkgfile
1452     local pcat
1453     local pname
1454   local mirr   local mirr
1455   local magefile   local magefile
1456   local md5file   local md5file
# Line 1265  fetch_packages() Line 1458  fetch_packages()
1458   local count_current   local count_current
1459   local count_total   local count_total
1460   local wget_opts   local wget_opts
1461     local fetching
1462    
1463   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1464    
# Line 1279  fetch_packages() Line 1473  fetch_packages()
1473    
1474   for magefile in ${list}   for magefile in ${list}
1475   do   do
1476   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1477     pkgfile="${pkgname}.${PKGSUFFIX}"
1478   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1479    
1480     pcat=$(magename2pcat ${magefile})
1481     pname=$(magename2pname ${magefile})
1482     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
1483    
1484   (( count_current++ ))   (( count_current++ ))
1485   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1486    
1487   # abort on virtual pkg   # abort on virtual pkg
1488   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1489   then   then
1490   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1491   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1492   continue   continue
1493   fi   fi
1494    
# Line 1297  fetch_packages() Line 1496  fetch_packages()
1496   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1497   then   then
1498   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1499   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1500   continue   continue
1501   fi   fi
1502    
1503   # abort if already exist   # check if FETCHING is required
1504   if [ -f ${PKGDIR}/${pkg} ]   if [ ! -f "${md5file}" ]
1505   then   then
1506   echo -ne " ${COLBLUE}***${COLDEFAULT}"   fetching=true
1507   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   else
1508   continue   if mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 &> /dev/null
  fi  
   
  for mirr in ${MIRRORS}  
  do  
  echo -ne " ${COLBLUE}***${COLDEFAULT}"  
  #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... "  
  echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "  
  [[ ${VERBOSE} = off ]] && opt="--quiet"  
  wget \  
  ${wget_opts} \  
  --directory-prefix=${PKGDIR} \  
  ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}  
  if [[ $? = 0 ]]  
1509   then   then
1510   break   # md5's ok, no fetching required
1511     fetching=false
1512   else   else
1513   continue   fetching=true
1514   fi   fi
1515   done   fi
1516    
1517     if [[ ${fetching} = false ]]
1518     then
1519     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1520     echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1521     continue
1522     else
1523     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1524     echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1525     mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1526     fi
1527    
1528   if [ ! -f ${PKGDIR}/${pkg} ]   # sanity check, not really needed but to be sure
1529     if [ ! -f ${PKGDIR}/${pkgfile} ]
1530   then   then
1531   die "Could not download ${pkg}"   die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1532   fi   fi
1533   done   done
1534    
# Line 1357  syncmage() Line 1556  syncmage()
1556   done   done
1557    
1558   # clean up backup files (foo~)   # clean up backup files (foo~)
1559   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1560    
1561   # check if a newer mage version is available   # check if a newer mage version is available
1562   is_newer_mage_version_available   is_newer_mage_version_available
# Line 1371  syncmage_tarball() Line 1570  syncmage_tarball()
1570   local mirr mymirr   local mirr mymirr
1571   local opt   local opt
1572   local tar_opts   local tar_opts
1573     local wget_opts
1574    
1575   # try to get the md5 marked as latest on the server   # try to get the md5 marked as latest on the server
1576   latest_md5="mage-latest.md5"   latest_md5="mage-latest.md5"
# Line 1378  syncmage_tarball() Line 1578  syncmage_tarball()
1578   # try to get the tarball marked as latest on the server   # try to get the tarball marked as latest on the server
1579   latest_tarball="mage-latest.tar.bz2"   latest_tarball="mage-latest.tar.bz2"
1580    
1581     # filter wget command if busybox was found
1582     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1583    
1584   for mirr in ${MIRRORS}   for mirr in ${MIRRORS}
1585   do   do
1586   # path without distribution   # path without distribution
1587   mymirr="${mirr%/*}"   # (only for stable|testing|unstable and not DISTROTAG)
1588     case ${mirr##*/} in
1589     stable|testing|unstable) mymirr="${mirr%/*}";;
1590     *) mymirr="${mirr}";;
1591     esac
1592    
1593   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1594   echo "fetching latest md5 from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
1595   [[ ${VERBOSE} = off ]] && opt="--quiet"   mqueryfeature "!verbose" && opt="--quiet"
1596   wget \   wget \
1597   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1598   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1599   ${opt} ${mymirr}/rsync/tarballs/${latest_md5}   ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1600    
1601   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1602   echo "fetching latest tarball from ${mymirr} ..."   echo "fetching latest tarball from ${mymirr} ..."
1603   wget \   wget \
1604   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1605   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1606   ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}   ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1607   if [[ $? = 0 ]]   if [[ $? = 0 ]]
# Line 1414  syncmage_tarball() Line 1621  syncmage_tarball()
1621   else   else
1622   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1623   echo -n "checking md5sum... "   echo -n "checking md5sum... "
1624   ( cd ${temp}; md5sum -c ${latest_md5} ) || die "md5 for ${latest_tarball} failed"   mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1625   fi   fi
1626    
1627   if [[ -d ${MAGEDIR} ]]   if [[ -d ${MAGEDIR} ]]
1628   then   then
1629   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1630   echo "cleaning old mage-tree ${MAGEDIR}..."   echo "cleaning old mage-tree ${MAGEDIR}..."
1631   rm -rf ${MAGEDIR}   # honor mountpoints and empty dirs
1632     if mountpoint -q ${MAGEDIR}
1633     then
1634     if ! mcheckemptydir ${MAGEDIR}
1635     then
1636     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1637     fi
1638     else
1639     rm -rf ${MAGEDIR}
1640     fi
1641   fi   fi
1642    
1643   if need_busybox_support tar   if need_busybox_support tar
# Line 1460  cleanpkg() Line 1676  cleanpkg()
1676   fi   fi
1677  }  }
1678    
1679  xtitle()  # unused?
1680  {  #
1681   if [[ ${TERM} = xterm ]]  # # cuts full pathnames or versionized names down to basename
1682   then  # choppkgname()
1683   echo -ne "\033]0;Mage: $1\007"  # {
1684   fi  # #we want this only if full name was used
1685   return 0  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1686  }  # then
1687    # #cuts ARCH and PBUILD
1688    # #ARCH comes from ${MAGERC}
1689  xtitleclean()  # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1690  {  #
1691   if [[ ${TERM} = xterm ]]  # #cuts version number
1692   then  # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1693   echo -ne "\033]0;\007"  # fi
1694   fi  # }
  return 0  
 }  
   
   
 # cuts full pathnames or versioniezed names down to basename  
 choppkgname()  
 {  
  #we want this only if full name was used  
  if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  
  then  
  #cuts ARCH and PBUILD  
  #ARCH comes from ${MAGERC}  
  MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  
1695    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1696    
1697  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1698  # $1=pname  # $1=pname
# Line 1563  get_highest_magefile() Line 1762  get_highest_magefile()
1762   local magefile   local magefile
1763    
1764   # do not list the content of a directory, only the name (-d)   # do not list the content of a directory, only the name (-d)
1765   for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/*)   for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1766   do   do
1767   [[ -z ${magefile} ]] && continue   [[ -z ${magefile} ]] && continue
1768   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
# Line 1572  get_highest_magefile() Line 1771  get_highest_magefile()
1771   then   then
1772   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1773   #for debug only   #for debug only
1774   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1775   fi   fi
1776   done   done
1777    
 # do not so anything  
 # # stop here if HIGHEST_MAGEFILE is zero  
 # # this package must be unstable or old  
 # if [ -z "${HIGHEST_MAGEFILE}" ]  
 # then  
 # echo  
 # echo -n "All packages named "  
 # echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}  
 # echo -n " are marked "  
 # echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}  
 # echo "."  
 # echo "You need to declare USE_UNSTABLE=true to install this."  
 # echo  
 # echo "Example:"  
 # echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"  
 # echo  
 # echo "Be warned that these packages are not stable and may cause serious problems."  
 # echo "You should know what you are doing, so don't complain about any damage."  
 # echo  
 # return 1  
 # fi  
   
1778   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1779   return 0   return 0
1780  }  }
# Line 1701  count_protected_files() Line 1878  count_protected_files()
1878   local filename="${file##*/}"   local filename="${file##*/}"
1879   local count   local count
1880   local output   local output
1881     local oldprotected
1882   local i   local i
1883     local x
1884    
1885     # hack; do not honor a global set IFS like '§'
1886     local IFS
1887    
1888   declare -i count=0   count=0
1889    
1890   # check if there are already protected files   # check if there are already protected files
1891   for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |   for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1892   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1893   sort -t'%' -k3 -k2 | cut -f1 -d'%')   sort -t'%' -k3 -k2 | cut -f1 -d'%')
1894   do   do
1895   count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")   count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1896     done
1897    
1898     # convert 0001 -> 1; 0120 -> 120 etc
1899     # use bash internal base functions to this task
1900     x="$((10#${count}))"
1901     for (( i=0; i<x; i++ ))
1902     do
1903     if [[ ${count:${i}:1} != 0 ]]
1904     then
1905     count="${count:${i}}"
1906     break
1907     fi
1908   done   done
1909   (( count ++ ))  
1910     count="$(( ${count}+1 ))"
1911    
1912   # fill output up with zeros   # fill output up with zeros
1913   for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done   for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
# Line 2002  minclude() Line 2197  minclude()
2197   then   then
2198   for i in $*   for i in $*
2199   do   do
2200   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2201   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2202   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2203   done   done
2204   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2205   fi   fi
2206  }  }
2207    
# Line 2018  sminclude() Line 2213  sminclude()
2213   then   then
2214   for i in $*   for i in $*
2215   do   do
2216   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2217   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2218   done   done
2219   echo   [[ ${SILENT} = 1 ]] || echo
2220   fi   fi
2221  }  }
2222    
# Line 2048  is_newer_mage_version_available() Line 2243  is_newer_mage_version_available()
2243   fi   fi
2244  }  }
2245    
   
2246  # returns pname from pkgname  # returns pname from pkgname
2247  # pkgname2pname $PKGNAME  # pkgname2pname $PKGNAME
2248  pkgname2pname()  pkgname2pname()
# Line 2325  get_value_from_magefile() Line 2519  get_value_from_magefile()
2519   local SDEPEND   local SDEPEND
2520   local PROVIDE   local PROVIDE
2521   local PKGTYPE   local PKGTYPE
  local MAGE_TARGETS  
2522   local SPLIT_PACKAGE_BASE   local SPLIT_PACKAGE_BASE
2523   local preinstall   local preinstall
2524   local postinstall   local postinstall
# Line 2447  mage_install() Line 2640  mage_install()
2640   echo B:${pbuild}   echo B:${pbuild}
2641   fi   fi
2642    
2643   if [[ -n ${MAGE_TARGETS} ]]   if [[ -n ${SPLIT_PACKAGE_BASE} ]]
  then  
  # basic svn compat  
  if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]  
  then  
  for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2  
  do  
  smage2file="${i}"  
  done  
  else  
  smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2  
  fi  
   
  elif [[ -n ${SPLIT_PACKAGE_BASE} ]]  
2644   then   then
2645   # basic svn compat   # basic svn compat
2646   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2647   then   then
2648   for i in ${SMAGESCRIPTSDIR}/trunk/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2649   do   do
2650   smage2file="${i}"   smage2file="${i}"
2651   done   done
# Line 2475  mage_install() Line 2655  mage_install()
2655    
2656   else   else
2657   # basic svn compat   # basic svn compat
2658   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2659   then   then
2660   for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2661   do   do
2662   smage2file="${i}"   smage2file="${i}"
2663   done   done
# Line 2502  mage_install() Line 2682  mage_install()
2682   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2683   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2684   then   then
2685     unpack_package "${magefile}"
2686   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
2687   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2688   fi   fi
# Line 2546  mage_install() Line 2727  mage_install()
2727   then   then
2728   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2729   echo -n "rebuilding environment ... "   echo -n "rebuilding environment ... "
2730   ${MLIBDIR}/env-rebuild.sh > /dev/null && \   ${MLIBDIR}/env-rebuild > /dev/null && \
2731   echo "done." || echo "failure."   echo "done." || echo "failure."
2732   unset MAGE_ENV_REBUILD   unset MAGE_ENV_REBUILD
2733   fi   fi
# Line 2590  md5sum_packages() Line 2771  md5sum_packages()
2771   pname=$(magename2pname ${magefile})   pname=$(magename2pname ${magefile})
2772   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2773   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2774   pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
2775   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2776    
2777   (( count_current++ ))   (( count_current++ ))
# Line 2600  md5sum_packages() Line 2781  md5sum_packages()
2781   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
2782   then   then
2783   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2784   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... "
2785   continue   continue
2786   fi   fi
2787    
# Line 2608  md5sum_packages() Line 2789  md5sum_packages()
2789   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
2790   then   then
2791   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2792   echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... "
2793   continue   continue
2794   fi   fi
2795    
# Line 2616  md5sum_packages() Line 2797  md5sum_packages()
2797   then   then
2798   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2799   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2800   ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2801   else   else
2802   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2803   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2656  uninstall_packages() Line 2837  uninstall_packages()
2837   pbuild=$(magename2pbuild ${pkg})   pbuild=$(magename2pbuild ${pkg})
2838   can_pcat="${pcat}"   can_pcat="${pcat}"
2839   can_pname="${pname}"   can_pname="${pname}"
2840    
2841   if [ -z "${can_ver_list}" ]   if [ -z "${can_ver_list}" ]
2842   then   then
2843   can_ver_list=" ${pver}-${pbuild}"   can_ver_list=" ${pver}-${pbuild}"
# Line 2811  mage_uninstall() Line 2992  mage_uninstall()
2992   then   then
2993   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2994   echo -n "rebuilding environment ... "   echo -n "rebuilding environment ... "
2995   ${MLIBDIR}/env-rebuild.sh > /dev/null && \   ${MLIBDIR}/env-rebuild > /dev/null && \
2996   echo "done." || echo "failure."   echo "done." || echo "failure."
2997   unset MAGE_ENV_REBUILD   unset MAGE_ENV_REBUILD
2998   fi   fi
# Line 2829  mage_uninstall() Line 3010  mage_uninstall()
3010   unset -f postremove   unset -f postremove
3011  }  }
3012    
3013    # rerun_pkgfunctions [method] pkg1 pkg2 pkg3
3014    rerun_pkgfunctions()
3015    {
3016     local method
3017     local list
3018     local pcat
3019     local pname
3020     local pver
3021     local pbuild
3022     local magefile
3023     local i
3024    
3025     # very basic getops
3026     case $1 in
3027     --method) shift; method="$1" ;;
3028     esac
3029     shift
3030     local list="$@"
3031    
3032     # sanity check
3033     case ${method} in
3034     preinstall|postinstall) ;;
3035     preremove|postremove) ;;
3036     *) die "rerun_pkgfunctions(): Unknown method '${method}'." ;;
3037     esac
3038    
3039     if [[ -n ${MROOT} ]]
3040     then
3041     echo -ne ${COLRED}
3042     echo "!! running in MROOT=${MROOT}"
3043     echo -ne ${COLDEFAULT}
3044     echo
3045     fi
3046    
3047     for pkg in ${list}
3048     do
3049     pcat=$(dep2pcat ${pkg})
3050     pname=$(magename2pname ${pkg})
3051     pver=$(magename2pver ${pkg})
3052     pbuild=$(magename2pbuild ${pkg})
3053     magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
3054    
3055     if [ -e ${magefile} ]
3056     then
3057     source ${magefile}
3058     if [ -n "$(typeset -f ${method})" ]
3059     then
3060     echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... "
3061     ${method}
3062     else
3063     echo "No ${method}() for pkg '${pkg}' defined. Doing nothing."
3064     fi
3065     unset -f preinstall postinstall preremove postremove
3066     else
3067     die "Magefile '${magefile}' does not exist."
3068     fi
3069     done
3070    }
3071    
3072  show_etc_update_mesg()  show_etc_update_mesg()
3073  {  {
3074   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
# Line 2856  pkgsearch() Line 3096  pkgsearch()
3096   local state   local state
3097   local descriptiom   local descriptiom
3098   local homepage   local homepage
3099     local license
3100   local i   local i
3101   local all_installed   local all_installed
3102   local ipver   local ipver
# Line 2892  pkgsearch() Line 3133  pkgsearch()
3133   state="$(get_value_from_magefile STATE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3134   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3135   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3136     license="$(get_value_from_magefile LICENSE ${magefile})"
3137    
3138   # all installed   # all installed
3139   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3140   do   do
3141   ipver="$(magename2pver ${i})"   ipver="$(magename2pver ${i})"
3142   ipbuild="$(magename2pbuild ${i})"   ipbuild="$(magename2pbuild ${i})"
3143    
3144   if [[ -z ${all_installed} ]]   if [[ -z ${all_installed} ]]
3145   then   then
3146   all_installed="${ipver}-${ipbuild}"   all_installed="${ipver}-${ipbuild}"
# Line 2907  pkgsearch() Line 3149  pkgsearch()
3149   fi   fi
3150   done   done
3151   [[ -z ${all_installed} ]] && all_installed="none"   [[ -z ${all_installed} ]] && all_installed="none"
3152    
3153   case ${state} in   case ${state} in
3154   stable) state=${COLGREEN}"[s] ";;   stable) state=${COLGREEN}"[s] ";;
3155   testing) state=${COLYELLOW}"[t] ";;   testing) state=${COLYELLOW}"[t] ";;
# Line 2931  pkgsearch() Line 3173  pkgsearch()
3173   "") continue;;   "") continue;;
3174   esac   esac
3175    
3176   deps="${deps} $(basename ${dep%-*})"   if [[ -z ${deps} ]]
3177     then
3178     deps="$(basename ${dep%-*})"
3179     else
3180     deps="${deps} $(basename ${dep%-*})"
3181     fi
3182   done << EOF   done << EOF
3183  ${depsfull}  ${depsfull}
3184  EOF  EOF
# Line 2942  EOF Line 3189  EOF
3189   "") continue;;   "") continue;;
3190   esac   esac
3191    
3192   sdeps="${sdeps} $(basename ${dep%-*})"   if [[ -z ${sdeps} ]]
3193     then
3194     sdeps="$(basename ${dep%-*})"
3195     else
3196     sdeps="${sdeps} $(basename ${dep%-*})"
3197     fi
3198   done << EOF   done << EOF
3199  ${sdepsfull}  ${sdepsfull}
3200  EOF  EOF
# Line 2952  EOF Line 3204  EOF
3204   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3205   echo "      Description: ${description}"   echo "      Description: ${description}"
3206   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3207   echo "      Depends: ${deps}"   if [[ ! -z ${license} ]]
3208     then
3209     echo "      License:  ${license}"
3210     fi
3211     echo "      Depends:  ${deps}"
3212   echo "      SDepends: ${sdeps}"   echo "      SDepends: ${sdeps}"
3213   echo   echo
3214    
# Line 2992  export_inherits() Line 3248  export_inherits()
3248   eval "${functions}() { ${include}_${functions} ; }"   eval "${functions}() { ${include}_${functions} ; }"
3249    
3250   # debug   # debug
3251   [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"   mqueryfeature "debug" && typeset -f "${functions}"
3252    
3253   shift   shift
3254   done   done
# Line 3069  EOF Line 3325  EOF
3325  need_busybox_support()  need_busybox_support()
3326  {  {
3327   local cmd   local cmd
3328     local busybox
3329   cmd="$1"   cmd="$1"
3330    
3331   if [[ -x /bin/busybox ]]   for busybox in {,/usr}/bin/busybox
3332   then   do
3333   if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]   if [[ -x ${busybox} ]]
3334   then   then
3335   # needs busybox support   if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3336   return 0   then
3337   else   # needs busybox support
3338   # no busybox   return 0
3339   return 1   fi
3340   fi   fi
3341   fi   done
3342    
3343     # no busybox
3344     return 1
3345  }  }
3346    
3347  # busybox_filter_wget_options ${wget_opts}  # busybox_filter_wget_options ${wget_opts}
# Line 3116  busybox_filter_wget_options() Line 3376  busybox_filter_wget_options()
3376   echo "${opts}"   echo "${opts}"
3377   fi   fi
3378  }  }
3379    
3380    have_root_privileges()
3381    {
3382     local retval
3383    
3384     if [[ $(id -u) = 0 ]]
3385     then
3386     retval=0
3387     else
3388     retval=1
3389     fi
3390    
3391     return ${retval}
3392    }
3393    
3394    known_mage_feature()
3395    {
3396     local feature="$1"
3397     local retval
3398    
3399     case "${feature}" in
3400     autosvc|!autosvc) retval=0 ;;
3401     buildlog|!buildlog) retval=0 ;;
3402     ccache|!ccache) retval=0 ;;
3403     check|!check) retval=0 ;;
3404     compressdoc|!compressdoc) retval=0 ;;
3405     debug|!debug) retval=0 ;;
3406     distcc|!distcc) retval=0 ;;
3407     icecc|!icecc) retval=0 ;;
3408     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3409     libtool|!libtool) retval=0 ;;
3410     linuxsymlink|!linuxsymlink) retval=0 ;;
3411     multilib|!multilib) reval=0 ;;
3412     pkgbuild|!pkgbuild) retval=0 ;;
3413     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3414     pkgmetadata|!pkgmetadata) retval=0 ;;
3415     purge|!purge) retval=0 ;;
3416     qalint|!qalint) retval=0 ;;
3417     regentree|!regentree) retval=0 ;;
3418     resume|!resume) retval=0 ;;
3419     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3420     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3421     static|!static) retval=0 ;;
3422     stepbystep|!stepbystep) retval=0 ;;
3423     strip|!strip) retval=0 ;;
3424     verbose|!verbose) retval=0 ;;
3425     *) retval=1 ;;
3426     esac
3427    
3428     return "${retval}"
3429    }
3430    
3431    load_mage_features()
3432    {
3433     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3434     do
3435     FVERBOSE=off msetfeature ${i}
3436     done
3437    }
3438    
3439    msetfeature()
3440    {
3441     local feature
3442     local count
3443     local i
3444     local found
3445    
3446     for feature in $@
3447     do
3448     found=0
3449     count="${#MAGE_FEATURES_CURRENT[*]}"
3450    
3451     if ! known_mage_feature "${feature}"
3452     then
3453     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3454     return 3
3455     fi
3456    
3457     for ((i=0; i<count; i++))
3458     do
3459     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3460     then
3461     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3462     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3463     found=1
3464     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3465     then
3466     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3467     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3468     found=1
3469     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3470     then
3471     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3472     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3473     found=1
3474     fi
3475     done
3476    
3477     # if the feature was not found after proccessing the whole array
3478     # it was not declared. in this case enable it
3479     if [[ ${found} = 0 ]]
3480     then
3481     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3482     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3483     fi
3484    
3485     export MAGE_FEATURE_CURRENT
3486     done
3487    }
3488    
3489    mqueryfeature()
3490    {
3491     local feature="$1"
3492     local retval=1
3493     local i
3494    
3495     if known_mage_feature "${feature}"
3496     then
3497     for i in ${MAGE_FEATURES_CURRENT[*]}
3498     do
3499     if [[ ${i} = ${feature} ]]
3500     then
3501     retval=0
3502     break # found break here
3503     fi
3504     done
3505     else
3506     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3507     retval=3
3508     fi
3509    
3510     return ${retval}
3511    }
3512    
3513    mprintfeatures()
3514    {
3515     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3516     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3517     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3518    }

Legend:
Removed from v.1273  
changed lines
  Added in v.2613