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 2720 by niro, Tue Jul 22 14:17:53 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
162   if [ ${count_total} -gt 1 ]; then echo; fi   if [ ${count_total} -gt 1 ]; then echo; fi
163  }  }
164    
   
165  # fix_mtime path/to/$mtime/reffile $pathto/file  # fix_mtime path/to/$mtime/reffile $pathto/file
166  # creates a given reference file and fixes given file  # creates a given reference file and fixes given file
167  # returns new mtime  # returns new mtime
# Line 151  fix_mtime() Line 174  fix_mtime()
174   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
175   touch \   touch \
176   --no-create \   --no-create \
177     --no-dereference \
178   --time=mtime \   --time=mtime \
179   --reference "${reference}" \   --reference="${reference}" \
180   "${pathto}"   "${pathto}"
181    
182   echo "${mtime}"   echo "${mtime}"
# Line 394  install_symlinks() Line 418  install_symlinks()
418    
419   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
420    
421  # # fix mtime and db   # fix mtime and db
422  # fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
423  # "${pathto}" \   "${pathto}" \
424  # "${posix}" \   "${posix}" \
425  # "${link}" \   "${link}" \
426  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
427  # "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
428    
429   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
430    
# Line 787  compare_mtime() Line 811  compare_mtime()
811    
812   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
813    
814   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
815   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
816   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  
817    
818   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
819    
# Line 1366  convertmirrors() Line 1379  convertmirrors()
1379   output+="${mirror}${addon}/${uri/${scheme}/}"   output+="${mirror}${addon}/${uri/${scheme}/}"
1380   done   done
1381   else   else
1382   output="${uri}"   output="${uri}"
1383   fi   fi
1384    
1385   echo "${output}"   echo "${output}"
# Line 1401  mdownload() Line 1414  mdownload()
1414   real_uris="$(convertmirrors ${uri})"   real_uris="$(convertmirrors ${uri})"
1415    
1416   # verbose or not   # verbose or not
1417   mqueryfeature "!verbose" && wget_opts="--quiet"   mqueryfeature "!verbose" && wget_opts+=" --quiet"
1418    
1419   # filter wget options if busybox was found   # filter wget options if busybox was found
1420   wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"   wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1421    
1422   # create outputdir   # create outputdir
1423   [[ ! -d ${outputdir} ]] && install -d "${outputdir}"   [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
# Line 1433  fetch_packages() Line 1446  fetch_packages()
1446  {  {
1447   local i   local i
1448   local list="$@"   local list="$@"
1449   local pkg   local pkgname
1450     local pkgfile
1451     local pcat
1452     local pname
1453   local mirr   local mirr
1454   local magefile   local magefile
1455   local md5file   local md5file
# Line 1441  fetch_packages() Line 1457  fetch_packages()
1457   local count_current   local count_current
1458   local count_total   local count_total
1459   local wget_opts   local wget_opts
1460     local fetching
1461    
1462   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1463    
# Line 1455  fetch_packages() Line 1472  fetch_packages()
1472    
1473   for magefile in ${list}   for magefile in ${list}
1474   do   do
1475   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1476     pkgfile="${pkgname}.${PKGSUFFIX}"
1477   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1478    
1479     pcat=$(magename2pcat ${magefile})
1480     pname=$(magename2pname ${magefile})
1481     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
1482    
1483   (( count_current++ ))   (( count_current++ ))
1484   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1485    
1486   # abort on virtual pkg   # abort on virtual pkg
1487   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1488   then   then
1489   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1490   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1491   continue   continue
1492   fi   fi
1493    
# Line 1473  fetch_packages() Line 1495  fetch_packages()
1495   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1496   then   then
1497   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1498   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1499   continue   continue
1500   fi   fi
1501    
1502   # abort if already exist   # check if FETCHING is required
1503   if [ -f ${PKGDIR}/${pkg} ]   if [ ! -f "${md5file}" ]
1504     then
1505     fetching=true
1506     else
1507     if mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 &> /dev/null
1508     then
1509     # md5's ok, no fetching required
1510     fetching=false
1511     else
1512     fetching=true
1513     fi
1514     fi
1515    
1516     if [[ ${fetching} = false ]]
1517   then   then
1518   echo -ne " ${COLBLUE}***${COLDEFAULT}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1519   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1520   continue   continue
1521     else
1522     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1523     echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1524     mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1525   fi   fi
1526    
1527   echo -ne " ${COLBLUE}***${COLDEFAULT}"   # sanity check, not really needed but to be sure
1528   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} ]  
1529   then   then
1530   die "Package '${pkg}' after download not found in '${PKGDIR}'"   die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1531   fi   fi
1532   done   done
1533    
# Line 1545  syncmage_tarball() Line 1582  syncmage_tarball()
1582    
1583   for mirr in ${MIRRORS}   for mirr in ${MIRRORS}
1584   do   do
1585   # path without distribution   # path without distribution
1586   mymirr="${mirr%/*}"   # (only for stable|testing|unstable and not DISTROTAG)
1587     case ${mirr##*/} in
1588     stable|testing|unstable) mymirr="${mirr%/*}";;
1589     *) mymirr="${mirr}";;
1590     esac
1591    
1592   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1593   echo "fetching latest md5 from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
# Line 1579  syncmage_tarball() Line 1620  syncmage_tarball()
1620   else   else
1621   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1622   echo -n "checking md5sum... "   echo -n "checking md5sum... "
1623   ( 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"
1624   fi   fi
1625    
1626   if [[ -d ${MAGEDIR} ]]   if [[ -d ${MAGEDIR} ]]
1627   then   then
1628   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1629   echo "cleaning old mage-tree ${MAGEDIR}..."   echo "cleaning old mage-tree ${MAGEDIR}..."
1630   rm -rf ${MAGEDIR}   # honor mountpoints and empty dirs
1631     if mountpoint -q ${MAGEDIR}
1632     then
1633     if ! mcheckemptydir ${MAGEDIR}
1634     then
1635     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1636     fi
1637     else
1638     rm -rf ${MAGEDIR}
1639     fi
1640   fi   fi
1641    
1642   if need_busybox_support tar   if need_busybox_support tar
# Line 1625  cleanpkg() Line 1675  cleanpkg()
1675   fi   fi
1676  }  }
1677    
1678  xtitle()  # unused?
1679  {  #
1680   if [[ ${TERM} = xterm ]]  # # cuts full pathnames or versionized names down to basename
1681   then  # choppkgname()
1682   echo -ne "\033]0;Mage: $1\007"  # {
1683   fi  # #we want this only if full name was used
1684   return 0  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1685  }  # then
1686    # #cuts ARCH and PBUILD
1687    # #ARCH comes from ${MAGERC}
1688    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1689    #
1690    # #cuts version number
1691    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1692    # fi
1693    # }
1694    
1695    
 xtitleclean()  
 {  
  if [[ ${TERM} = xterm ]]  
  then  
  echo -ne "\033]0;\007"  
  fi  
  return 0  
 }  
   
   
 # 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  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1697  # $1=pname  # $1=pname
1698  # ret 0=ok, 1=not_found  # ret 0=ok, 1=not_found
# Line 1737  get_highest_magefile() Line 1770  get_highest_magefile()
1770   then   then
1771   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1772   #for debug only   #for debug only
1773   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1774   fi   fi
1775   done   done
1776    
# Line 1844  count_protected_files() Line 1877  count_protected_files()
1877   local filename="${file##*/}"   local filename="${file##*/}"
1878   local count   local count
1879   local output   local output
1880     local oldprotected
1881   local i   local i
1882     local x
1883    
1884   declare -i count=0   # hack; do not honor a global set IFS like '§'
1885     local IFS
1886    
1887     count=0
1888    
1889   # check if there are already protected files   # check if there are already protected files
1890   for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |   for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1891   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1892   sort -t'%' -k3 -k2 | cut -f1 -d'%')   sort -t'%' -k3 -k2 | cut -f1 -d'%')
1893   do   do
1894   count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")   count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1895   done   done
1896   (( count ++ ))  
1897     # convert 0001 -> 1; 0120 -> 120 etc
1898     # use bash internal base functions to this task
1899     x="$((10#${count}))"
1900     for (( i=0; i<x; i++ ))
1901     do
1902     if [[ ${count:${i}:1} != 0 ]]
1903     then
1904     count="${count:${i}}"
1905     break
1906     fi
1907     done
1908    
1909     count="$(( ${count}+1 ))"
1910    
1911   # fill output up with zeros   # fill output up with zeros
1912   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 2212  sminclude()
2212   then   then
2213   for i in $*   for i in $*
2214   do   do
2215   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2216   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2217   done   done
2218   echo   [[ ${SILENT} = 1 ]] || echo
2219   fi   fi
2220  }  }
2221    
# Line 2191  is_newer_mage_version_available() Line 2242  is_newer_mage_version_available()
2242   fi   fi
2243  }  }
2244    
   
2245  # returns pname from pkgname  # returns pname from pkgname
2246  # pkgname2pname $PKGNAME  # pkgname2pname $PKGNAME
2247  pkgname2pname()  pkgname2pname()
# Line 2468  get_value_from_magefile() Line 2518  get_value_from_magefile()
2518   local SDEPEND   local SDEPEND
2519   local PROVIDE   local PROVIDE
2520   local PKGTYPE   local PKGTYPE
  local MAGE_TARGETS  
2521   local SPLIT_PACKAGE_BASE   local SPLIT_PACKAGE_BASE
2522   local preinstall   local preinstall
2523   local postinstall   local postinstall
# Line 2590  mage_install() Line 2639  mage_install()
2639   echo B:${pbuild}   echo B:${pbuild}
2640   fi   fi
2641    
2642   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} ]]  
2643   then   then
2644   # basic svn compat   # basic svn compat
2645   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
# Line 2645  mage_install() Line 2681  mage_install()
2681   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2682   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2683   then   then
2684     unpack_package "${magefile}"
2685   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
2686   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2687   fi   fi
# Line 2689  mage_install() Line 2726  mage_install()
2726   then   then
2727   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2728   echo -n "rebuilding environment ... "   echo -n "rebuilding environment ... "
2729   ${MLIBDIR}/env-rebuild.sh > /dev/null && \   ${MLIBDIR}/env-rebuild > /dev/null && \
2730   echo "done." || echo "failure."   echo "done." || echo "failure."
2731   unset MAGE_ENV_REBUILD   unset MAGE_ENV_REBUILD
2732   fi   fi
# Line 2733  md5sum_packages() Line 2770  md5sum_packages()
2770   pname=$(magename2pname ${magefile})   pname=$(magename2pname ${magefile})
2771   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2772   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2773   pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
2774   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2775    
2776   (( count_current++ ))   (( count_current++ ))
# Line 2743  md5sum_packages() Line 2780  md5sum_packages()
2780   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
2781   then   then
2782   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2783   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... "
2784   continue   continue
2785   fi   fi
2786    
# Line 2751  md5sum_packages() Line 2788  md5sum_packages()
2788   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
2789   then   then
2790   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2791   echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... "
2792   continue   continue
2793   fi   fi
2794    
# Line 2759  md5sum_packages() Line 2796  md5sum_packages()
2796   then   then
2797   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2798   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2799   ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2800   else   else
2801   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2802   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2799  uninstall_packages() Line 2836  uninstall_packages()
2836   pbuild=$(magename2pbuild ${pkg})   pbuild=$(magename2pbuild ${pkg})
2837   can_pcat="${pcat}"   can_pcat="${pcat}"
2838   can_pname="${pname}"   can_pname="${pname}"
2839    
2840   if [ -z "${can_ver_list}" ]   if [ -z "${can_ver_list}" ]
2841   then   then
2842   can_ver_list=" ${pver}-${pbuild}"   can_ver_list=" ${pver}-${pbuild}"
# Line 2954  mage_uninstall() Line 2991  mage_uninstall()
2991   then   then
2992   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2993   echo -n "rebuilding environment ... "   echo -n "rebuilding environment ... "
2994   ${MLIBDIR}/env-rebuild.sh > /dev/null && \   ${MLIBDIR}/env-rebuild > /dev/null && \
2995   echo "done." || echo "failure."   echo "done." || echo "failure."
2996   unset MAGE_ENV_REBUILD   unset MAGE_ENV_REBUILD
2997   fi   fi
# Line 2972  mage_uninstall() Line 3009  mage_uninstall()
3009   unset -f postremove   unset -f postremove
3010  }  }
3011    
3012    # rerun_pkgfunctions [method] pkg1 pkg2 pkg3
3013    rerun_pkgfunctions()
3014    {
3015     local method
3016     local list
3017     local pcat
3018     local pname
3019     local pver
3020     local pbuild
3021     local magefile
3022     local i
3023    
3024     # very basic getops
3025     case $1 in
3026     --method) shift; method="$1" ;;
3027     esac
3028     shift
3029     local list="$@"
3030    
3031     # sanity check
3032     case ${method} in
3033     preinstall|postinstall) ;;
3034     preremove|postremove) ;;
3035     *) die "rerun_pkgfunctions(): Unknown method '${method}'." ;;
3036     esac
3037    
3038     if [[ -n ${MROOT} ]]
3039     then
3040     echo -ne ${COLRED}
3041     echo "!! running in MROOT=${MROOT}"
3042     echo -ne ${COLDEFAULT}
3043     echo
3044     fi
3045    
3046     for pkg in ${list}
3047     do
3048     pcat=$(dep2pcat ${pkg})
3049     pname=$(magename2pname ${pkg})
3050     pver=$(magename2pver ${pkg})
3051     pbuild=$(magename2pbuild ${pkg})
3052     magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
3053    
3054     if [ -e ${magefile} ]
3055     then
3056     source ${magefile}
3057     if [ -n "$(typeset -f ${method})" ]
3058     then
3059     echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... "
3060     ${method}
3061     else
3062     echo "No ${method}() for pkg '${pkg}' defined. Doing nothing."
3063     fi
3064     unset -f preinstall postinstall preremove postremove
3065     else
3066     die "Magefile '${magefile}' does not exist."
3067     fi
3068     done
3069    }
3070    
3071  show_etc_update_mesg()  show_etc_update_mesg()
3072  {  {
3073   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
# Line 2999  pkgsearch() Line 3095  pkgsearch()
3095   local state   local state
3096   local descriptiom   local descriptiom
3097   local homepage   local homepage
3098     local license
3099   local i   local i
3100   local all_installed   local all_installed
3101   local ipver   local ipver
# Line 3035  pkgsearch() Line 3132  pkgsearch()
3132   state="$(get_value_from_magefile STATE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3133   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3134   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3135     license="$(get_value_from_magefile LICENSE ${magefile})"
3136    
3137   # all installed   # all installed
3138   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3139   do   do
3140   ipver="$(magename2pver ${i})"   ipver="$(magename2pver ${i})"
3141   ipbuild="$(magename2pbuild ${i})"   ipbuild="$(magename2pbuild ${i})"
3142    
3143   if [[ -z ${all_installed} ]]   if [[ -z ${all_installed} ]]
3144   then   then
3145   all_installed="${ipver}-${ipbuild}"   all_installed="${ipver}-${ipbuild}"
# Line 3050  pkgsearch() Line 3148  pkgsearch()
3148   fi   fi
3149   done   done
3150   [[ -z ${all_installed} ]] && all_installed="none"   [[ -z ${all_installed} ]] && all_installed="none"
3151    
3152   case ${state} in   case ${state} in
3153   stable) state=${COLGREEN}"[s] ";;   stable) state=${COLGREEN}"[s] ";;
3154   testing) state=${COLYELLOW}"[t] ";;   testing) state=${COLYELLOW}"[t] ";;
# Line 3074  pkgsearch() Line 3172  pkgsearch()
3172   "") continue;;   "") continue;;
3173   esac   esac
3174    
3175   deps="${deps} $(basename ${dep%-*})"   if [[ -z ${deps} ]]
3176     then
3177     deps="$(basename ${dep%-*})"
3178     else
3179     deps="${deps} $(basename ${dep%-*})"
3180     fi
3181   done << EOF   done << EOF
3182  ${depsfull}  ${depsfull}
3183  EOF  EOF
# Line 3085  EOF Line 3188  EOF
3188   "") continue;;   "") continue;;
3189   esac   esac
3190    
3191   sdeps="${sdeps} $(basename ${dep%-*})"   if [[ -z ${sdeps} ]]
3192     then
3193     sdeps="$(basename ${dep%-*})"
3194     else
3195     sdeps="${sdeps} $(basename ${dep%-*})"
3196     fi
3197   done << EOF   done << EOF
3198  ${sdepsfull}  ${sdepsfull}
3199  EOF  EOF
# Line 3095  EOF Line 3203  EOF
3203   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3204   echo "      Description: ${description}"   echo "      Description: ${description}"
3205   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3206   echo "      Depends: ${deps}"   if [[ ! -z ${license} ]]
3207     then
3208     echo "      License:  ${license}"
3209     fi
3210     echo "      Depends:  ${deps}"
3211   echo "      SDepends: ${sdeps}"   echo "      SDepends: ${sdeps}"
3212   echo   echo
3213    
# Line 3212  EOF Line 3324  EOF
3324  need_busybox_support()  need_busybox_support()
3325  {  {
3326   local cmd   local cmd
3327     local busybox
3328   cmd="$1"   cmd="$1"
3329    
3330   if [[ -x /bin/busybox ]]   for busybox in {,/usr}/bin/busybox
3331   then   do
3332   if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]   if [[ -x ${busybox} ]]
3333   then   then
3334   # needs busybox support   if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3335   return 0   then
3336     # needs busybox support
3337     return 0
3338     fi
3339   fi   fi
3340   fi   done
3341    
3342   # no busybox   # no busybox
3343   return 1   return 1
# Line 3278  known_mage_feature() Line 3394  known_mage_feature()
3394  {  {
3395   local feature="$1"   local feature="$1"
3396   local retval   local retval
3397    
3398   case "${feature}" in   case "${feature}" in
3399   autosvc|!autosvc) retval=0 ;;   autosvc|!autosvc) retval=0 ;;
3400   buildlog|!buildlog) retval=0 ;;   buildlog|!buildlog) retval=0 ;;
3401   ccache|!ccache) retval=0 ;;   ccache|!ccache) retval=0 ;;
3402   check|!check) retval=0 ;;   check|!check) retval=0 ;;
3403   compressdoc|!compressdoc) retval=0 ;;   compressdoc|!compressdoc) retval=0 ;;
3404     debug|!debug) retval=0 ;;
3405   distcc|!distcc) retval=0 ;;   distcc|!distcc) retval=0 ;;
3406     icecc|!icecc) retval=0 ;;
3407   kernelsrcunpack|!kernelsrcunpack) retval=0 ;;   kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3408   libtool|!libtool) retval=0 ;;   libtool|!libtool) retval=0 ;;
3409   linuxsymlink|!linuxsymlink) retval=0 ;;   linuxsymlink|!linuxsymlink) retval=0 ;;
3410     multilib|!multilib) reval=0 ;;
3411   pkgbuild|!pkgbuild) retval=0 ;;   pkgbuild|!pkgbuild) retval=0 ;;
3412     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3413     pkgmetadata|!pkgmetadata) retval=0 ;;
3414   purge|!purge) retval=0 ;;   purge|!purge) retval=0 ;;
3415   qalint|!qalint) retval=0 ;;   qalint|!qalint) retval=0 ;;
3416   regentree|!regentree) retval=0 ;;   regentree|!regentree) retval=0 ;;
3417   stepbystep|!stepbystep) retval=0 ;;   resume|!resume) retval=0 ;;
3418   srcpkgbuild|!srcpkgbuild) retval=0 ;;   srcpkgbuild|!srcpkgbuild) retval=0 ;;
3419   srcpkgtarball|!srcpkgtarball) retval=0 ;;   srcpkgtarball|!srcpkgtarball) retval=0 ;;
3420     static|!static) retval=0 ;;
3421     stepbystep|!stepbystep) retval=0 ;;
3422   strip|!strip) retval=0 ;;   strip|!strip) retval=0 ;;
3423     verbose|!verbose) retval=0 ;;
3424   *) retval=1 ;;   *) retval=1 ;;
3425   esac   esac
3426    
# Line 3305  known_mage_feature() Line 3429  known_mage_feature()
3429    
3430  load_mage_features()  load_mage_features()
3431  {  {
  echo -en "${COLBLUE}---${COLGREEN} Loading mage-features... ${COLDEFAULT}"  
3432   for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}   for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3433   do   do
3434   FVERBOSE=off msetfeature ${i}   FVERBOSE=off msetfeature ${i}
3435   done   done
   
  echo -e "${COLGREEN}done${COLDEFAULT}"  
3436  }  }
3437    
3438  msetfeature()  msetfeature()
# Line 3328  msetfeature() Line 3449  msetfeature()
3449    
3450   if ! known_mage_feature "${feature}"   if ! known_mage_feature "${feature}"
3451   then   then
3452   [[ ${FVERBOSE} = off ]] || echo "unkown feature ${feature}, ignoring it"   [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3453   return 3   return 3
3454   fi   fi
3455    
# Line 3336  msetfeature() Line 3457  msetfeature()
3457   do   do
3458   if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]   if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3459   then   then
3460   [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled"   [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3461   MAGE_FEATURES_CURRENT[${i}]="${feature}"   MAGE_FEATURES_CURRENT[${i}]="${feature}"
3462   found=1   found=1
3463   elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]   elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3464   then   then
3465   [[ ${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}"
3466   MAGE_FEATURES_CURRENT[${i}]="${feature}"   MAGE_FEATURES_CURRENT[${i}]="${feature}"
3467   found=1   found=1
3468   elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]   elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3469   then   then
3470   [[ ${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}"
3471   MAGE_FEATURES_CURRENT[${i}]="${feature}"   MAGE_FEATURES_CURRENT[${i}]="${feature}"
3472   found=1   found=1
3473   fi   fi
# Line 3356  msetfeature() Line 3477  msetfeature()
3477   # it was not declared. in this case enable it   # it was not declared. in this case enable it
3478   if [[ ${found} = 0 ]]   if [[ ${found} = 0 ]]
3479   then   then
3480   [[ ${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}"
3481   MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )   MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3482   fi   fi
3483    
3484   export MAGE_FEATURE_CURRENT   export MAGE_FEATURES_CURRENT
3485   done   done
3486  }  }
3487    
# Line 3381  mqueryfeature() Line 3502  mqueryfeature()
3502   fi   fi
3503   done   done
3504   else   else
3505     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3506   retval=3   retval=3
3507   fi   fi
3508    
# Line 3389  mqueryfeature() Line 3511  mqueryfeature()
3511    
3512  mprintfeatures()  mprintfeatures()
3513  {  {
3514   echo "Global features:  ${MAGE_FEATURES_GLOBAL[*]}"   echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3515   echo "Local features:   ${MAGE_FEATURES[*]}"   echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3516   echo "Current features: ${MAGE_FEATURES_CURRENT[*]}"   echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3517  }  }

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