Magellan Linux

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

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

revision 1273 by niro, Wed Apr 27 09:45:07 2011 UTC revision 2225 by niro, Wed Oct 16 07:49:19 2013 UTC
# Line 2  Line 2 
2  # Magellan Linux Installer Functions (mage.functions.sh)  # Magellan Linux Installer Functions (mage.functions.sh)
3  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.38 2008-10-05 10:32:24 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.38 2008-10-05 10:32:24 niro Exp $
4    
5    COLRED="\033[1;6m\033[31m"
6    COLGREEN="\033[1;6m\033[32m"
7    COLYELLOW="\033[1;6m\033[33m"
8    COLBLUE="\033[1;6m\033[34m"
9    COLMAGENTA="\033[1;6m\033[35m"
10    COLWHITE="\033[1;6m\033[37m"
11    COLGRAY="\033[0;6m\033[37m"
12    COLBOLD="\033[1m"
13    COLDEFAULT="\033[0m"
14    
15    if [[ ${NOCOLORS} = true ]]
16    then
17     COLRED=""
18     COLGREEN=""
19     COLYELLOW=""
20     COLBLUE=""
21     COLMAGENTA=""
22     COLWHITE=""
23     COLGRAY=""
24     COLBOLD=""
25     COLDEFAULT=""
26    fi
27    
28  mage_setup()  mage_setup()
29  {  {
30   [ ! -d ${MROOT}${INSTALLDB} ] && \   [ ! -d ${MROOT}${INSTALLDB} ] && \
# Line 15  mage_setup() Line 38  mage_setup()
38   return 0   return 0
39  }  }
40    
41    mchecksum()
42    {
43     local i
44     local rundir
45     local file
46     local method
47     local cmd
48     local retval
49     local sum
50     local dest
51    
52     # very basic getops
53     for i in $*
54     do
55     case $1 in
56     --rundir|-r) shift; rundir="$1" ;;
57     --file|-f) shift; file="$1" ;;
58     --method|-m) shift; method="$1" ;;
59     esac
60     shift
61     done
62    
63     # sanity checks
64     [[ -z ${rundir} ]] && die "mchecksum(): rundir missing"
65     [[ -z ${file} ]] && die "mchecksum(): file missing"
66     [[ -z ${method} ]] && die "mchecksum(): method missing"
67    
68     case ${method} in
69     md5) cmd="md5sum" ;;
70     sha256) cmd="sha256sum" ;;
71     *) die "mchecksum(): unknown method '${method}'" ;;
72     esac
73    
74     if [[ -d ${rundir} ]]
75     then
76     pushd ${rundir} &> /dev/null
77    
78     # 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
101     else
102     retval=1
103     fi
104    
105     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 33  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 84  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 139  install_directories() Line 257  install_directories()
257   while read pathto posix user group   while read pathto posix user group
258   do   do
259   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
260   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
   
261    
262   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
263   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 216  install_files() Line 333  install_files()
333   case ${retval} in   case ${retval} in
334   # file is not protected - (over)write it   # file is not protected - (over)write it
335   0|3)   0|3)
336   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
337   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
338   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
339   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 228  install_files() Line 345  install_files()
345   "${user}" \   "${user}" \
346   "${group}" \   "${group}" \
347   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
348   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
349   "${md5sum}"   "${md5sum}"
350   ;;   ;;
351    
352   # file is protected, write backup file   # file is protected, write backup file
353   2)   2)
354   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
355   then   then
356   echo -en "${COLRED}"   echo -en "${COLRED}"
357   echo -n "! prot "   echo -n "! prot "
# Line 255  install_files() Line 372  install_files()
372   "${user}" \   "${user}" \
373   "${group}" \   "${group}" \
374   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
375   "${dest_protected}")" \   "${dest_protected}")" \
376   "${md5sum}"   "${md5sum}"
377    
378   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
# Line 265  install_files() Line 382  install_files()
382    
383   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
384   4)   4)
385   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
386   then   then
387   echo -en "${COLRED}"   echo -en "${COLRED}"
388   echo -n "! ignr "   echo -n "! ignr "
389   echo -en "${COLDEFAULT}"   echo -en "${COLDEFAULT}"
390   echo " === FILE: ${MROOT}${pathto}"   echo " === FILE: ${MROOT}${pathto}"
391   fi   fi
392   # simply do nothing here   # simply do nothing here - only fix mtime
393     fix_descriptor ${pkgname}/.files \
394     "${pathto}" \
395     "${posix}" \
396     "${user}" \
397     "${group}" \
398     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
399     "${MROOT}${pathto}")" \
400     "${md5sum}"
401   ;;   ;;
402   esac   esac
403   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
# Line 316  install_symlinks() Line 441  install_symlinks()
441   while read pathto posix link mtime   while read pathto posix link mtime
442   do   do
443   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
444   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
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 366  install_blockdevices() Line 491  install_blockdevices()
491   while read pathto posix major minor user group   while read pathto posix major minor user group
492   do   do
493   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
494   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
495    
496   mknod -m "${posix}" "${MROOT}${pathto}"   mknod -m "${posix}" "${MROOT}${pathto}"
497   # make it optional atm !!   # make it optional atm !!
# Line 410  install_characterdevices() Line 535  install_characterdevices()
535   while read pathto posix major minor user group   while read pathto posix major minor user group
536   do   do
537   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
538   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
539    
540   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
541    
# Line 454  install_fifos() Line 579  install_fifos()
579   while read pathto posix user group   while read pathto posix user group
580   do   do
581   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
582   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FIFO: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
583    
584   mkfifo -m "${posix}" "${MROOT}${pathto}"   mkfifo -m "${posix}" "${MROOT}${pathto}"
585   chown "${user}:${group}" "${MROOT}${pathto}"   chown "${user}:${group}" "${MROOT}${pathto}"
# Line 476  build_doinstall() Line 601  build_doinstall()
601    
602   # sanity checks; abort if not given   # sanity checks; abort if not given
603   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
604    
605   # this is only a wrapper   # this is only a wrapper
606    
607   # NOTE:   # NOTE:
# Line 713  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 788  remove_symlinks() Line 902  remove_symlinks()
902   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
903   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
904   then   then
905   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
906   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
907   continue   continue
908   fi   fi
# Line 800  remove_symlinks() Line 914  remove_symlinks()
914   # 1=keep me   #   # 1=keep me   #
915   case ${retval} in   case ${retval} in
916   0)   0)
917   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
918   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
919   ;;   ;;
920    
921   1)   1)
922   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
923   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
924   ;;   ;;
925   esac   esac
# Line 872  remove_files() Line 986  remove_files()
986    
987   if [ ! -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
988   then   then
989   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
990   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
991   continue   continue
992   fi   fi
# Line 898  remove_files() Line 1012  remove_files()
1012   case ${retval} in   case ${retval} in
1013   # file is not protected - delete it   # file is not protected - delete it
1014   0|3)   0|3)
1015   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
1016   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1017   ;;   ;;
1018    
1019   # file is protected, do not delete   # file is protected, do not delete
1020   2)   2)
1021   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1022   then   then
1023   echo -en "${COLRED}"   echo -en "${COLRED}"
1024   echo -n "! prot "   echo -n "! prot "
# Line 915  remove_files() Line 1029  remove_files()
1029    
1030   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
1031   4)   4)
1032   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1033   then   then
1034   echo -en "${COLRED}"   echo -en "${COLRED}"
1035   echo -n "! ignr "   echo -n "! ignr "
# Line 927  remove_files() Line 1041  remove_files()
1041   esac   esac
1042   ;;   ;;
1043   1)   1)
1044   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1045   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1046   ;;   ;;
1047   esac   esac
# Line 989  remove_blockdevices() Line 1103  remove_blockdevices()
1103   do   do
1104   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1105    
1106   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1107   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1108   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1109    
# Line 1049  remove_characterdevices() Line 1163  remove_characterdevices()
1163   do   do
1164   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1165    
1166   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1167   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1168   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1169    
# Line 1111  remove_fifos() Line 1225  remove_fifos()
1225   do   do
1226   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1227    
1228   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1229   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1230   done < ${MROOT}${INSTALLDB}/${pfull}/.fifo   done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1231    
# Line 1172  remove_directories() Line 1286  remove_directories()
1286    
1287   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1288   then   then
1289   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1290   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1291   continue   continue
1292   fi   fi
# Line 1180  remove_directories() Line 1294  remove_directories()
1294   # exclude .keep directories   # exclude .keep directories
1295   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1296   then   then
1297   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1298   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1299   continue   continue
1300   fi   fi
# Line 1193  remove_directories() Line 1307  remove_directories()
1307    
1308   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1309   then   then
1310   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1311   else   else
1312   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1313   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1314   fi   fi
1315   done   done
# Line 1253  build_douninstall() Line 1367  build_douninstall()
1367   done   done
1368  }  }
1369    
1370    # convertmirrors [uri]
1371    convertmirrors()
1372    {
1373     local uri="$1"
1374     local scheme
1375     local mirror
1376     local mirrors
1377     local addon
1378     local real_uri
1379     local output
1380    
1381     # needs
1382     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1383     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1384     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1385     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1386     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1387    
1388     # check known uri schemes
1389     case ${uri} in
1390     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1391     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1392     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1393     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1394     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1395     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1396     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1397     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1398     esac
1399    
1400     if [[ ! -z ${mirrors} ]]
1401     then
1402     for mirror in ${mirrors}
1403     do
1404     # add a whitespace to the output
1405     [[ -z ${output} ]] || output+=" "
1406     output+="${mirror}${addon}/${uri/${scheme}/}"
1407     done
1408     else
1409     output="${uri}"
1410     fi
1411    
1412     echo "${output}"
1413    }
1414    
1415    mdownload()
1416    {
1417     local i
1418     local uri
1419     local real_uris
1420     local mirror
1421     local outputfile
1422     local outputdir
1423     local retval
1424     local wget_opts
1425    
1426     # very basic getops
1427     for i in $*
1428     do
1429     case $1 in
1430     --uri|-u) shift; uri="$1" ;;
1431     --dir|-d) shift; outputdir="$1" ;;
1432     esac
1433     shift
1434     done
1435    
1436     # sanity checks; abort if not given
1437     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1438     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1439    
1440     # convert mirrored uris to the real ones
1441     real_uris="$(convertmirrors ${uri})"
1442    
1443     # verbose or not
1444     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1445    
1446     # filter wget options if busybox was found
1447     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1448    
1449     # create outputdir
1450     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1451    
1452     for mirror in ${real_uris}
1453     do
1454     # get the name of the output file
1455     outputfile="${mirror##*/}"
1456    
1457     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1458     retval="$?"
1459     if [[ ${retval} = 0 ]]
1460     then
1461     break
1462     else
1463     continue
1464     fi
1465     done
1466    
1467     # return wget retval
1468     return "${retval}"
1469    }
1470    
1471  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1472  fetch_packages()  fetch_packages()
1473  {  {
1474     local i
1475   local list="$@"   local list="$@"
1476   local pkg   local pkg
1477   local mirr   local mirr
# Line 1309  fetch_packages() Line 1525  fetch_packages()
1525   continue   continue
1526   fi   fi
1527    
1528   for mirr in ${MIRRORS}   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1529   do   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1530   echo -ne " ${COLBLUE}***${COLDEFAULT}"   mdownload --uri "package://${pkg}" --dir "${PKGDIR}" || die "Could not download ${pkg}"
  #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... "  
  echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "  
  [[ ${VERBOSE} = off ]] && opt="--quiet"  
  wget \  
  ${wget_opts} \  
  --directory-prefix=${PKGDIR} \  
  ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}  
  if [[ $? = 0 ]]  
  then  
  break  
  else  
  continue  
  fi  
  done  
   
1531   if [ ! -f ${PKGDIR}/${pkg} ]   if [ ! -f ${PKGDIR}/${pkg} ]
1532   then   then
1533   die "Could not download ${pkg}"   die "Package '${pkg}' after download not found in '${PKGDIR}'"
1534   fi   fi
1535   done   done
1536    
# Line 1357  syncmage() Line 1558  syncmage()
1558   done   done
1559    
1560   # clean up backup files (foo~)   # clean up backup files (foo~)
1561   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1562    
1563   # check if a newer mage version is available   # check if a newer mage version is available
1564   is_newer_mage_version_available   is_newer_mage_version_available
# Line 1371  syncmage_tarball() Line 1572  syncmage_tarball()
1572   local mirr mymirr   local mirr mymirr
1573   local opt   local opt
1574   local tar_opts   local tar_opts
1575     local wget_opts
1576    
1577   # try to get the md5 marked as latest on the server   # try to get the md5 marked as latest on the server
1578   latest_md5="mage-latest.md5"   latest_md5="mage-latest.md5"
# Line 1378  syncmage_tarball() Line 1580  syncmage_tarball()
1580   # try to get the tarball marked as latest on the server   # try to get the tarball marked as latest on the server
1581   latest_tarball="mage-latest.tar.bz2"   latest_tarball="mage-latest.tar.bz2"
1582    
1583     # filter wget command if busybox was found
1584     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
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} ..."
1597   [[ ${VERBOSE} = off ]] && opt="--quiet"   mqueryfeature "!verbose" && opt="--quiet"
1598   wget \   wget \
1599   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1600   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1601   ${opt} ${mymirr}/rsync/tarballs/${latest_md5}   ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1602    
1603   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1604   echo "fetching latest tarball from ${mymirr} ..."   echo "fetching latest tarball from ${mymirr} ..."
1605   wget \   wget \
1606   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1607   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1608   ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}   ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1609   if [[ $? = 0 ]]   if [[ $? = 0 ]]
# Line 1414  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 1480  xtitleclean() Line 1698  xtitleclean()
1698  }  }
1699    
1700    
1701  # cuts full pathnames or versioniezed 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 1563  get_highest_magefile() Line 1784  get_highest_magefile()
1784   local magefile   local magefile
1785    
1786   # do not list the content of a directory, only the name (-d)   # do not list the content of a directory, only the name (-d)
1787   for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/*)   for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1788   do   do
1789   [[ -z ${magefile} ]] && continue   [[ -z ${magefile} ]] && continue
1790   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
# Line 1572  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   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1797   fi   fi
1798   done   done
1799    
 # do not so anything  
 # # stop here if HIGHEST_MAGEFILE is zero  
 # # this package must be unstable or old  
 # if [ -z "${HIGHEST_MAGEFILE}" ]  
 # then  
 # echo  
 # echo -n "All packages named "  
 # echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}  
 # echo -n " are marked "  
 # echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}  
 # echo "."  
 # echo "You need to declare USE_UNSTABLE=true to install this."  
 # echo  
 # echo "Example:"  
 # echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"  
 # echo  
 # echo "Be warned that these packages are not stable and may cause serious problems."  
 # echo "You should know what you are doing, so don't complain about any damage."  
 # echo  
 # return 1  
 # fi  
   
1800   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1801   return 0   return 0
1802  }  }
# Line 1701  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     # hack; do not honor a global set IFS like '§'
1908     local IFS
1909    
1910   declare -i count=0   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 2002  minclude() Line 2219  minclude()
2219   then   then
2220   for i in $*   for i in $*
2221   do   do
2222   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2223   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2224   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2225   done   done
2226   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2227   fi   fi
2228  }  }
2229    
# Line 2450  mage_install() Line 2667  mage_install()
2667   if [[ -n ${MAGE_TARGETS} ]]   if [[ -n ${MAGE_TARGETS} ]]
2668   then   then
2669   # basic svn compat   # basic svn compat
2670   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2671   then   then
2672   for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2673   do   do
2674   smage2file="${i}"   smage2file="${i}"
2675   done   done
# Line 2463  mage_install() Line 2680  mage_install()
2680   elif [[ -n ${SPLIT_PACKAGE_BASE} ]]   elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2681   then   then
2682   # basic svn compat   # basic svn compat
2683   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2684   then   then
2685   for i in ${SMAGESCRIPTSDIR}/trunk/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2686   do   do
2687   smage2file="${i}"   smage2file="${i}"
2688   done   done
# Line 2475  mage_install() Line 2692  mage_install()
2692    
2693   else   else
2694   # basic svn compat   # basic svn compat
2695   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2696   then   then
2697   for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2698   do   do
2699   smage2file="${i}"   smage2file="${i}"
2700   done   done
# Line 2502  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 2616  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 2856  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 2892  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 2907  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 2931  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 2942  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 2952  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 2992  export_inherits() Line 3226  export_inherits()
3226   eval "${functions}() { ${include}_${functions} ; }"   eval "${functions}() { ${include}_${functions} ; }"
3227    
3228   # debug   # debug
3229   [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"   mqueryfeature "debug" && typeset -f "${functions}"
3230    
3231   shift   shift
3232   done   done
# Line 3069  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   else   # needs busybox support
3316   # no busybox   return 0
3317   return 1   fi
3318   fi   fi
3319   fi   done
3320    
3321     # no busybox
3322     return 1
3323  }  }
3324    
3325  # busybox_filter_wget_options ${wget_opts}  # busybox_filter_wget_options ${wget_opts}
# Line 3116  busybox_filter_wget_options() Line 3354  busybox_filter_wget_options()
3354   echo "${opts}"   echo "${opts}"
3355   fi   fi
3356  }  }
3357    
3358    have_root_privileges()
3359    {
3360     local retval
3361    
3362     if [[ $(id -u) = 0 ]]
3363     then
3364     retval=0
3365     else
3366     retval=1
3367     fi
3368    
3369     return ${retval}
3370    }
3371    
3372    known_mage_feature()
3373    {
3374     local feature="$1"
3375     local retval
3376    
3377     case "${feature}" in
3378     autosvc|!autosvc) retval=0 ;;
3379     buildlog|!buildlog) retval=0 ;;
3380     ccache|!ccache) retval=0 ;;
3381     check|!check) retval=0 ;;
3382     compressdoc|!compressdoc) retval=0 ;;
3383     debug|!debug) retval=0 ;;
3384     distcc|!distcc) retval=0 ;;
3385     icecc|!icecc) retval=0 ;;
3386     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3387     libtool|!libtool) retval=0 ;;
3388     linuxsymlink|!linuxsymlink) retval=0 ;;
3389     pkgbuild|!pkgbuild) retval=0 ;;
3390     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3391     purge|!purge) retval=0 ;;
3392     qalint|!qalint) retval=0 ;;
3393     regentree|!regentree) retval=0 ;;
3394     resume|!resume) retval=0 ;;
3395     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3396     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3397     static|!static) retval=0 ;;
3398     stepbystep|!stepbystep) retval=0 ;;
3399     strip|!strip) retval=0 ;;
3400     verbose|!verbose) retval=0 ;;
3401     *) retval=1 ;;
3402     esac
3403    
3404     return "${retval}"
3405    }
3406    
3407    load_mage_features()
3408    {
3409     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3410     do
3411     FVERBOSE=off msetfeature ${i}
3412     done
3413    }
3414    
3415    msetfeature()
3416    {
3417     local feature
3418     local count
3419     local i
3420     local found
3421    
3422     for feature in $@
3423     do
3424     found=0
3425     count="${#MAGE_FEATURES_CURRENT[*]}"
3426    
3427     if ! known_mage_feature "${feature}"
3428     then
3429     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3430     return 3
3431     fi
3432    
3433     for ((i=0; i<count; i++))
3434     do
3435     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3436     then
3437     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3438     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3439     found=1
3440     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3441     then
3442     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3443     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3444     found=1
3445     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3446     then
3447     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3448     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3449     found=1
3450     fi
3451     done
3452    
3453     # if the feature was not found after proccessing the whole array
3454     # it was not declared. in this case enable it
3455     if [[ ${found} = 0 ]]
3456     then
3457     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3458     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3459     fi
3460    
3461     export MAGE_FEATURE_CURRENT
3462     done
3463    }
3464    
3465    mqueryfeature()
3466    {
3467     local feature="$1"
3468     local retval=1
3469     local i
3470    
3471     if known_mage_feature "${feature}"
3472     then
3473     for i in ${MAGE_FEATURES_CURRENT[*]}
3474     do
3475     if [[ ${i} = ${feature} ]]
3476     then
3477     retval=0
3478     break # found break here
3479     fi
3480     done
3481     else
3482     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3483     retval=3
3484     fi
3485    
3486     return ${retval}
3487    }
3488    
3489    mprintfeatures()
3490    {
3491     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3492     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3493     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3494    }

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