Magellan Linux

Diff of /trunk/mage/usr/lib/mage/mage4.functions.sh

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

revision 1658 by niro, Sat Jan 14 00:00:53 2012 UTC revision 2225 by niro, Wed Oct 16 07:49:19 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-size OK"
85     else
86     echo "${dest}: file is empty ;("
87     retval=127
88     fi
89     done < ${file}
90     if [[ ${retval} != 127 ]]
91     then
92     # insert an empty line for cosmetic
93     echo
94    
95     # be verbose here
96     ${cmd} -c ${file} #&> /dev/null
97     retval="$?"
98     fi
99    
100   popd &> /dev/null   popd &> /dev/null
101   else   else
102   retval=1   retval=1
# Line 102  mcheckemptydir() Line 124  mcheckemptydir()
124   return ${retval}   return ${retval}
125  }  }
126    
127    unpack_package()
128    {
129     local magefile="$1"
130     local pkg
131     local pkgtype
132     local tar_opts
133    
134     pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"
135     pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
136    
137     xtitle "[ Unpacking ${pkg} ]"
138    
139     # abort on virtual pkg
140     if [[ ${pkgtype} = virtual ]]
141     then
142     echo -ne " ${COLBLUE}---${COLDEFAULT}"
143     echo " !unpack virtual ${pkg/.${PKGSUFFIX}/} ... "
144     continue
145     fi
146    
147     # abort on sources pkg
148     if [[ ${pkgtype} = sources ]]
149     then
150     echo -ne " ${COLBLUE}---${COLDEFAULT}"
151     echo " !unpack sources ${pkg/.${PKGSUFFIX}/} ... "
152     continue
153     fi
154    
155     # busybox?
156     if need_busybox_support tar
157     then
158     tar_opts="xjf"
159     else
160     tar_opts="xjmf"
161     fi
162    
163     echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkg} ... "
164     tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"
165    }
166    
167  unpack_packages()  unpack_packages()
168  {  {
169   local list="$@"   local list="$@"
170   local magefile   local magefile
  local pkg  
  local pkgtype  
171   local count_current   local count_current
172   local count_total   local count_total
173   local tar_opts   local tar_opts
# Line 120  unpack_packages() Line 180  unpack_packages()
180    
181   for magefile in ${list}   for magefile in ${list}
182   do   do
183   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   unpack_package "${magefile}"
  pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"  
   
184   (( 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}"  
185   done   done
186    
187   # add a crlf for a better view   # add a crlf for a better view
# Line 171  fix_mtime() Line 201  fix_mtime()
201   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
202   touch \   touch \
203   --no-create \   --no-create \
204     --no-dereference \
205   --time=mtime \   --time=mtime \
206   --reference "${reference}" \   --reference="${reference}" \
207   "${pathto}"   "${pathto}"
208    
209   echo "${mtime}"   echo "${mtime}"
# Line 414  install_symlinks() Line 445  install_symlinks()
445    
446   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
447    
448  # # fix mtime and db   # fix mtime and db
449  # fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
450  # "${pathto}" \   "${pathto}" \
451  # "${posix}" \   "${posix}" \
452  # "${link}" \   "${link}" \
453  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
454  # "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
455    
456   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
457    
# Line 807  compare_mtime() Line 838  compare_mtime()
838    
839   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
840    
841   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
842   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
843   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  
844    
845   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
846    
# Line 1565  syncmage_tarball() Line 1585  syncmage_tarball()
1585    
1586   for mirr in ${MIRRORS}   for mirr in ${MIRRORS}
1587   do   do
1588   # path without distribution   # path without distribution
1589   mymirr="${mirr%/*}"   # (only for stable|testing|unstable and not DISTROTAG)
1590     case ${mirr##*/} in
1591     stable|testing|unstable) mymirr="${mirr%/*}";;
1592     *) mymirr="${mirr}";;
1593     esac
1594    
1595   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1596   echo "fetching latest md5 from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
# Line 1611  syncmage_tarball() Line 1635  syncmage_tarball()
1635   then   then
1636   if ! mcheckemptydir ${MAGEDIR}   if ! mcheckemptydir ${MAGEDIR}
1637   then   then
1638   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
1639   fi   fi
1640   else   else
1641   rm -rf ${MAGEDIR}   rm -rf ${MAGEDIR}
# Line 1769  get_highest_magefile() Line 1793  get_highest_magefile()
1793   then   then
1794   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1795   #for debug only   #for debug only
1796   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1797   fi   fi
1798   done   done
1799    
# Line 1876  count_protected_files() Line 1900  count_protected_files()
1900   local filename="${file##*/}"   local filename="${file##*/}"
1901   local count   local count
1902   local output   local output
1903     local oldprotected
1904   local i   local i
1905     local x
1906    
1907   declare -i count=0   # hack; do not honor a global set IFS like '§'
1908     local IFS
1909    
1910     count=0
1911    
1912   # check if there are already protected files   # check if there are already protected files
1913   for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |   for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1914   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1915   sort -t'%' -k3 -k2 | cut -f1 -d'%')   sort -t'%' -k3 -k2 | cut -f1 -d'%')
1916   do   do
1917   count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")   count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1918   done   done
1919   (( count ++ ))  
1920     # convert 0001 -> 1; 0120 -> 120 etc
1921     # use bash internal base functions to this task
1922     x="$((10#${count}))"
1923     for (( i=0; i<x; i++ ))
1924     do
1925     if [[ ${count:${i}:1} != 0 ]]
1926     then
1927     count="${count:${i}}"
1928     break
1929     fi
1930     done
1931    
1932     count="$(( ${count}+1 ))"
1933    
1934   # fill output up with zeros   # fill output up with zeros
1935   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 2719  mage_install()
2719   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2720   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2721   then   then
2722     unpack_package "${magefile}"
2723   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
2724   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2725   fi   fi
# Line 3108  pkgsearch() Line 3151  pkgsearch()
3151   "") continue;;   "") continue;;
3152   esac   esac
3153    
3154   deps="${deps} $(basename ${dep%-*})"   if [[ -z ${deps} ]]
3155     then
3156     deps="$(basename ${dep%-*})"
3157     else
3158     deps="${deps} $(basename ${dep%-*})"
3159     fi
3160   done << EOF   done << EOF
3161  ${depsfull}  ${depsfull}
3162  EOF  EOF
# Line 3119  EOF Line 3167  EOF
3167   "") continue;;   "") continue;;
3168   esac   esac
3169    
3170   sdeps="${sdeps} $(basename ${dep%-*})"   if [[ -z ${sdeps} ]]
3171     then
3172     sdeps="$(basename ${dep%-*})"
3173     else
3174     sdeps="${sdeps} $(basename ${dep%-*})"
3175     fi
3176   done << EOF   done << EOF
3177  ${sdepsfull}  ${sdepsfull}
3178  EOF  EOF
# Line 3133  EOF Line 3186  EOF
3186   then   then
3187   echo "      License:  ${license}"   echo "      License:  ${license}"
3188   fi   fi
3189   echo "      Depends: ${deps}"   echo "      Depends:  ${deps}"
3190   echo "      SDepends: ${sdeps}"   echo "      SDepends: ${sdeps}"
3191   echo   echo
3192    
# Line 3250  EOF Line 3303  EOF
3303  need_busybox_support()  need_busybox_support()
3304  {  {
3305   local cmd   local cmd
3306     local busybox
3307   cmd="$1"   cmd="$1"
3308    
3309   if [[ -x /bin/busybox ]]   for busybox in {,/usr}/bin/busybox
3310   then   do
3311   if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]   if [[ -x ${busybox} ]]
3312   then   then
3313   # needs busybox support   if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3314   return 0   then
3315     # needs busybox support
3316     return 0
3317     fi
3318   fi   fi
3319   fi   done
3320    
3321   # no busybox   # no busybox
3322   return 1   return 1
# Line 3316  known_mage_feature() Line 3373  known_mage_feature()
3373  {  {
3374   local feature="$1"   local feature="$1"
3375   local retval   local retval
3376    
3377   case "${feature}" in   case "${feature}" in
3378   autosvc|!autosvc) retval=0 ;;   autosvc|!autosvc) retval=0 ;;
3379   buildlog|!buildlog) retval=0 ;;   buildlog|!buildlog) retval=0 ;;
# Line 3325  known_mage_feature() Line 3382  known_mage_feature()
3382   compressdoc|!compressdoc) retval=0 ;;   compressdoc|!compressdoc) retval=0 ;;
3383   debug|!debug) retval=0 ;;   debug|!debug) retval=0 ;;
3384   distcc|!distcc) retval=0 ;;   distcc|!distcc) retval=0 ;;
3385     icecc|!icecc) retval=0 ;;
3386   kernelsrcunpack|!kernelsrcunpack) retval=0 ;;   kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3387   libtool|!libtool) retval=0 ;;   libtool|!libtool) retval=0 ;;
3388   linuxsymlink|!linuxsymlink) retval=0 ;;   linuxsymlink|!linuxsymlink) retval=0 ;;
# Line 3430  mqueryfeature() Line 3488  mqueryfeature()
3488    
3489  mprintfeatures()  mprintfeatures()
3490  {  {
3491   echo "Global features:  ${MAGE_FEATURES_GLOBAL[*]}"   echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3492   echo "Local features:   ${MAGE_FEATURES[*]}"   echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3493   echo "Current features: ${MAGE_FEATURES_CURRENT[*]}"   echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3494  }  }

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