Magellan Linux

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

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

revision 1658 by niro, Sat Jan 14 00:00:53 2012 UTC revision 2232 by niro, Wed Oct 16 09:28:00 2013 UTC
# Line 46  mchecksum() Line 46  mchecksum()
46   local method   local method
47   local cmd   local cmd
48   local retval   local retval
49     local sum
50     local dest
51    
52   # very basic getops   # very basic getops
53   for i in $*   for i in $*
# Line 72  mchecksum() Line 74  mchecksum()
74   if [[ -d ${rundir} ]]   if [[ -d ${rundir} ]]
75   then   then
76   pushd ${rundir} &> /dev/null   pushd ${rundir} &> /dev/null
77   # be verbose here  
78   ${cmd} -c ${file} #&> /dev/null   # all file must be non-zero
79   retval="$?"   retval=0
80     while read sum dest
81     do
82     if [ ! -s ${dest} ]
83     then
84     echo "${dest}: file is empty ;("
85     retval=127
86     fi
87     done < ${file}
88     if [[ ${retval} != 127 ]]
89     then
90     # be verbose here
91     ${cmd} -c ${file} #&> /dev/null
92     retval="$?"
93     fi
94    
95   popd &> /dev/null   popd &> /dev/null
96   else   else
97   retval=1   retval=1
# Line 102  mcheckemptydir() Line 119  mcheckemptydir()
119   return ${retval}   return ${retval}
120  }  }
121    
122    unpack_package()
123    {
124     local magefile="$1"
125     local pkg
126     local pkgtype
127     local tar_opts
128    
129     pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"
130     pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
131    
132     xtitle "[ Unpacking ${pkg} ]"
133    
134     # abort on virtual pkg
135     if [[ ${pkgtype} = virtual ]]
136     then
137     echo -ne " ${COLBLUE}---${COLDEFAULT}"
138     echo " !unpack virtual ${pkg/.${PKGSUFFIX}/} ... "
139     continue
140     fi
141    
142     # abort on sources pkg
143     if [[ ${pkgtype} = sources ]]
144     then
145     echo -ne " ${COLBLUE}---${COLDEFAULT}"
146     echo " !unpack sources ${pkg/.${PKGSUFFIX}/} ... "
147     continue
148     fi
149    
150     # busybox?
151     if need_busybox_support tar
152     then
153     tar_opts="xjf"
154     else
155     tar_opts="xjmf"
156     fi
157    
158     echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkg} ... "
159     tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"
160    }
161    
162  unpack_packages()  unpack_packages()
163  {  {
164   local list="$@"   local list="$@"
165   local magefile   local magefile
  local pkg  
  local pkgtype  
166   local count_current   local count_current
167   local count_total   local count_total
168   local tar_opts   local tar_opts
# Line 120  unpack_packages() Line 175  unpack_packages()
175    
176   for magefile in ${list}   for magefile in ${list}
177   do   do
178   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   unpack_package "${magefile}"
  pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"  
   
179   (( 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}"  
180   done   done
181    
182   # add a crlf for a better view   # add a crlf for a better view
# Line 171  fix_mtime() Line 196  fix_mtime()
196   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
197   touch \   touch \
198   --no-create \   --no-create \
199     --no-dereference \
200   --time=mtime \   --time=mtime \
201   --reference "${reference}" \   --reference="${reference}" \
202   "${pathto}"   "${pathto}"
203    
204   echo "${mtime}"   echo "${mtime}"
# Line 414  install_symlinks() Line 440  install_symlinks()
440    
441   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
442    
443  # # fix mtime and db   # fix mtime and db
444  # fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
445  # "${pathto}" \   "${pathto}" \
446  # "${posix}" \   "${posix}" \
447  # "${link}" \   "${link}" \
448  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
449  # "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
450    
451   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
452    
# Line 807  compare_mtime() Line 833  compare_mtime()
833    
834   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
835    
836   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
837   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
838   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  
839    
840   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
841    
# Line 1565  syncmage_tarball() Line 1580  syncmage_tarball()
1580    
1581   for mirr in ${MIRRORS}   for mirr in ${MIRRORS}
1582   do   do
1583   # path without distribution   # path without distribution
1584   mymirr="${mirr%/*}"   # (only for stable|testing|unstable and not DISTROTAG)
1585     case ${mirr##*/} in
1586     stable|testing|unstable) mymirr="${mirr%/*}";;
1587     *) mymirr="${mirr}";;
1588     esac
1589    
1590   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1591   echo "fetching latest md5 from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
# Line 1611  syncmage_tarball() Line 1630  syncmage_tarball()
1630   then   then
1631   if ! mcheckemptydir ${MAGEDIR}   if ! mcheckemptydir ${MAGEDIR}
1632   then   then
1633   find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xarg --no-run-if-empty rm -r   find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1634   fi   fi
1635   else   else
1636   rm -rf ${MAGEDIR}   rm -rf ${MAGEDIR}
# Line 1769  get_highest_magefile() Line 1788  get_highest_magefile()
1788   then   then
1789   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1790   #for debug only   #for debug only
1791   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1792   fi   fi
1793   done   done
1794    
# Line 1876  count_protected_files() Line 1895  count_protected_files()
1895   local filename="${file##*/}"   local filename="${file##*/}"
1896   local count   local count
1897   local output   local output
1898     local oldprotected
1899   local i   local i
1900     local x
1901    
1902     # hack; do not honor a global set IFS like '§'
1903     local IFS
1904    
1905   declare -i count=0   count=0
1906    
1907   # check if there are already protected files   # check if there are already protected files
1908   for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |   for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1909   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1910   sort -t'%' -k3 -k2 | cut -f1 -d'%')   sort -t'%' -k3 -k2 | cut -f1 -d'%')
1911   do   do
1912   count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")   count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1913   done   done
1914   (( count ++ ))  
1915     # convert 0001 -> 1; 0120 -> 120 etc
1916     # use bash internal base functions to this task
1917     x="$((10#${count}))"
1918     for (( i=0; i<x; i++ ))
1919     do
1920     if [[ ${count:${i}:1} != 0 ]]
1921     then
1922     count="${count:${i}}"
1923     break
1924     fi
1925     done
1926    
1927     count="$(( ${count}+1 ))"
1928    
1929   # fill output up with zeros   # fill output up with zeros
1930   for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done   for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
# Line 2677  mage_install() Line 2714  mage_install()
2714   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2715   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2716   then   then
2717     unpack_package "${magefile}"
2718   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
2719   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2720   fi   fi
# Line 3108  pkgsearch() Line 3146  pkgsearch()
3146   "") continue;;   "") continue;;
3147   esac   esac
3148    
3149   deps="${deps} $(basename ${dep%-*})"   if [[ -z ${deps} ]]
3150     then
3151     deps="$(basename ${dep%-*})"
3152     else
3153     deps="${deps} $(basename ${dep%-*})"
3154     fi
3155   done << EOF   done << EOF
3156  ${depsfull}  ${depsfull}
3157  EOF  EOF
# Line 3119  EOF Line 3162  EOF
3162   "") continue;;   "") continue;;
3163   esac   esac
3164    
3165   sdeps="${sdeps} $(basename ${dep%-*})"   if [[ -z ${sdeps} ]]
3166     then
3167     sdeps="$(basename ${dep%-*})"
3168     else
3169     sdeps="${sdeps} $(basename ${dep%-*})"
3170     fi
3171   done << EOF   done << EOF
3172  ${sdepsfull}  ${sdepsfull}
3173  EOF  EOF
# Line 3133  EOF Line 3181  EOF
3181   then   then
3182   echo "      License:  ${license}"   echo "      License:  ${license}"
3183   fi   fi
3184   echo "      Depends: ${deps}"   echo "      Depends:  ${deps}"
3185   echo "      SDepends: ${sdeps}"   echo "      SDepends: ${sdeps}"
3186   echo   echo
3187    
# Line 3250  EOF Line 3298  EOF
3298  need_busybox_support()  need_busybox_support()
3299  {  {
3300   local cmd   local cmd
3301     local busybox
3302   cmd="$1"   cmd="$1"
3303    
3304   if [[ -x /bin/busybox ]]   for busybox in {,/usr}/bin/busybox
3305   then   do
3306   if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]   if [[ -x ${busybox} ]]
3307   then   then
3308   # needs busybox support   if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3309   return 0   then
3310     # needs busybox support
3311     return 0
3312     fi
3313   fi   fi
3314   fi   done
3315    
3316   # no busybox   # no busybox
3317   return 1   return 1
# Line 3316  known_mage_feature() Line 3368  known_mage_feature()
3368  {  {
3369   local feature="$1"   local feature="$1"
3370   local retval   local retval
3371    
3372   case "${feature}" in   case "${feature}" in
3373   autosvc|!autosvc) retval=0 ;;   autosvc|!autosvc) retval=0 ;;
3374   buildlog|!buildlog) retval=0 ;;   buildlog|!buildlog) retval=0 ;;
# Line 3325  known_mage_feature() Line 3377  known_mage_feature()
3377   compressdoc|!compressdoc) retval=0 ;;   compressdoc|!compressdoc) retval=0 ;;
3378   debug|!debug) retval=0 ;;   debug|!debug) retval=0 ;;
3379   distcc|!distcc) retval=0 ;;   distcc|!distcc) retval=0 ;;
3380     icecc|!icecc) retval=0 ;;
3381   kernelsrcunpack|!kernelsrcunpack) retval=0 ;;   kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3382   libtool|!libtool) retval=0 ;;   libtool|!libtool) retval=0 ;;
3383   linuxsymlink|!linuxsymlink) retval=0 ;;   linuxsymlink|!linuxsymlink) retval=0 ;;
# Line 3430  mqueryfeature() Line 3483  mqueryfeature()
3483    
3484  mprintfeatures()  mprintfeatures()
3485  {  {
3486   echo "Global features:  ${MAGE_FEATURES_GLOBAL[*]}"   echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3487   echo "Local features:   ${MAGE_FEATURES[*]}"   echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3488   echo "Current features: ${MAGE_FEATURES_CURRENT[*]}"   echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3489  }  }

Legend:
Removed from v.1658  
changed lines
  Added in v.2232