Magellan Linux

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

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

revision 1549 by niro, Tue Dec 27 10:43:40 2011 UTC revision 1658 by niro, Sat Jan 14 00:00:53 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 206  install_directories() Line 226  install_directories()
226   while read pathto posix user group   while read pathto posix user group
227   do   do
228   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
229   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
230    
231   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
232   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 282  install_files() Line 302  install_files()
302   case ${retval} in   case ${retval} in
303   # file is not protected - (over)write it   # file is not protected - (over)write it
304   0|3)   0|3)
305   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
306   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
307   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
308   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 300  install_files() Line 320  install_files()
320    
321   # file is protected, write backup file   # file is protected, write backup file
322   2)   2)
323   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
324   then   then
325   echo -en "${COLRED}"   echo -en "${COLRED}"
326   echo -n "! prot "   echo -n "! prot "
# Line 331  install_files() Line 351  install_files()
351    
352   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
353   4)   4)
354   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
355   then   then
356   echo -en "${COLRED}"   echo -en "${COLRED}"
357   echo -n "! ignr "   echo -n "! ignr "
# Line 390  install_symlinks() Line 410  install_symlinks()
410   while read pathto posix link mtime   while read pathto posix link mtime
411   do   do
412   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
413   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
414    
415   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
416    
# Line 440  install_blockdevices() Line 460  install_blockdevices()
460   while read pathto posix major minor user group   while read pathto posix major minor user group
461   do   do
462   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
463   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
464    
465   mknod -m "${posix}" "${MROOT}${pathto}"   mknod -m "${posix}" "${MROOT}${pathto}"
466   # make it optional atm !!   # make it optional atm !!
# Line 484  install_characterdevices() Line 504  install_characterdevices()
504   while read pathto posix major minor user group   while read pathto posix major minor user group
505   do   do
506   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
507   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
508    
509   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
510    
# Line 528  install_fifos() Line 548  install_fifos()
548   while read pathto posix user group   while read pathto posix user group
549   do   do
550   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
551   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FIFO: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
552    
553   mkfifo -m "${posix}" "${MROOT}${pathto}"   mkfifo -m "${posix}" "${MROOT}${pathto}"
554   chown "${user}:${group}" "${MROOT}${pathto}"   chown "${user}:${group}" "${MROOT}${pathto}"
# Line 862  remove_symlinks() Line 882  remove_symlinks()
882   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
883   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
884   then   then
885   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
886   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
887   continue   continue
888   fi   fi
# Line 874  remove_symlinks() Line 894  remove_symlinks()
894   # 1=keep me   #   # 1=keep me   #
895   case ${retval} in   case ${retval} in
896   0)   0)
897   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
898   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
899   ;;   ;;
900    
901   1)   1)
902   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
903   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
904   ;;   ;;
905   esac   esac
# Line 946  remove_files() Line 966  remove_files()
966    
967   if [ ! -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
968   then   then
969   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
970   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
971   continue   continue
972   fi   fi
# Line 972  remove_files() Line 992  remove_files()
992   case ${retval} in   case ${retval} in
993   # file is not protected - delete it   # file is not protected - delete it
994   0|3)   0|3)
995   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
996   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
997   ;;   ;;
998    
999   # file is protected, do not delete   # file is protected, do not delete
1000   2)   2)
1001   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1002   then   then
1003   echo -en "${COLRED}"   echo -en "${COLRED}"
1004   echo -n "! prot "   echo -n "! prot "
# Line 989  remove_files() Line 1009  remove_files()
1009    
1010   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
1011   4)   4)
1012   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1013   then   then
1014   echo -en "${COLRED}"   echo -en "${COLRED}"
1015   echo -n "! ignr "   echo -n "! ignr "
# Line 1001  remove_files() Line 1021  remove_files()
1021   esac   esac
1022   ;;   ;;
1023   1)   1)
1024   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1025   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1026   ;;   ;;
1027   esac   esac
# Line 1063  remove_blockdevices() Line 1083  remove_blockdevices()
1083   do   do
1084   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1085    
1086   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1087   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1088   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1089    
# Line 1123  remove_characterdevices() Line 1143  remove_characterdevices()
1143   do   do
1144   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1145    
1146   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1147   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1148   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1149    
# Line 1185  remove_fifos() Line 1205  remove_fifos()
1205   do   do
1206   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1207    
1208   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1209   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1210   done < ${MROOT}${INSTALLDB}/${pfull}/.fifo   done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1211    
# Line 1246  remove_directories() Line 1266  remove_directories()
1266    
1267   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1268   then   then
1269   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1270   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1271   continue   continue
1272   fi   fi
# Line 1254  remove_directories() Line 1274  remove_directories()
1274   # exclude .keep directories   # exclude .keep directories
1275   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1276   then   then
1277   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1278   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1279   continue   continue
1280   fi   fi
# Line 1267  remove_directories() Line 1287  remove_directories()
1287    
1288   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1289   then   then
1290   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1291   else   else
1292   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1293   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1294   fi   fi
1295   done   done
# Line 1401  mdownload() Line 1421  mdownload()
1421   real_uris="$(convertmirrors ${uri})"   real_uris="$(convertmirrors ${uri})"
1422    
1423   # verbose or not   # verbose or not
1424   [[ ${VERBOSE} = off ]] && wget_opts="--quiet"   mqueryfeature "!verbose" && wget_opts+=" --quiet"
1425    
1426   # filter wget options if busybox was found   # filter wget options if busybox was found
1427   wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"   wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1428    
1429   # create outputdir   # create outputdir
1430   [[ ! -d ${outputdir} ]] && install -d "${outputdir}"   [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
# Line 1488  fetch_packages() Line 1508  fetch_packages()
1508   echo -ne " ${COLBLUE}***${COLDEFAULT}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1509   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1510   mdownload --uri "package://${pkg}" --dir "${PKGDIR}" || die "Could not download ${pkg}"   mdownload --uri "package://${pkg}" --dir "${PKGDIR}" || die "Could not download ${pkg}"
   
1511   if [ ! -f ${PKGDIR}/${pkg} ]   if [ ! -f ${PKGDIR}/${pkg} ]
1512   then   then
1513   die "Package '${pkg}' after download not found in '${PKGDIR}'"   die "Package '${pkg}' after download not found in '${PKGDIR}'"
# Line 1551  syncmage_tarball() Line 1570  syncmage_tarball()
1570    
1571   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1572   echo "fetching latest md5 from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
1573   [[ ${VERBOSE} = off ]] && opt="--quiet"   mqueryfeature "!verbose" && opt="--quiet"
1574   wget \   wget \
1575   ${wget_opts} \   ${wget_opts} \
1576   --directory-prefix=${temp} \   --directory-prefix=${temp} \
# Line 1580  syncmage_tarball() Line 1599  syncmage_tarball()
1599   else   else
1600   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1601   echo -n "checking md5sum... "   echo -n "checking md5sum... "
1602   ( 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"
1603   fi   fi
1604    
1605   if [[ -d ${MAGEDIR} ]]   if [[ -d ${MAGEDIR} ]]
1606   then   then
1607   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1608   echo "cleaning old mage-tree ${MAGEDIR}..."   echo "cleaning old mage-tree ${MAGEDIR}..."
1609   rm -rf ${MAGEDIR}   # honor mountpoints and empty dirs
1610     if mountpoint -q ${MAGEDIR}
1611     then
1612     if ! mcheckemptydir ${MAGEDIR}
1613     then
1614     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xarg --no-run-if-empty rm -r
1615     fi
1616     else
1617     rm -rf ${MAGEDIR}
1618     fi
1619   fi   fi
1620    
1621   if need_busybox_support tar   if need_busybox_support tar
# Line 1646  xtitleclean() Line 1674  xtitleclean()
1674  }  }
1675    
1676    
1677  # cuts full pathnames or versionized names down to basename  # unused?
1678  choppkgname()  #
1679  {  # # cuts full pathnames or versionized names down to basename
1680   #we want this only if full name was used  # choppkgname()
1681   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1682   then  # #we want this only if full name was used
1683   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1684   #ARCH comes from ${MAGERC}  # then
1685   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1686    # #ARCH comes from ${MAGERC}
1687    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1688    #
1689    # #cuts version number
1690    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1691    # fi
1692    # }
1693    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1694    
1695  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1696  # $1=pname  # $1=pname
# Line 1738  get_highest_magefile() Line 1769  get_highest_magefile()
1769   then   then
1770   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1771   #for debug only   #for debug only
1772   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"
1773   fi   fi
1774   done   done
1775    
# Line 2146  minclude() Line 2177  minclude()
2177   then   then
2178   for i in $*   for i in $*
2179   do   do
2180   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2181   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2182   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2183   done   done
2184   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2185   fi   fi
2186  }  }
2187    
# Line 2760  md5sum_packages() Line 2791  md5sum_packages()
2791   then   then
2792   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2793   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2794   ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2795   else   else
2796   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2797   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 3000  pkgsearch() Line 3031  pkgsearch()
3031   local state   local state
3032   local descriptiom   local descriptiom
3033   local homepage   local homepage
3034     local license
3035   local i   local i
3036   local all_installed   local all_installed
3037   local ipver   local ipver
# Line 3036  pkgsearch() Line 3068  pkgsearch()
3068   state="$(get_value_from_magefile STATE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3069   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3070   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3071     license="$(get_value_from_magefile LICENSE ${magefile})"
3072    
3073   # all installed   # all installed
3074   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3075   do   do
3076   ipver="$(magename2pver ${i})"   ipver="$(magename2pver ${i})"
3077   ipbuild="$(magename2pbuild ${i})"   ipbuild="$(magename2pbuild ${i})"
3078    
3079   if [[ -z ${all_installed} ]]   if [[ -z ${all_installed} ]]
3080   then   then
3081   all_installed="${ipver}-${ipbuild}"   all_installed="${ipver}-${ipbuild}"
# Line 3051  pkgsearch() Line 3084  pkgsearch()
3084   fi   fi
3085   done   done
3086   [[ -z ${all_installed} ]] && all_installed="none"   [[ -z ${all_installed} ]] && all_installed="none"
3087    
3088   case ${state} in   case ${state} in
3089   stable) state=${COLGREEN}"[s] ";;   stable) state=${COLGREEN}"[s] ";;
3090   testing) state=${COLYELLOW}"[t] ";;   testing) state=${COLYELLOW}"[t] ";;
# Line 3096  EOF Line 3129  EOF
3129   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3130   echo "      Description: ${description}"   echo "      Description: ${description}"
3131   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3132     if [[ ! -z ${license} ]]
3133     then
3134     echo "      License:  ${license}"
3135     fi
3136   echo "      Depends: ${deps}"   echo "      Depends: ${deps}"
3137   echo "      SDepends: ${sdeps}"   echo "      SDepends: ${sdeps}"
3138   echo   echo
# Line 3136  export_inherits() Line 3173  export_inherits()
3173   eval "${functions}() { ${include}_${functions} ; }"   eval "${functions}() { ${include}_${functions} ; }"
3174    
3175   # debug   # debug
3176   [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"   mqueryfeature "debug" && typeset -f "${functions}"
3177    
3178   shift   shift
3179   done   done
# Line 3274  have_root_privileges() Line 3311  have_root_privileges()
3311    
3312   return ${retval}   return ${retval}
3313  }  }
3314    
3315    known_mage_feature()
3316    {
3317     local feature="$1"
3318     local retval
3319    
3320     case "${feature}" in
3321     autosvc|!autosvc) retval=0 ;;
3322     buildlog|!buildlog) retval=0 ;;
3323     ccache|!ccache) retval=0 ;;
3324     check|!check) retval=0 ;;
3325     compressdoc|!compressdoc) retval=0 ;;
3326     debug|!debug) retval=0 ;;
3327     distcc|!distcc) retval=0 ;;
3328     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3329     libtool|!libtool) retval=0 ;;
3330     linuxsymlink|!linuxsymlink) retval=0 ;;
3331     pkgbuild|!pkgbuild) retval=0 ;;
3332     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3333     purge|!purge) retval=0 ;;
3334     qalint|!qalint) retval=0 ;;
3335     regentree|!regentree) retval=0 ;;
3336     resume|!resume) retval=0 ;;
3337     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3338     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3339     static|!static) retval=0 ;;
3340     stepbystep|!stepbystep) retval=0 ;;
3341     strip|!strip) retval=0 ;;
3342     verbose|!verbose) retval=0 ;;
3343     *) retval=1 ;;
3344     esac
3345    
3346     return "${retval}"
3347    }
3348    
3349    load_mage_features()
3350    {
3351     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3352     do
3353     FVERBOSE=off msetfeature ${i}
3354     done
3355    }
3356    
3357    msetfeature()
3358    {
3359     local feature
3360     local count
3361     local i
3362     local found
3363    
3364     for feature in $@
3365     do
3366     found=0
3367     count="${#MAGE_FEATURES_CURRENT[*]}"
3368    
3369     if ! known_mage_feature "${feature}"
3370     then
3371     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3372     return 3
3373     fi
3374    
3375     for ((i=0; i<count; i++))
3376     do
3377     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3378     then
3379     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3380     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3381     found=1
3382     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3383     then
3384     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3385     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3386     found=1
3387     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3388     then
3389     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3390     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3391     found=1
3392     fi
3393     done
3394    
3395     # if the feature was not found after proccessing the whole array
3396     # it was not declared. in this case enable it
3397     if [[ ${found} = 0 ]]
3398     then
3399     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3400     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3401     fi
3402    
3403     export MAGE_FEATURE_CURRENT
3404     done
3405    }
3406    
3407    mqueryfeature()
3408    {
3409     local feature="$1"
3410     local retval=1
3411     local i
3412    
3413     if known_mage_feature "${feature}"
3414     then
3415     for i in ${MAGE_FEATURES_CURRENT[*]}
3416     do
3417     if [[ ${i} = ${feature} ]]
3418     then
3419     retval=0
3420     break # found break here
3421     fi
3422     done
3423     else
3424     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3425     retval=3
3426     fi
3427    
3428     return ${retval}
3429    }
3430    
3431    mprintfeatures()
3432    {
3433     echo "Global features:  ${MAGE_FEATURES_GLOBAL[*]}"
3434     echo "Local features:   ${MAGE_FEATURES[*]}"
3435     echo "Current features: ${MAGE_FEATURES_CURRENT[*]}"
3436    }

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