Magellan Linux

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

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

revision 1599 by niro, Fri Dec 30 10:07:18 2011 UTC revision 1963 by niro, Fri Oct 26 21:14:51 2012 UTC
# Line 66  mchecksum() Line 66  mchecksum()
66   case ${method} in   case ${method} in
67   md5) cmd="md5sum" ;;   md5) cmd="md5sum" ;;
68   sha256) cmd="sha256sum" ;;   sha256) cmd="sha256sum" ;;
69   *) die "mchecksum(): unkown method '${method}'" ;;   *) die "mchecksum(): unknown method '${method}'" ;;
70   esac   esac
71    
72   if [[ -d ${rundir} ]]   if [[ -d ${rundir} ]]
73   then   then
74   pushd ${rundir} &> /dev/null   pushd ${rundir} &> /dev/null
75   ${cmd} -c ${file} &> /dev/null   # be verbose here
76     ${cmd} -c ${file} #&> /dev/null
77   retval="$?"   retval="$?"
78   popd &> /dev/null   popd &> /dev/null
79   else   else
# Line 82  mchecksum() Line 83  mchecksum()
83   return "${retval}"   return "${retval}"
84  }  }
85    
86    mcheckemptydir()
87    {
88     local dir="$1"
89     local retval=1
90    
91     if [[ ! -d ${dir} ]]
92     then
93     echo "mcheckemptydir(): '${dir}' is not a directory!"
94     retval=3
95     else
96     shopt -s nullglob dotglob
97     files=( ${dir}/* )
98     (( ${#files[*]} )) || retval=0
99     shopt -u nullglob dotglob
100     fi
101    
102     return ${retval}
103    }
104    
105  unpack_packages()  unpack_packages()
106  {  {
107   local list="$@"   local list="$@"
# Line 151  fix_mtime() Line 171  fix_mtime()
171   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
172   touch \   touch \
173   --no-create \   --no-create \
174     --no-dereference \
175   --time=mtime \   --time=mtime \
176   --reference "${reference}" \   --reference="${reference}" \
177   "${pathto}"   "${pathto}"
178    
179   echo "${mtime}"   echo "${mtime}"
# Line 394  install_symlinks() Line 415  install_symlinks()
415    
416   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
417    
418  # # fix mtime and db   # fix mtime and db
419  # fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
420  # "${pathto}" \   "${pathto}" \
421  # "${posix}" \   "${posix}" \
422  # "${link}" \   "${link}" \
423  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
424  # "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
425    
426   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
427    
# Line 787  compare_mtime() Line 808  compare_mtime()
808    
809   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
810    
811   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
812   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
813   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  
814    
815   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
816    
# Line 1401  mdownload() Line 1411  mdownload()
1411   real_uris="$(convertmirrors ${uri})"   real_uris="$(convertmirrors ${uri})"
1412    
1413   # verbose or not   # verbose or not
1414   mqueryfeature "!verbose" && wget_opts="--quiet"   mqueryfeature "!verbose" && wget_opts+=" --quiet"
1415    
1416   # filter wget options if busybox was found   # filter wget options if busybox was found
1417   wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"   wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1418    
1419   # create outputdir   # create outputdir
1420   [[ ! -d ${outputdir} ]] && install -d "${outputdir}"   [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
# Line 1545  syncmage_tarball() Line 1555  syncmage_tarball()
1555    
1556   for mirr in ${MIRRORS}   for mirr in ${MIRRORS}
1557   do   do
1558   # path without distribution   # path without distribution
1559   mymirr="${mirr%/*}"   # (only for stable|testing|unstable and not DISTROTAG)
1560     case ${mirr##*/} in
1561     stable|testing|unstable) mymirr="${mirr%/*}";;
1562     *) mymirr="${mirr}";;
1563     esac
1564    
1565   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1566   echo "fetching latest md5 from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
# Line 1579  syncmage_tarball() Line 1593  syncmage_tarball()
1593   else   else
1594   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1595   echo -n "checking md5sum... "   echo -n "checking md5sum... "
1596   ( 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"
1597   fi   fi
1598    
1599   if [[ -d ${MAGEDIR} ]]   if [[ -d ${MAGEDIR} ]]
1600   then   then
1601   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1602   echo "cleaning old mage-tree ${MAGEDIR}..."   echo "cleaning old mage-tree ${MAGEDIR}..."
1603   rm -rf ${MAGEDIR}   # honor mountpoints and empty dirs
1604     if mountpoint -q ${MAGEDIR}
1605     then
1606     if ! mcheckemptydir ${MAGEDIR}
1607     then
1608     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1609     fi
1610     else
1611     rm -rf ${MAGEDIR}
1612     fi
1613   fi   fi
1614    
1615   if need_busybox_support tar   if need_busybox_support tar
# Line 1645  xtitleclean() Line 1668  xtitleclean()
1668  }  }
1669    
1670    
1671  # cuts full pathnames or versionized names down to basename  # unused?
1672  choppkgname()  #
1673  {  # # cuts full pathnames or versionized names down to basename
1674   #we want this only if full name was used  # choppkgname()
1675   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1676   then  # #we want this only if full name was used
1677   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1678   #ARCH comes from ${MAGERC}  # then
1679   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1680    # #ARCH comes from ${MAGERC}
1681    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1682    #
1683    # #cuts version number
1684    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1685    # fi
1686    # }
1687    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1688    
1689  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1690  # $1=pname  # $1=pname
# Line 1844  count_protected_files() Line 1870  count_protected_files()
1870   local filename="${file##*/}"   local filename="${file##*/}"
1871   local count   local count
1872   local output   local output
1873     local oldprotected
1874   local i   local i
1875     local x
1876    
1877   declare -i count=0   # hack; do not honor a global set IFS like '§'
1878     local IFS
1879    
1880     count=0
1881    
1882   # check if there are already protected files   # check if there are already protected files
1883   for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |   for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1884   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1885   sort -t'%' -k3 -k2 | cut -f1 -d'%')   sort -t'%' -k3 -k2 | cut -f1 -d'%')
1886   do   do
1887   count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")   count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1888     done
1889    
1890     # convert 0001 -> 1; 0120 -> 120 etc
1891     # use bash internal base functions to this task
1892     x="$((10#${count}))"
1893     for (( i=0; i<x; i++ ))
1894     do
1895     if [[ ${count:${i}:1} != 0 ]]
1896     then
1897     count="${count:${i}}"
1898     break
1899     fi
1900   done   done
1901   (( count ++ ))  
1902     count="$(( ${count}+1 ))"
1903    
1904   # fill output up with zeros   # fill output up with zeros
1905   for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done   for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
# Line 2759  md5sum_packages() Line 2803  md5sum_packages()
2803   then   then
2804   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2805   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2806   ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2807   else   else
2808   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2809   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2999  pkgsearch() Line 3043  pkgsearch()
3043   local state   local state
3044   local descriptiom   local descriptiom
3045   local homepage   local homepage
3046     local license
3047   local i   local i
3048   local all_installed   local all_installed
3049   local ipver   local ipver
# Line 3035  pkgsearch() Line 3080  pkgsearch()
3080   state="$(get_value_from_magefile STATE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3081   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3082   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3083     license="$(get_value_from_magefile LICENSE ${magefile})"
3084    
3085   # all installed   # all installed
3086   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3087   do   do
3088   ipver="$(magename2pver ${i})"   ipver="$(magename2pver ${i})"
3089   ipbuild="$(magename2pbuild ${i})"   ipbuild="$(magename2pbuild ${i})"
3090    
3091   if [[ -z ${all_installed} ]]   if [[ -z ${all_installed} ]]
3092   then   then
3093   all_installed="${ipver}-${ipbuild}"   all_installed="${ipver}-${ipbuild}"
# Line 3050  pkgsearch() Line 3096  pkgsearch()
3096   fi   fi
3097   done   done
3098   [[ -z ${all_installed} ]] && all_installed="none"   [[ -z ${all_installed} ]] && all_installed="none"
3099    
3100   case ${state} in   case ${state} in
3101   stable) state=${COLGREEN}"[s] ";;   stable) state=${COLGREEN}"[s] ";;
3102   testing) state=${COLYELLOW}"[t] ";;   testing) state=${COLYELLOW}"[t] ";;
# Line 3074  pkgsearch() Line 3120  pkgsearch()
3120   "") continue;;   "") continue;;
3121   esac   esac
3122    
3123   deps="${deps} $(basename ${dep%-*})"   if [[ -z ${deps} ]]
3124     then
3125     deps="$(basename ${dep%-*})"
3126     else
3127     deps="${deps} $(basename ${dep%-*})"
3128     fi
3129   done << EOF   done << EOF
3130  ${depsfull}  ${depsfull}
3131  EOF  EOF
# Line 3085  EOF Line 3136  EOF
3136   "") continue;;   "") continue;;
3137   esac   esac
3138    
3139   sdeps="${sdeps} $(basename ${dep%-*})"   if [[ -z ${sdeps} ]]
3140     then
3141     sdeps="$(basename ${dep%-*})"
3142     else
3143     sdeps="${sdeps} $(basename ${dep%-*})"
3144     fi
3145   done << EOF   done << EOF
3146  ${sdepsfull}  ${sdepsfull}
3147  EOF  EOF
# Line 3095  EOF Line 3151  EOF
3151   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3152   echo "      Description: ${description}"   echo "      Description: ${description}"
3153   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3154   echo "      Depends: ${deps}"   if [[ ! -z ${license} ]]
3155     then
3156     echo "      License:  ${license}"
3157     fi
3158     echo "      Depends:  ${deps}"
3159   echo "      SDepends: ${sdeps}"   echo "      SDepends: ${sdeps}"
3160   echo   echo
3161    
# Line 3212  EOF Line 3272  EOF
3272  need_busybox_support()  need_busybox_support()
3273  {  {
3274   local cmd   local cmd
3275     local busybox
3276   cmd="$1"   cmd="$1"
3277    
3278   if [[ -x /bin/busybox ]]   for busybox in {,/usr}/bin/busybox
3279   then   do
3280   if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]   if [[ -x ${busybox} ]]
3281   then   then
3282   # needs busybox support   if [[ $(readlink $(which ${cmd})) = ${busybox} ]]
3283   return 0   then
3284     # needs busybox support
3285     return 0
3286     fi
3287   fi   fi
3288   fi   done
3289    
3290   # no busybox   # no busybox
3291   return 1   return 1
# Line 3285  known_mage_feature() Line 3349  known_mage_feature()
3349   ccache|!ccache) retval=0 ;;   ccache|!ccache) retval=0 ;;
3350   check|!check) retval=0 ;;   check|!check) retval=0 ;;
3351   compressdoc|!compressdoc) retval=0 ;;   compressdoc|!compressdoc) retval=0 ;;
3352     debug|!debug) retval=0 ;;
3353   distcc|!distcc) retval=0 ;;   distcc|!distcc) retval=0 ;;
3354   kernelsrcunpack|!kernelsrcunpack) retval=0 ;;   kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3355   libtool|!libtool) retval=0 ;;   libtool|!libtool) retval=0 ;;
3356   linuxsymlink|!linuxsymlink) retval=0 ;;   linuxsymlink|!linuxsymlink) retval=0 ;;
3357   pkgbuild|!pkgbuild) retval=0 ;;   pkgbuild|!pkgbuild) retval=0 ;;
3358     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3359   purge|!purge) retval=0 ;;   purge|!purge) retval=0 ;;
3360   qalint|!qalint) retval=0 ;;   qalint|!qalint) retval=0 ;;
3361   regentree|!regentree) retval=0 ;;   regentree|!regentree) retval=0 ;;
3362   stepbystep|!stepbystep) retval=0 ;;   resume|!resume) retval=0 ;;
3363   srcpkgbuild|!srcpkgbuild) retval=0 ;;   srcpkgbuild|!srcpkgbuild) retval=0 ;;
3364   srcpkgtarball|!srcpkgtarball) retval=0 ;;   srcpkgtarball|!srcpkgtarball) retval=0 ;;
3365     static|!static) retval=0 ;;
3366     stepbystep|!stepbystep) retval=0 ;;
3367   strip|!strip) retval=0 ;;   strip|!strip) retval=0 ;;
3368     verbose|!verbose) retval=0 ;;
3369   *) retval=1 ;;   *) retval=1 ;;
3370   esac   esac
3371    
# Line 3305  known_mage_feature() Line 3374  known_mage_feature()
3374    
3375  load_mage_features()  load_mage_features()
3376  {  {
  echo -en "${COLBLUE}---${COLGREEN} Loading mage-features... ${COLDEFAULT}"  
3377   for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}   for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3378   do   do
3379   FVERBOSE=off msetfeature ${i}   FVERBOSE=off msetfeature ${i}
3380   done   done
   
  echo -e "${COLGREEN}done${COLDEFAULT}"  
3381  }  }
3382    
3383  msetfeature()  msetfeature()
# Line 3328  msetfeature() Line 3394  msetfeature()
3394    
3395   if ! known_mage_feature "${feature}"   if ! known_mage_feature "${feature}"
3396   then   then
3397   [[ ${FVERBOSE} = off ]] || echo "unkown feature ${feature}, ignoring it"   [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3398   return 3   return 3
3399   fi   fi
3400    
# Line 3381  mqueryfeature() Line 3447  mqueryfeature()
3447   fi   fi
3448   done   done
3449   else   else
3450     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3451   retval=3   retval=3
3452   fi   fi
3453    
# Line 3389  mqueryfeature() Line 3456  mqueryfeature()
3456    
3457  mprintfeatures()  mprintfeatures()
3458  {  {
3459   echo "Global features:  ${MAGE_FEATURES_GLOBAL[*]}"   echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3460   echo "Local features:   ${MAGE_FEATURES[*]}"   echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3461   echo "Current features: ${MAGE_FEATURES_CURRENT[*]}"   echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3462  }  }

Legend:
Removed from v.1599  
changed lines
  Added in v.1963