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 1590 by niro, Thu Dec 29 15:12:05 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$
   
 COLRED="\033[1;6m\033[31m"  
 COLGREEN="\033[1;6m\033[32m"  
 COLYELLOW="\033[1;6m\033[33m"  
 COLBLUE="\033[1;6m\033[34m"  
 COLMAGENTA="\033[1;6m\033[35m"  
 COLWHITE="\033[1;6m\033[37m"  
 COLGRAY="\033[0;6m\033[37m"  
 COLBOLD="\033[1m"  
 COLDEFAULT="\033[0m"  
   
 if [[ ${NOCOLORS} = true ]]  
 then  
  COLRED=""  
  COLGREEN=""  
  COLYELLOW=""  
  COLBLUE=""  
  COLMAGENTA=""  
  COLWHITE=""  
  COLGRAY=""  
  COLBOLD=""  
  COLDEFAULT=""  
 fi  
4    
5  mage_setup()  mage_setup()
6  {  {
# Line 46  mchecksum() Line 23  mchecksum()
23   local method   local method
24   local cmd   local cmd
25   local retval   local retval
26     local sum
27     local dest
28    
29   # very basic getops   # very basic getops
30   for i in $*   for i in $*
# Line 66  mchecksum() Line 45  mchecksum()
45   case ${method} in   case ${method} in
46   md5) cmd="md5sum" ;;   md5) cmd="md5sum" ;;
47   sha256) cmd="sha256sum" ;;   sha256) cmd="sha256sum" ;;
48   *) die "mchecksum(): unkown method '${method}'" ;;   *) die "mchecksum(): unknown method '${method}'" ;;
49   esac   esac
50    
51   if [[ -d ${rundir} ]]   if [[ -d ${rundir} ]]
52   then   then
53   pushd ${rundir} &> /dev/null   pushd ${rundir} &> /dev/null
54   ${cmd} -c ${file} &> /dev/null  
55   retval="$?"   # 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   popd &> /dev/null
73   else   else
74   retval=1   retval=1
# Line 82  mchecksum() Line 77  mchecksum()
77   return "${retval}"   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 100  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 151  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 394  install_symlinks() Line 419  install_symlinks()
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 787  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 1366  convertmirrors() Line 1380  convertmirrors()
1380   output+="${mirror}${addon}/${uri/${scheme}/}"   output+="${mirror}${addon}/${uri/${scheme}/}"
1381   done   done
1382   else   else
1383   output="${uri}"   output="${uri}"
1384   fi   fi
1385    
1386   echo "${output}"   echo "${output}"
# Line 1401  mdownload() Line 1415  mdownload()
1415   real_uris="$(convertmirrors ${uri})"   real_uris="$(convertmirrors ${uri})"
1416    
1417   # verbose or not   # verbose or not
1418   mqueryfeature "!verbose" && wget_opts="--quiet"   mqueryfeature "!verbose" && wget_opts+=" --quiet"
1419    
1420   # filter wget options if busybox was found   # filter wget options if busybox was found
1421   wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"   wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1422    
1423   # create outputdir   # create outputdir
1424   [[ ! -d ${outputdir} ]] && install -d "${outputdir}"   [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
# Line 1433  fetch_packages() Line 1447  fetch_packages()
1447  {  {
1448   local i   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 1441  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 1455  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 1473  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
1506     fetching=true
1507     else
1508     if mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 &> /dev/null
1509     then
1510     # md5's ok, no fetching required
1511     fetching=false
1512     else
1513     fetching=true
1514     fi
1515     fi
1516    
1517     if [[ ${fetching} = false ]]
1518   then   then
1519   echo -ne " ${COLBLUE}***${COLDEFAULT}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1520   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1521   continue   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   fi
1527    
1528   echo -ne " ${COLBLUE}***${COLDEFAULT}"   # sanity check, not really needed but to be sure
1529   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "   if [ ! -f ${PKGDIR}/${pkgfile} ]
  mdownload --uri "package://${pkg}" --dir "${PKGDIR}" || die "Could not download ${pkg}"  
  if [ ! -f ${PKGDIR}/${pkg} ]  
1530   then   then
1531   die "Package '${pkg}' after download not found in '${PKGDIR}'"   die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1532   fi   fi
1533   done   done
1534    
# Line 1545  syncmage_tarball() Line 1583  syncmage_tarball()
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} ..."
# Line 1579  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 1625  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  
 }  
   
1695    
 # cuts full pathnames or versionized 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")  
   
  #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 1737  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   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1775   fi   fi
1776   done   done
1777    
# Line 1844  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   declare -i count=0   # hack; do not honor a global set IFS like '§'
1886     local IFS
1887    
1888     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   done
1897   (( count ++ ))  
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
1909    
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 2161  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 2191  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 2468  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 2590  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}/.svn ]]  
  then  
  for i in ${SMAGESCRIPTSDIR}/*/${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}/.svn ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
# Line 2645  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 2689  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 2733  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 2743  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 2751  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 2759  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 2799  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 2954  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 2972  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 2999  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 3035  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 3050  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 3074  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 3085  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 3095  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 3212  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     # needs busybox support
3338     return 0
3339     fi
3340   fi   fi
3341   fi   done
3342    
3343   # no busybox   # no busybox
3344   return 1   return 1
# Line 3278  known_mage_feature() Line 3395  known_mage_feature()
3395  {  {
3396   local feature="$1"   local feature="$1"
3397   local retval   local retval
3398    
3399   case "${feature}" in   case "${feature}" in
3400   autosvc|!autosvc) retval=0 ;;   autosvc|!autosvc) retval=0 ;;
3401   buildlog|!buildlog) retval=0 ;;   buildlog|!buildlog) retval=0 ;;
3402   ccache|!ccache) retval=0 ;;   ccache|!ccache) retval=0 ;;
3403   check|!check) retval=0 ;;   check|!check) retval=0 ;;
3404   compressdoc|!compressdoc) retval=0 ;;   compressdoc|!compressdoc) retval=0 ;;
3405     debug|!debug) retval=0 ;;
3406   distcc|!distcc) retval=0 ;;   distcc|!distcc) retval=0 ;;
3407     icecc|!icecc) retval=0 ;;
3408   kernelsrcunpack|!kernelsrcunpack) retval=0 ;;   kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3409   libtool|!libtool) retval=0 ;;   libtool|!libtool) retval=0 ;;
3410   linuxsymlink|!linuxsymlink) retval=0 ;;   linuxsymlink|!linuxsymlink) retval=0 ;;
3411     multilib|!multilib) reval=0 ;;
3412   pkgbuild|!pkgbuild) retval=0 ;;   pkgbuild|!pkgbuild) retval=0 ;;
3413     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3414     pkgmetadata|!pkgmetadata) retval=0 ;;
3415   purge|!purge) retval=0 ;;   purge|!purge) retval=0 ;;
3416   qalint|!qalint) retval=0 ;;   qalint|!qalint) retval=0 ;;
3417   regentree|!regentree) retval=0 ;;   regentree|!regentree) retval=0 ;;
3418   stepbystep|!stepbystep) retval=0 ;;   resume|!resume) retval=0 ;;
3419   srcpkgbuild|!srcpkgbuild) retval=0 ;;   srcpkgbuild|!srcpkgbuild) retval=0 ;;
3420   srcpkgtarball|!srcpkgtarball) retval=0 ;;   srcpkgtarball|!srcpkgtarball) retval=0 ;;
3421     static|!static) retval=0 ;;
3422     stepbystep|!stepbystep) retval=0 ;;
3423   strip|!strip) retval=0 ;;   strip|!strip) retval=0 ;;
3424     verbose|!verbose) retval=0 ;;
3425   *) retval=1 ;;   *) retval=1 ;;
3426   esac   esac
3427    
# Line 3305  known_mage_feature() Line 3430  known_mage_feature()
3430    
3431  load_mage_features()  load_mage_features()
3432  {  {
  echo -en "${COLBLUE}---${COLGREEN} Loading mage-features... ${COLDEFAULT}"  
3433   for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}   for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3434   do   do
3435   FVERBOSE=off msetfeature ${i}   FVERBOSE=off msetfeature ${i}
3436   done   done
   
  echo -e "${COLGREEN}done${COLDEFAULT}"  
3437  }  }
3438    
3439  msetfeature()  msetfeature()
# Line 3328  msetfeature() Line 3450  msetfeature()
3450    
3451   if ! known_mage_feature "${feature}"   if ! known_mage_feature "${feature}"
3452   then   then
3453   [[ ${FVERBOSE} = off ]] || echo "unkown feature ${feature}, ignoring it"   [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3454   return 3   return 3
3455   fi   fi
3456    
# Line 3336  msetfeature() Line 3458  msetfeature()
3458   do   do
3459   if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]   if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3460   then   then
3461   [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled"   [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3462   MAGE_FEATURES_CURRENT[${i}]="${feature}"   MAGE_FEATURES_CURRENT[${i}]="${feature}"
3463   found=1   found=1
3464   elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]   elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3465   then   then
3466   [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!"   [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3467   MAGE_FEATURES_CURRENT[${i}]="${feature}"   MAGE_FEATURES_CURRENT[${i}]="${feature}"
3468   found=1   found=1
3469   elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]   elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3470   then   then
3471   [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!"   [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3472   MAGE_FEATURES_CURRENT[${i}]="${feature}"   MAGE_FEATURES_CURRENT[${i}]="${feature}"
3473   found=1   found=1
3474   fi   fi
# Line 3356  msetfeature() Line 3478  msetfeature()
3478   # it was not declared. in this case enable it   # it was not declared. in this case enable it
3479   if [[ ${found} = 0 ]]   if [[ ${found} = 0 ]]
3480   then   then
3481   [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!"   [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3482   MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )   MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3483   fi   fi
3484    
# Line 3381  mqueryfeature() Line 3503  mqueryfeature()
3503   fi   fi
3504   done   done
3505   else   else
3506     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3507   retval=3   retval=3
3508   fi   fi
3509    
# Line 3389  mqueryfeature() Line 3512  mqueryfeature()
3512    
3513  mprintfeatures()  mprintfeatures()
3514  {  {
3515   echo "Global features:  ${MAGE_FEATURES_GLOBAL[*]}"   echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3516   echo "Local features:   ${MAGE_FEATURES[*]}"   echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3517   echo "Current features: ${MAGE_FEATURES_CURRENT[*]}"   echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3518  }  }

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