Magellan Linux

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

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

revision 1628 by niro, Fri Jan 13 13:13:14 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   ${cmd} -c ${file} &> /dev/null  
78   retval="$?"   # all file must be non-zero
79     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 82  mchecksum() Line 105  mchecksum()
105   return "${retval}"   return "${retval}"
106  }  }
107    
108    mcheckemptydir()
109    {
110     local dir="$1"
111     local retval=1
112    
113     if [[ ! -d ${dir} ]]
114     then
115     echo "mcheckemptydir(): '${dir}' is not a directory!"
116     retval=3
117     else
118     shopt -s nullglob dotglob
119     files=( ${dir}/* )
120     (( ${#files[*]} )) || retval=0
121     shopt -u nullglob dotglob
122     fi
123    
124     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 100  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 151  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 394  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 787  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 1545  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 1579  syncmage_tarball() Line 1623  syncmage_tarball()
1623   else   else
1624   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1625   echo -n "checking md5sum... "   echo -n "checking md5sum... "
1626   ( 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"
1627   fi   fi
1628    
1629   if [[ -d ${MAGEDIR} ]]   if [[ -d ${MAGEDIR} ]]
1630   then   then
1631   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1632   echo "cleaning old mage-tree ${MAGEDIR}..."   echo "cleaning old mage-tree ${MAGEDIR}..."
1633   rm -rf ${MAGEDIR}   # honor mountpoints and empty dirs
1634     if mountpoint -q ${MAGEDIR}
1635     then
1636     if ! mcheckemptydir ${MAGEDIR}
1637     then
1638     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1639     fi
1640     else
1641     rm -rf ${MAGEDIR}
1642     fi
1643   fi   fi
1644    
1645   if need_busybox_support tar   if need_busybox_support tar
# Line 1645  xtitleclean() Line 1698  xtitleclean()
1698  }  }
1699    
1700    
1701  # cuts full pathnames or versionized names down to basename  # unused?
1702  choppkgname()  #
1703  {  # # cuts full pathnames or versionized names down to basename
1704   #we want this only if full name was used  # choppkgname()
1705   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1706   then  # #we want this only if full name was used
1707   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1708   #ARCH comes from ${MAGERC}  # then
1709   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1710    # #ARCH comes from ${MAGERC}
1711    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1712    #
1713    # #cuts version number
1714    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1715    # fi
1716    # }
1717    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1718    
1719  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1720  # $1=pname  # $1=pname
# Line 1737  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 1844  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 2645  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 2759  md5sum_packages() Line 2834  md5sum_packages()
2834   then   then
2835   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2836   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2837   ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2838   else   else
2839   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2840   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2999  pkgsearch() Line 3074  pkgsearch()
3074   local state   local state
3075   local descriptiom   local descriptiom
3076   local homepage   local homepage
3077     local license
3078   local i   local i
3079   local all_installed   local all_installed
3080   local ipver   local ipver
# Line 3035  pkgsearch() Line 3111  pkgsearch()
3111   state="$(get_value_from_magefile STATE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3112   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3113   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3114     license="$(get_value_from_magefile LICENSE ${magefile})"
3115    
3116   # all installed   # all installed
3117   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3118   do   do
3119   ipver="$(magename2pver ${i})"   ipver="$(magename2pver ${i})"
3120   ipbuild="$(magename2pbuild ${i})"   ipbuild="$(magename2pbuild ${i})"
3121    
3122   if [[ -z ${all_installed} ]]   if [[ -z ${all_installed} ]]
3123   then   then
3124   all_installed="${ipver}-${ipbuild}"   all_installed="${ipver}-${ipbuild}"
# Line 3050  pkgsearch() Line 3127  pkgsearch()
3127   fi   fi
3128   done   done
3129   [[ -z ${all_installed} ]] && all_installed="none"   [[ -z ${all_installed} ]] && all_installed="none"
3130    
3131   case ${state} in   case ${state} in
3132   stable) state=${COLGREEN}"[s] ";;   stable) state=${COLGREEN}"[s] ";;
3133   testing) state=${COLYELLOW}"[t] ";;   testing) state=${COLYELLOW}"[t] ";;
# Line 3074  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 3085  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 3095  EOF Line 3182  EOF
3182   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3183   echo "      Description: ${description}"   echo "      Description: ${description}"
3184   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3185   echo "      Depends: ${deps}"   if [[ ! -z ${license} ]]
3186     then
3187     echo "      License:  ${license}"
3188     fi
3189     echo "      Depends:  ${deps}"
3190   echo "      SDepends: ${sdeps}"   echo "      SDepends: ${sdeps}"
3191   echo   echo
3192    
# Line 3212  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 3278  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 3287  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 ;;
3389   pkgbuild|!pkgbuild) retval=0 ;;   pkgbuild|!pkgbuild) retval=0 ;;
3390     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3391   purge|!purge) retval=0 ;;   purge|!purge) retval=0 ;;
3392   qalint|!qalint) retval=0 ;;   qalint|!qalint) retval=0 ;;
3393   regentree|!regentree) retval=0 ;;   regentree|!regentree) retval=0 ;;
# Line 3391  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.1628  
changed lines
  Added in v.2225