Magellan Linux

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

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

revision 1438 by niro, Mon Jul 25 12:05:37 2011 UTC revision 2867 by niro, Thu Mar 19 15:28:54 2015 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
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 $  # $Id$
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  {  {
# 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 is empty ;("
85     retval=127
86     fi
87     done < ${file}
88     if [[ ${retval} != 127 ]]
89     then
90     # be verbose here
91     ${cmd} -c ${file} #&> /dev/null
92     retval="$?"
93     fi
94    
95     popd &> /dev/null
96     else
97     retval=1
98     fi
99    
100     return "${retval}"
101    }
102    
103    mcheckemptydir()
104    {
105     local dir="$1"
106     local retval=1
107    
108     if [[ ! -d ${dir} ]]
109     then
110     echo "mcheckemptydir(): '${dir}' is not a directory!"
111     retval=3
112     else
113     shopt -s nullglob dotglob
114     files=( ${dir}/* )
115     (( ${#files[*]} )) || retval=0
116     shopt -u nullglob dotglob
117     fi
118    
119     return ${retval}
120    }
121    
122    unpack_package()
123    {
124     local magefile="$1"
125     local pkgname
126     local pkgfile
127     local pkgtype
128     local tar_opts
129    
130     pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
131     pkgfile="${pkgname}.${PKGSUFFIX}"
132     pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
133    
134     xtitle "[ Unpacking ${pkg} ]"
135    
136     # abort on virtual pkg
137     if [[ ${pkgtype} = virtual ]]
138     then
139     echo -ne " ${COLBLUE}---${COLDEFAULT}"
140     echo " !unpack virtual ${pkgname} ... "
141     continue
142     fi
143    
144     # abort on sources pkg
145     if [[ ${pkgtype} = sources ]]
146     then
147     echo -ne " ${COLBLUE}---${COLDEFAULT}"
148     echo " !unpack sources ${pkgname} ... "
149     continue
150     fi
151    
152     # busybox?
153     if need_busybox_support tar
154     then
155     tar_opts="xjf"
156     else
157     tar_opts="xjmf"
158     fi
159    
160     echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkgfile} ... "
161     tar ${tar_opts} ${PKGDIR}/${pkgfile} -C ${BUILDDIR} || die "Unpacking package ${pkgfile}"
162    }
163    
164  unpack_packages()  unpack_packages()
165  {  {
166   local list="$@"   local list="$@"
167   local magefile   local magefile
  local pkg  
  local pkgtype  
168   local count_current   local count_current
169   local count_total   local count_total
170   local tar_opts   local tar_opts
# Line 33  unpack_packages() Line 177  unpack_packages()
177    
178   for magefile in ${list}   for magefile in ${list}
179   do   do
180   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   unpack_package "${magefile}"
  pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"  
   
181   (( 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}"  
182   done   done
183    
184   # add a crlf for a better view   # add a crlf for a better view
# Line 84  fix_mtime() Line 198  fix_mtime()
198   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
199   touch \   touch \
200   --no-create \   --no-create \
201     --no-dereference \
202   --time=mtime \   --time=mtime \
203   --reference "${reference}" \   --reference="${reference}" \
204   "${pathto}"   "${pathto}"
205    
206   echo "${mtime}"   echo "${mtime}"
# Line 139  install_directories() Line 254  install_directories()
254   while read pathto posix user group   while read pathto posix user group
255   do   do
256   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
257   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
   
258    
259   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
260   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 216  install_files() Line 330  install_files()
330   case ${retval} in   case ${retval} in
331   # file is not protected - (over)write it   # file is not protected - (over)write it
332   0|3)   0|3)
333   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
334   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
335   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
336   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 234  install_files() Line 348  install_files()
348    
349   # file is protected, write backup file   # file is protected, write backup file
350   2)   2)
351   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
352   then   then
353   echo -en "${COLRED}"   echo -en "${COLRED}"
354   echo -n "! prot "   echo -n "! prot "
# Line 265  install_files() Line 379  install_files()
379    
380   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
381   4)   4)
382   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
383   then   then
384   echo -en "${COLRED}"   echo -en "${COLRED}"
385   echo -n "! ignr "   echo -n "! ignr "
# Line 324  install_symlinks() Line 438  install_symlinks()
438   while read pathto posix link mtime   while read pathto posix link mtime
439   do   do
440   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
441   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
442    
443   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
444    
445  # # fix mtime and db   # fix mtime and db
446  # fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
447  # "${pathto}" \   "${pathto}" \
448  # "${posix}" \   "${posix}" \
449  # "${link}" \   "${link}" \
450  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
451  # "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
452    
453   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
454    
# Line 374  install_blockdevices() Line 488  install_blockdevices()
488   while read pathto posix major minor user group   while read pathto posix major minor user group
489   do   do
490   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
491   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
492    
493   mknod -m "${posix}" "${MROOT}${pathto}"   mknod -m "${posix}" "${MROOT}${pathto}"
494   # make it optional atm !!   # make it optional atm !!
# Line 418  install_characterdevices() Line 532  install_characterdevices()
532   while read pathto posix major minor user group   while read pathto posix major minor user group
533   do   do
534   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
535   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
536    
537   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
538    
# Line 462  install_fifos() Line 576  install_fifos()
576   while read pathto posix user group   while read pathto posix user group
577   do   do
578   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
579   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FIFO: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
580    
581   mkfifo -m "${posix}" "${MROOT}${pathto}"   mkfifo -m "${posix}" "${MROOT}${pathto}"
582   chown "${user}:${group}" "${MROOT}${pathto}"   chown "${user}:${group}" "${MROOT}${pathto}"
# Line 647  remove_database_entry() Line 761  remove_database_entry()
761   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
762    
763   # remove virtuals only if no other exist   # remove virtuals only if no other exist
764   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]   if [[ $(count_installed_pkgs --pcat=${pcat} --pname=${pname}) -le 1 ]]
765   then   then
766   # first unregister virtuals   # first unregister virtuals
767   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
# Line 676  count_installed_pkgs() Line 790  count_installed_pkgs()
790   local i   local i
791    
792   # very basic getops   # very basic getops
793   for i in $*   for i in $@
794   do   do
795   case $1 in   case ${i} in
796   --pcat|-c) shift; pcat="$1" ;;   --pcat*) pcat="${i#*=}" ;;
797   --pname|-n) shift; pname="$1" ;;   --pname*) pname="${i#*=}" ;;
798   esac   esac
  shift  
799   done   done
800    
801   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 721  compare_mtime() Line 834  compare_mtime()
834    
835   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
836    
837   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
838   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
839   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  
840    
841   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
842    
# Line 796  remove_symlinks() Line 898  remove_symlinks()
898   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
899   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
900   then   then
901   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
902   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
903   continue   continue
904   fi   fi
# Line 808  remove_symlinks() Line 910  remove_symlinks()
910   # 1=keep me   #   # 1=keep me   #
911   case ${retval} in   case ${retval} in
912   0)   0)
913   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
914   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
915   ;;   ;;
916    
917   1)   1)
918   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
919   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
920   ;;   ;;
921   esac   esac
# Line 880  remove_files() Line 982  remove_files()
982    
983   if [ ! -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
984   then   then
985   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
986   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
987   continue   continue
988   fi   fi
# Line 906  remove_files() Line 1008  remove_files()
1008   case ${retval} in   case ${retval} in
1009   # file is not protected - delete it   # file is not protected - delete it
1010   0|3)   0|3)
1011   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
1012   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1013   ;;   ;;
1014    
1015   # file is protected, do not delete   # file is protected, do not delete
1016   2)   2)
1017   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1018   then   then
1019   echo -en "${COLRED}"   echo -en "${COLRED}"
1020   echo -n "! prot "   echo -n "! prot "
# Line 923  remove_files() Line 1025  remove_files()
1025    
1026   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
1027   4)   4)
1028   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1029   then   then
1030   echo -en "${COLRED}"   echo -en "${COLRED}"
1031   echo -n "! ignr "   echo -n "! ignr "
# Line 935  remove_files() Line 1037  remove_files()
1037   esac   esac
1038   ;;   ;;
1039   1)   1)
1040   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1041   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1042   ;;   ;;
1043   esac   esac
# Line 997  remove_blockdevices() Line 1099  remove_blockdevices()
1099   do   do
1100   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1101    
1102   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1103   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1104   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1105    
# Line 1057  remove_characterdevices() Line 1159  remove_characterdevices()
1159   do   do
1160   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1161    
1162   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1163   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1164   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1165    
# Line 1119  remove_fifos() Line 1221  remove_fifos()
1221   do   do
1222   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1223    
1224   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1225   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1226   done < ${MROOT}${INSTALLDB}/${pfull}/.fifo   done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1227    
# Line 1180  remove_directories() Line 1282  remove_directories()
1282    
1283   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1284   then   then
1285   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1286   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1287   continue   continue
1288   fi   fi
# Line 1188  remove_directories() Line 1290  remove_directories()
1290   # exclude .keep directories   # exclude .keep directories
1291   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1292   then   then
1293   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1294   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1295   continue   continue
1296   fi   fi
# Line 1201  remove_directories() Line 1303  remove_directories()
1303    
1304   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1305   then   then
1306   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1307   else   else
1308   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1309   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1310   fi   fi
1311   done   done
# Line 1261  build_douninstall() Line 1363  build_douninstall()
1363   done   done
1364  }  }
1365    
1366    # convertmirrors [uri]
1367    convertmirrors()
1368    {
1369     local uri="$1"
1370     local scheme
1371     local mirror
1372     local mirrors
1373     local addon
1374     local real_uri
1375     local output
1376    
1377     # needs
1378     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1379     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1380     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1381     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1382     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1383    
1384     # check known uri schemes
1385     case ${uri} in
1386     http://*|https://*|ftp://*|ftps://*|file://*) mirrors="" ;;
1387     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1388     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1389     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1390     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1391     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1392     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1393     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1394     esac
1395    
1396     if [[ ! -z ${mirrors} ]]
1397     then
1398     for mirror in ${mirrors}
1399     do
1400     # add a whitespace to the output
1401     [[ -z ${output} ]] || output+=" "
1402     output+="${mirror}${addon}/${uri/${scheme}/}"
1403     done
1404     else
1405     output="${uri}"
1406     fi
1407    
1408     echo "${output}"
1409    }
1410    
1411    mdownload()
1412    {
1413     local i
1414     local uri
1415     local real_uris
1416     local mirror
1417     local outputfile
1418     local outputdir
1419     local retval
1420     local wget_opts
1421    
1422     # very basic getops
1423     for i in $*
1424     do
1425     case $1 in
1426     --uri|-u) shift; uri="$1" ;;
1427     --dir|-d) shift; outputdir="$1" ;;
1428     esac
1429     shift
1430     done
1431    
1432     # sanity checks; abort if not given
1433     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1434     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1435    
1436     # convert mirrored uris to the real ones
1437     real_uris="$(convertmirrors ${uri})"
1438    
1439     # verbose or not
1440     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1441    
1442     # filter wget options if busybox was found
1443     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1444    
1445     # create outputdir
1446     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1447    
1448     for mirror in ${real_uris}
1449     do
1450     # get the name of the output file
1451     outputfile="${mirror##*/}"
1452    
1453     case ${mirror} in
1454     file://*)
1455     cp -v "${mirror//file:\/\/}" "${outputdir}/${outputfile}"
1456     retval="$?"
1457     ;;
1458     *)
1459     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1460     retval="$?"
1461     ;;
1462     esac
1463    
1464     if [[ ${retval} = 0 ]]
1465     then
1466     break
1467     else
1468     continue
1469     fi
1470     done
1471    
1472     # return wget retval
1473     return "${retval}"
1474    }
1475    
1476  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1477  fetch_packages()  fetch_packages()
1478  {  {
1479     local i
1480   local list="$@"   local list="$@"
1481   local pkg   local pkgname
1482     local pkgfile
1483     local pcat
1484     local pname
1485   local mirr   local mirr
1486   local magefile   local magefile
1487   local md5file   local md5file
# Line 1273  fetch_packages() Line 1489  fetch_packages()
1489   local count_current   local count_current
1490   local count_total   local count_total
1491   local wget_opts   local wget_opts
1492     local fetching
1493    
1494   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1495    
# Line 1287  fetch_packages() Line 1504  fetch_packages()
1504    
1505   for magefile in ${list}   for magefile in ${list}
1506   do   do
1507   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1508     pkgfile="${pkgname}.${PKGSUFFIX}"
1509   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1510    
1511     pcat=$(magename2pcat ${magefile})
1512     pname=$(magename2pname ${magefile})
1513     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
1514    
1515   (( count_current++ ))   (( count_current++ ))
1516   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1517    
1518   # abort on virtual pkg   # abort on virtual pkg
1519   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1520   then   then
1521   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1522   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1523   continue   continue
1524   fi   fi
1525    
# Line 1305  fetch_packages() Line 1527  fetch_packages()
1527   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1528   then   then
1529   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1530   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1531   continue   continue
1532   fi   fi
1533    
1534   # abort if already exist   # check if FETCHING is required
1535   if [ -f ${PKGDIR}/${pkg} ]   if [ ! -f "${md5file}" ]
1536   then   then
1537   echo -ne " ${COLBLUE}***${COLDEFAULT}"   fetching=true
1538   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   else
1539   continue   if mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 &> /dev/null
  fi  
   
  for mirr in ${MIRRORS}  
  do  
  echo -ne " ${COLBLUE}***${COLDEFAULT}"  
  #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 ]]  
1540   then   then
1541   break   # md5's ok, no fetching required
1542     fetching=false
1543   else   else
1544   continue   fetching=true
1545   fi   fi
1546   done   fi
1547    
1548   if [ ! -f ${PKGDIR}/${pkg} ]   if [[ ${fetching} = false ]]
1549   then   then
1550   die "Could not download ${pkg}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1551     echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1552     continue
1553     else
1554     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1555     echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1556     mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1557     fi
1558    
1559     # sanity check, not really needed but to be sure
1560     if [ ! -f ${PKGDIR}/${pkgfile} ]
1561     then
1562     die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1563   fi   fi
1564   done   done
1565    
# Line 1392  syncmage_tarball() Line 1614  syncmage_tarball()
1614    
1615   for mirr in ${MIRRORS}   for mirr in ${MIRRORS}
1616   do   do
1617   # path without distribution   # path without distribution
1618   mymirr="${mirr%/*}"   # (only for stable|testing|unstable and not DISTROTAG)
1619     case ${mirr##*/} in
1620     stable|testing|unstable) mymirr="${mirr%/*}";;
1621     *) mymirr="${mirr}";;
1622     esac
1623    
1624   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1625   echo "fetching latest md5 from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
1626   [[ ${VERBOSE} = off ]] && opt="--quiet"   mqueryfeature "!verbose" && opt="--quiet"
1627   wget \   wget \
1628   ${wget_opts} \   ${wget_opts} \
1629   --directory-prefix=${temp} \   --directory-prefix=${temp} \
# Line 1426  syncmage_tarball() Line 1652  syncmage_tarball()
1652   else   else
1653   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1654   echo -n "checking md5sum... "   echo -n "checking md5sum... "
1655   ( 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"
1656   fi   fi
1657    
1658   if [[ -d ${MAGEDIR} ]]   if [[ -d ${MAGEDIR} ]]
1659   then   then
1660   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1661   echo "cleaning old mage-tree ${MAGEDIR}..."   echo "cleaning old mage-tree ${MAGEDIR}..."
1662   rm -rf ${MAGEDIR}   # honor mountpoints and empty dirs
1663     if mountpoint -q ${MAGEDIR}
1664     then
1665     if ! mcheckemptydir ${MAGEDIR}
1666     then
1667     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1668     fi
1669     else
1670     rm -rf ${MAGEDIR}
1671     fi
1672   fi   fi
1673    
1674   if need_busybox_support tar   if need_busybox_support tar
# Line 1492  xtitleclean() Line 1727  xtitleclean()
1727  }  }
1728    
1729    
1730  # cuts full pathnames or versioniezed names down to basename  # unused?
1731  choppkgname()  #
1732  {  # # cuts full pathnames or versionized names down to basename
1733   #we want this only if full name was used  # choppkgname()
1734   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1735   then  # #we want this only if full name was used
1736   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1737   #ARCH comes from ${MAGERC}  # then
1738   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1739    # #ARCH comes from ${MAGERC}
1740    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1741    #
1742    # #cuts version number
1743    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1744    # fi
1745    # }
1746    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1747    
1748  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1749  # $1=pname  # $1=pname
# Line 1584  get_highest_magefile() Line 1822  get_highest_magefile()
1822   then   then
1823   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1824   #for debug only   #for debug only
1825   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1826   fi   fi
1827   done   done
1828    
 # 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  
   
1829   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1830   return 0   return 0
1831  }  }
# Line 1713  count_protected_files() Line 1929  count_protected_files()
1929   local filename="${file##*/}"   local filename="${file##*/}"
1930   local count   local count
1931   local output   local output
1932     local oldprotected
1933   local i   local i
1934     local x
1935    
1936     # hack; do not honor a global set IFS like '§'
1937     local IFS
1938    
1939   declare -i count=0   count=0
1940    
1941   # check if there are already protected files   # check if there are already protected files
1942   for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |   for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1943   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1944   sort -t'%' -k3 -k2 | cut -f1 -d'%')   sort -t'%' -k3 -k2 | cut -f1 -d'%')
1945   do   do
1946   count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")   count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1947   done   done
1948   (( count ++ ))  
1949     # convert 0001 -> 1; 0120 -> 120 etc
1950     # use bash internal base functions to this task
1951     x="$((10#${count}))"
1952     for (( i=0; i<x; i++ ))
1953     do
1954     if [[ ${count:${i}:1} != 0 ]]
1955     then
1956     count="${count:${i}}"
1957     break
1958     fi
1959     done
1960    
1961     count="$(( ${count}+1 ))"
1962    
1963   # fill output up with zeros   # fill output up with zeros
1964   for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done   for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
# Line 2014  minclude() Line 2248  minclude()
2248   then   then
2249   for i in $*   for i in $*
2250   do   do
2251   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2252   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2253   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2254   done   done
2255   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2256   fi   fi
2257  }  }
2258    
# Line 2030  sminclude() Line 2264  sminclude()
2264   then   then
2265   for i in $*   for i in $*
2266   do   do
2267   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2268   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2269   done   done
2270   echo   [[ ${SILENT} = 1 ]] || echo
2271   fi   fi
2272  }  }
2273    
# Line 2337  get_value_from_magefile() Line 2571  get_value_from_magefile()
2571   local SDEPEND   local SDEPEND
2572   local PROVIDE   local PROVIDE
2573   local PKGTYPE   local PKGTYPE
  local MAGE_TARGETS  
2574   local SPLIT_PACKAGE_BASE   local SPLIT_PACKAGE_BASE
2575   local preinstall   local preinstall
2576   local postinstall   local postinstall
# Line 2459  mage_install() Line 2692  mage_install()
2692   echo B:${pbuild}   echo B:${pbuild}
2693   fi   fi
2694    
2695   if [[ -n ${MAGE_TARGETS} ]]   if [[ -n ${SPLIT_PACKAGE_BASE} ]]
  then  
  # basic svn compat  
  if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]  
  then  
  for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2  
  do  
  smage2file="${i}"  
  done  
  else  
  smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2  
  fi  
   
  elif [[ -n ${SPLIT_PACKAGE_BASE} ]]  
2696   then   then
2697   # basic svn compat   # basic svn compat
2698   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2699   then   then
2700   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
2701   do   do
2702   smage2file="${i}"   smage2file="${i}"
2703   done   done
# Line 2487  mage_install() Line 2707  mage_install()
2707    
2708   else   else
2709   # basic svn compat   # basic svn compat
2710   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2711   then   then
2712   for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2713   do   do
2714   smage2file="${i}"   smage2file="${i}"
2715   done   done
# Line 2514  mage_install() Line 2734  mage_install()
2734   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2735   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2736   then   then
2737     unpack_package "${magefile}"
2738   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
2739   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2740   fi   fi
# Line 2602  md5sum_packages() Line 2823  md5sum_packages()
2823   pname=$(magename2pname ${magefile})   pname=$(magename2pname ${magefile})
2824   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2825   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2826   pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
2827   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2828    
2829   (( count_current++ ))   (( count_current++ ))
# Line 2612  md5sum_packages() Line 2833  md5sum_packages()
2833   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
2834   then   then
2835   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2836   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... "
2837   continue   continue
2838   fi   fi
2839    
# Line 2620  md5sum_packages() Line 2841  md5sum_packages()
2841   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
2842   then   then
2843   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2844   echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... "
2845   continue   continue
2846   fi   fi
2847    
# Line 2628  md5sum_packages() Line 2849  md5sum_packages()
2849   then   then
2850   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2851   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2852   ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2853   else   else
2854   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2855   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2668  uninstall_packages() Line 2889  uninstall_packages()
2889   pbuild=$(magename2pbuild ${pkg})   pbuild=$(magename2pbuild ${pkg})
2890   can_pcat="${pcat}"   can_pcat="${pcat}"
2891   can_pname="${pname}"   can_pname="${pname}"
2892    
2893   if [ -z "${can_ver_list}" ]   if [ -z "${can_ver_list}" ]
2894   then   then
2895   can_ver_list=" ${pver}-${pbuild}"   can_ver_list=" ${pver}-${pbuild}"
# Line 2841  mage_uninstall() Line 3062  mage_uninstall()
3062   unset -f postremove   unset -f postremove
3063  }  }
3064    
3065    # rerun_pkgfunctions [method] pkg1 pkg2 pkg3
3066    rerun_pkgfunctions()
3067    {
3068     local method
3069     local list
3070     local pcat
3071     local pname
3072     local pver
3073     local pbuild
3074     local magefile
3075     local i
3076    
3077     # very basic getops
3078     case $1 in
3079     --method) shift; method="$1" ;;
3080     esac
3081     shift
3082     local list="$@"
3083    
3084     # sanity check
3085     case ${method} in
3086     preinstall|postinstall) ;;
3087     preremove|postremove) ;;
3088     *) die "rerun_pkgfunctions(): Unknown method '${method}'." ;;
3089     esac
3090    
3091     if [[ -n ${MROOT} ]]
3092     then
3093     echo -ne ${COLRED}
3094     echo "!! running in MROOT=${MROOT}"
3095     echo -ne ${COLDEFAULT}
3096     echo
3097     fi
3098    
3099     for pkg in ${list}
3100     do
3101     pcat=$(dep2pcat ${pkg})
3102     pname=$(magename2pname ${pkg})
3103     pver=$(magename2pver ${pkg})
3104     pbuild=$(magename2pbuild ${pkg})
3105     magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
3106    
3107     if [ -e ${magefile} ]
3108     then
3109     source ${magefile}
3110     if [ -n "$(typeset -f ${method})" ]
3111     then
3112     echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... "
3113     ${method}
3114     else
3115     echo "No ${method}() for pkg '${pkg}' defined. Doing nothing."
3116     fi
3117     unset -f preinstall postinstall preremove postremove
3118     else
3119     die "Magefile '${magefile}' does not exist."
3120     fi
3121     done
3122    }
3123    
3124  show_etc_update_mesg()  show_etc_update_mesg()
3125  {  {
3126   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
# Line 2868  pkgsearch() Line 3148  pkgsearch()
3148   local state   local state
3149   local descriptiom   local descriptiom
3150   local homepage   local homepage
3151     local license
3152   local i   local i
3153   local all_installed   local all_installed
3154   local ipver   local ipver
# Line 2904  pkgsearch() Line 3185  pkgsearch()
3185   state="$(get_value_from_magefile STATE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3186   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3187   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3188     license="$(get_value_from_magefile LICENSE ${magefile})"
3189    
3190   # all installed   # all installed
3191   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3192   do   do
3193   ipver="$(magename2pver ${i})"   ipver="$(magename2pver ${i})"
3194   ipbuild="$(magename2pbuild ${i})"   ipbuild="$(magename2pbuild ${i})"
3195    
3196   if [[ -z ${all_installed} ]]   if [[ -z ${all_installed} ]]
3197   then   then
3198   all_installed="${ipver}-${ipbuild}"   all_installed="${ipver}-${ipbuild}"
# Line 2919  pkgsearch() Line 3201  pkgsearch()
3201   fi   fi
3202   done   done
3203   [[ -z ${all_installed} ]] && all_installed="none"   [[ -z ${all_installed} ]] && all_installed="none"
3204    
3205   case ${state} in   case ${state} in
3206   stable) state=${COLGREEN}"[s] ";;   stable) state=${COLGREEN}"[s] ";;
3207   testing) state=${COLYELLOW}"[t] ";;   testing) state=${COLYELLOW}"[t] ";;
# Line 2943  pkgsearch() Line 3225  pkgsearch()
3225   "") continue;;   "") continue;;
3226   esac   esac
3227    
3228   deps="${deps} $(basename ${dep%-*})"   if [[ -z ${deps} ]]
3229     then
3230     deps="$(basename ${dep%-*})"
3231     else
3232     deps="${deps} $(basename ${dep%-*})"
3233     fi
3234   done << EOF   done << EOF
3235  ${depsfull}  ${depsfull}
3236  EOF  EOF
# Line 2954  EOF Line 3241  EOF
3241   "") continue;;   "") continue;;
3242   esac   esac
3243    
3244   sdeps="${sdeps} $(basename ${dep%-*})"   if [[ -z ${sdeps} ]]
3245     then
3246     sdeps="$(basename ${dep%-*})"
3247     else
3248     sdeps="${sdeps} $(basename ${dep%-*})"
3249     fi
3250   done << EOF   done << EOF
3251  ${sdepsfull}  ${sdepsfull}
3252  EOF  EOF
# Line 2964  EOF Line 3256  EOF
3256   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3257   echo "      Description: ${description}"   echo "      Description: ${description}"
3258   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3259   echo "      Depends: ${deps}"   if [[ ! -z ${license} ]]
3260     then
3261     echo "      License:  ${license}"
3262     fi
3263     echo "      Depends:  ${deps}"
3264   echo "      SDepends: ${sdeps}"   echo "      SDepends: ${sdeps}"
3265   echo   echo
3266    
# Line 3004  export_inherits() Line 3300  export_inherits()
3300   eval "${functions}() { ${include}_${functions} ; }"   eval "${functions}() { ${include}_${functions} ; }"
3301    
3302   # debug   # debug
3303   [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"   mqueryfeature "debug" && typeset -f "${functions}"
3304    
3305   shift   shift
3306   done   done
# Line 3081  EOF Line 3377  EOF
3377  need_busybox_support()  need_busybox_support()
3378  {  {
3379   local cmd   local cmd
3380     local busybox
3381   cmd="$1"   cmd="$1"
3382    
3383   if [[ -x /bin/busybox ]]   for busybox in {,/usr}/bin/busybox
3384   then   do
3385   if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]   if [[ -x ${busybox} ]]
3386   then   then
3387   # needs busybox support   if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3388   return 0   then
3389     # needs busybox support
3390     return 0
3391     fi
3392   fi   fi
3393   fi   done
3394    
3395   # no busybox   # no busybox
3396   return 1   return 1
# Line 3128  busybox_filter_wget_options() Line 3428  busybox_filter_wget_options()
3428   echo "${opts}"   echo "${opts}"
3429   fi   fi
3430  }  }
3431    
3432    have_root_privileges()
3433    {
3434     local retval
3435    
3436     if [[ $(id -u) = 0 ]]
3437     then
3438     retval=0
3439     else
3440     retval=1
3441     fi
3442    
3443     return ${retval}
3444    }
3445    
3446    known_mage_feature()
3447    {
3448     local feature="$1"
3449     local retval
3450    
3451     case "${feature}" in
3452     autosvc|!autosvc) retval=0 ;;
3453     buildlog|!buildlog) retval=0 ;;
3454     ccache|!ccache) retval=0 ;;
3455     check|!check) retval=0 ;;
3456     compressdoc|!compressdoc) retval=0 ;;
3457     debug|!debug) retval=0 ;;
3458     distcc|!distcc) retval=0 ;;
3459     icecc|!icecc) retval=0 ;;
3460     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3461     libtool|!libtool) retval=0 ;;
3462     linuxsymlink|!linuxsymlink) retval=0 ;;
3463     pkgbuild|!pkgbuild) retval=0 ;;
3464     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3465     purge|!purge) retval=0 ;;
3466     qalint|!qalint) retval=0 ;;
3467     regentree|!regentree) retval=0 ;;
3468     resume|!resume) retval=0 ;;
3469     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3470     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3471     static|!static) retval=0 ;;
3472     stepbystep|!stepbystep) retval=0 ;;
3473     strip|!strip) retval=0 ;;
3474     verbose|!verbose) retval=0 ;;
3475     *) retval=1 ;;
3476     esac
3477    
3478     return "${retval}"
3479    }
3480    
3481    load_mage_features()
3482    {
3483     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3484     do
3485     FVERBOSE=off msetfeature ${i}
3486     done
3487    }
3488    
3489    msetfeature()
3490    {
3491     local feature
3492     local count
3493     local i
3494     local found
3495    
3496     for feature in $@
3497     do
3498     found=0
3499     count="${#MAGE_FEATURES_CURRENT[*]}"
3500    
3501     if ! known_mage_feature "${feature}"
3502     then
3503     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3504     return 3
3505     fi
3506    
3507     for ((i=0; i<count; i++))
3508     do
3509     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3510     then
3511     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3512     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3513     found=1
3514     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3515     then
3516     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3517     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3518     found=1
3519     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3520     then
3521     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3522     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3523     found=1
3524     fi
3525     done
3526    
3527     # if the feature was not found after proccessing the whole array
3528     # it was not declared. in this case enable it
3529     if [[ ${found} = 0 ]]
3530     then
3531     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3532     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3533     fi
3534    
3535     export MAGE_FEATURES_CURRENT
3536     done
3537    }
3538    
3539    mqueryfeature()
3540    {
3541     local feature="$1"
3542     local retval=1
3543     local i
3544    
3545     if known_mage_feature "${feature}"
3546     then
3547     for i in ${MAGE_FEATURES_CURRENT[*]}
3548     do
3549     if [[ ${i} = ${feature} ]]
3550     then
3551     retval=0
3552     break # found break here
3553     fi
3554     done
3555     else
3556     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3557     retval=3
3558     fi
3559    
3560     return ${retval}
3561    }
3562    
3563    mprintfeatures()
3564    {
3565     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3566     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3567     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3568    }

Legend:
Removed from v.1438  
changed lines
  Added in v.2867