Magellan Linux

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

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

revision 1209 by niro, Fri Jan 28 20:37:27 2011 UTC revision 2364 by niro, Mon Jan 6 12:53:31 2014 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
171    
172   # get count of total packages   # get count of total packages
173   declare -i count_current=0   declare -i count_current=0
# Line 32  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  
   
  echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "  
  tar xjmf ${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 75  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 130  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 207  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 219  install_files() Line 342  install_files()
342   "${user}" \   "${user}" \
343   "${group}" \   "${group}" \
344   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
345   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
346   "${md5sum}"   "${md5sum}"
347   ;;   ;;
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 246  install_files() Line 369  install_files()
369   "${user}" \   "${user}" \
370   "${group}" \   "${group}" \
371   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
372   "${dest_protected}")" \   "${dest_protected}")" \
373   "${md5sum}"   "${md5sum}"
374    
375   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
# Line 256  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 "
386   echo -en "${COLDEFAULT}"   echo -en "${COLDEFAULT}"
387   echo " === FILE: ${MROOT}${pathto}"   echo " === FILE: ${MROOT}${pathto}"
388   fi   fi
389   # simply do nothing here   # simply do nothing here - only fix mtime
390     fix_descriptor ${pkgname}/.files \
391     "${pathto}" \
392     "${posix}" \
393     "${user}" \
394     "${group}" \
395     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
396     "${MROOT}${pathto}")" \
397     "${md5sum}"
398   ;;   ;;
399   esac   esac
400   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
# Line 307  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 354  install_blockdevices() Line 485  install_blockdevices()
485   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
486   IFS=§   IFS=§
487    
488   while read pathto posix 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   mkfifo -m "${posix}" "${MROOT}${pathto}"   mknod -m "${posix}" "${MROOT}${pathto}"
494   chown "${user}:${group}" "${MROOT}${pathto}"   # make it optional atm !!
495     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
496     then
497     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
498     fi
499   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
500    
501   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 397  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}" c ${major} ${minor}   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
538   chown "${user}:${group}" "${MROOT}${pathto}"  
539     # make it optional atm !!
540     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
541     then
542     chown "${user}:${group}" "${MROOT}${pathto}"
543     fi
544   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
545    
546   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 426  install_fifos() Line 566  install_fifos()
566   # check needed global vars   # check needed global vars
567   [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."   [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
568    
569   [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"   # make it optional atm !!
570     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
571     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
572    
573   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
574   IFS=§   IFS=§
# Line 434  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 456  build_doinstall() Line 598  build_doinstall()
598    
599   # sanity checks; abort if not given   # sanity checks; abort if not given
600   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
601    
602   # this is only a wrapper   # this is only a wrapper
603    
604   # NOTE:   # NOTE:
# Line 553  install_database_entry() Line 695  install_database_entry()
695   local i   local i
696   for i in .char .dirs .files .pipes .symlinks .fifo   for i in .char .dirs .files .pipes .symlinks .fifo
697   do   do
698   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
699   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
700     then
701     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
702     fi
703   done   done
704   ;;   ;;
705   esac   esac
# Line 690  compare_mtime() Line 835  compare_mtime()
835    
836   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
837    
838   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
839   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
840   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  
841    
842   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
843    
# Line 765  remove_symlinks() Line 899  remove_symlinks()
899   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
900   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
901   then   then
902   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
903   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
904   continue   continue
905   fi   fi
# Line 777  remove_symlinks() Line 911  remove_symlinks()
911   # 1=keep me   #   # 1=keep me   #
912   case ${retval} in   case ${retval} in
913   0)   0)
914   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
915   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
916   ;;   ;;
917    
918   1)   1)
919   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
920   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
921   ;;   ;;
922   esac   esac
# Line 849  remove_files() Line 983  remove_files()
983    
984   if [ ! -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
985   then   then
986   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
987   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
988   continue   continue
989   fi   fi
# Line 875  remove_files() Line 1009  remove_files()
1009   case ${retval} in   case ${retval} in
1010   # file is not protected - delete it   # file is not protected - delete it
1011   0|3)   0|3)
1012   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
1013   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1014   ;;   ;;
1015    
1016   # file is protected, do not delete   # file is protected, do not delete
1017   2)   2)
1018   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1019   then   then
1020   echo -en "${COLRED}"   echo -en "${COLRED}"
1021   echo -n "! prot "   echo -n "! prot "
# Line 892  remove_files() Line 1026  remove_files()
1026    
1027   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
1028   4)   4)
1029   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1030   then   then
1031   echo -en "${COLRED}"   echo -en "${COLRED}"
1032   echo -n "! ignr "   echo -n "! ignr "
# Line 904  remove_files() Line 1038  remove_files()
1038   esac   esac
1039   ;;   ;;
1040   1)   1)
1041   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1042   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1043   ;;   ;;
1044   esac   esac
# Line 966  remove_blockdevices() Line 1100  remove_blockdevices()
1100   do   do
1101   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1102    
1103   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1104   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1105   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1106    
# Line 1026  remove_characterdevices() Line 1160  remove_characterdevices()
1160   do   do
1161   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1162    
1163   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1164   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1165   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1166    
# Line 1077  remove_fifos() Line 1211  remove_fifos()
1211   # check needed global vars   # check needed global vars
1212   [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."   [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1213    
1214   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"   # make it optional atm !!
1215     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1216     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1217    
1218   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1219   IFS=§   IFS=§
# Line 1086  remove_fifos() Line 1222  remove_fifos()
1222   do   do
1223   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1224    
1225   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1226   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1227   done < ${MROOT}${INSTALLDB}/${pfull}/.fifo   done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1228    
# Line 1147  remove_directories() Line 1283  remove_directories()
1283    
1284   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1285   then   then
1286   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1287   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1288   continue   continue
1289   fi   fi
# Line 1155  remove_directories() Line 1291  remove_directories()
1291   # exclude .keep directories   # exclude .keep directories
1292   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1293   then   then
1294   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1295   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1296   continue   continue
1297   fi   fi
# Line 1168  remove_directories() Line 1304  remove_directories()
1304    
1305   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1306   then   then
1307   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1308   else   else
1309   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1310   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1311   fi   fi
1312   done   done
# Line 1228  build_douninstall() Line 1364  build_douninstall()
1364   done   done
1365  }  }
1366    
1367    # convertmirrors [uri]
1368    convertmirrors()
1369    {
1370     local uri="$1"
1371     local scheme
1372     local mirror
1373     local mirrors
1374     local addon
1375     local real_uri
1376     local output
1377    
1378     # needs
1379     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1380     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1381     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1382     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1383     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1384    
1385     # check known uri schemes
1386     case ${uri} in
1387     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1388     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1389     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1390     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1391     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1392     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1393     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1394     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1395     esac
1396    
1397     if [[ ! -z ${mirrors} ]]
1398     then
1399     for mirror in ${mirrors}
1400     do
1401     # add a whitespace to the output
1402     [[ -z ${output} ]] || output+=" "
1403     output+="${mirror}${addon}/${uri/${scheme}/}"
1404     done
1405     else
1406     output="${uri}"
1407     fi
1408    
1409     echo "${output}"
1410    }
1411    
1412    mdownload()
1413    {
1414     local i
1415     local uri
1416     local real_uris
1417     local mirror
1418     local outputfile
1419     local outputdir
1420     local retval
1421     local wget_opts
1422    
1423     # very basic getops
1424     for i in $*
1425     do
1426     case $1 in
1427     --uri|-u) shift; uri="$1" ;;
1428     --dir|-d) shift; outputdir="$1" ;;
1429     esac
1430     shift
1431     done
1432    
1433     # sanity checks; abort if not given
1434     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1435     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1436    
1437     # convert mirrored uris to the real ones
1438     real_uris="$(convertmirrors ${uri})"
1439    
1440     # verbose or not
1441     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1442    
1443     # filter wget options if busybox was found
1444     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1445    
1446     # create outputdir
1447     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1448    
1449     for mirror in ${real_uris}
1450     do
1451     # get the name of the output file
1452     outputfile="${mirror##*/}"
1453    
1454     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1455     retval="$?"
1456     if [[ ${retval} = 0 ]]
1457     then
1458     break
1459     else
1460     continue
1461     fi
1462     done
1463    
1464     # return wget retval
1465     return "${retval}"
1466    }
1467    
1468  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1469  fetch_packages()  fetch_packages()
1470  {  {
1471     local i
1472   local list="$@"   local list="$@"
1473   local pkg   local pkgname
1474     local pkgfile
1475     local pcat
1476     local pname
1477   local mirr   local mirr
1478   local magefile   local magefile
1479   local md5file   local md5file
1480   local opt   local opt
1481   local count_current   local count_current
1482   local count_total   local count_total
1483     local wget_opts
1484     local fetching
1485    
1486   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1487    
1488     # filter wget command if busybox was found
1489     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1490    
1491   # get count of total packages   # get count of total packages
1492   declare -i count_current=0   declare -i count_current=0
1493   declare -i count_total=0   declare -i count_total=0
# Line 1250  fetch_packages() Line 1496  fetch_packages()
1496    
1497   for magefile in ${list}   for magefile in ${list}
1498   do   do
1499   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1500     pkgfile="${pkgname}.${PKGSUFFIX}"
1501   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1502    
1503     pcat=$(magename2pcat ${magefile})
1504     pname=$(magename2pname ${magefile})
1505     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
1506    
1507   (( count_current++ ))   (( count_current++ ))
1508   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1509    
1510   # abort on virtual pkg   # abort on virtual pkg
1511   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1512   then   then
1513   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1514   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1515   continue   continue
1516   fi   fi
1517    
# Line 1268  fetch_packages() Line 1519  fetch_packages()
1519   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1520   then   then
1521   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1522   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1523   continue   continue
1524   fi   fi
1525    
1526   # abort if already exist   # check if FETCHING is required
1527   if [ -f ${PKGDIR}/${pkg} ]   if [ ! -f "${md5file}" ]
1528   then   then
1529   echo -ne " ${COLBLUE}***${COLDEFAULT}"   fetching=true
1530   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   else
1531   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_FETCH_OPTIONS} \  
  --directory-prefix=${PKGDIR} \  
  ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}  
  if [[ $? = 0 ]]  
1532   then   then
1533   break   # md5's ok, no fetching required
1534     fetching=false
1535   else   else
1536   continue   fetching=true
1537   fi   fi
1538   done   fi
1539    
1540   if [ ! -f ${PKGDIR}/${pkg} ]   if [[ ${fetching} = false ]]
1541   then   then
1542   die "Could not download ${pkg}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1543     echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1544     continue
1545     else
1546     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1547     echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1548     mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1549     fi
1550    
1551     # sanity check, not really needed but to be sure
1552     if [ ! -f ${PKGDIR}/${pkgfile} ]
1553     then
1554     die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1555   fi   fi
1556   done   done
1557    
# Line 1328  syncmage() Line 1579  syncmage()
1579   done   done
1580    
1581   # clean up backup files (foo~)   # clean up backup files (foo~)
1582   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1583    
1584   # check if a newer mage version is available   # check if a newer mage version is available
1585   is_newer_mage_version_available   is_newer_mage_version_available
# Line 1341  syncmage_tarball() Line 1592  syncmage_tarball()
1592   local temp="$(mktemp -d)"   local temp="$(mktemp -d)"
1593   local mirr mymirr   local mirr mymirr
1594   local opt   local opt
1595     local tar_opts
1596     local wget_opts
1597    
1598   # try to get the md5 marked as latest on the server   # try to get the md5 marked as latest on the server
1599   latest_md5="mage-latest.md5"   latest_md5="mage-latest.md5"
# Line 1348  syncmage_tarball() Line 1601  syncmage_tarball()
1601   # try to get the tarball marked as latest on the server   # try to get the tarball marked as latest on the server
1602   latest_tarball="mage-latest.tar.bz2"   latest_tarball="mage-latest.tar.bz2"
1603    
1604     # filter wget command if busybox was found
1605     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1606    
1607   for mirr in ${MIRRORS}   for mirr in ${MIRRORS}
1608   do   do
1609   # path without distribution   # path without distribution
1610   mymirr="${mirr%/*}"   # (only for stable|testing|unstable and not DISTROTAG)
1611     case ${mirr##*/} in
1612     stable|testing|unstable) mymirr="${mirr%/*}";;
1613     *) mymirr="${mirr}";;
1614     esac
1615    
1616   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1617   echo "fetching latest md5 from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
1618   [[ ${VERBOSE} = off ]] && opt="--quiet"   mqueryfeature "!verbose" && opt="--quiet"
1619   wget \   wget \
1620   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1621   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1622   ${opt} ${mymirr}/rsync/tarballs/${latest_md5}   ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1623    
1624   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1625   echo "fetching latest tarball from ${mymirr} ..."   echo "fetching latest tarball from ${mymirr} ..."
1626   wget \   wget \
1627   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1628   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1629   ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}   ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1630   if [[ $? = 0 ]]   if [[ $? = 0 ]]
# Line 1384  syncmage_tarball() Line 1644  syncmage_tarball()
1644   else   else
1645   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1646   echo -n "checking md5sum... "   echo -n "checking md5sum... "
1647   ( cd ${temp}; md5sum --check ${latest_md5} ) || die "md5 for ${latest_tarball} failed"   mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1648   fi   fi
1649    
1650   if [[ -d ${MAGEDIR} ]]   if [[ -d ${MAGEDIR} ]]
1651   then   then
1652   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1653   echo "cleaning old mage-tree ${MAGEDIR}..."   echo "cleaning old mage-tree ${MAGEDIR}..."
1654   rm -rf ${MAGEDIR}   # honor mountpoints and empty dirs
1655     if mountpoint -q ${MAGEDIR}
1656     then
1657     if ! mcheckemptydir ${MAGEDIR}
1658     then
1659     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1660     fi
1661     else
1662     rm -rf ${MAGEDIR}
1663     fi
1664     fi
1665    
1666     if need_busybox_support tar
1667     then
1668     tar_opts="xjf"
1669     else
1670     tar_opts="xjmf"
1671   fi   fi
1672    
1673   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1674   echo "updating mage-tree from tarball ..."   echo "updating mage-tree from tarball ..."
1675   # unpack in dirname of MAGEDIR, as the tarball has already the mage   # unpack in dirname of MAGEDIR, as the tarball has already the mage
1676   tar xjmf ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"   tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1677    
1678   if [[ -d ${temp} ]]   if [[ -d ${temp} ]]
1679   then   then
# Line 1443  xtitleclean() Line 1719  xtitleclean()
1719  }  }
1720    
1721    
1722  # cuts full pathnames or versioniezed names down to basename  # unused?
1723  choppkgname()  #
1724  {  # # cuts full pathnames or versionized names down to basename
1725   #we want this only if full name was used  # choppkgname()
1726   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1727   then  # #we want this only if full name was used
1728   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1729   #ARCH comes from ${MAGERC}  # then
1730   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1731    # #ARCH comes from ${MAGERC}
1732    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1733    #
1734    # #cuts version number
1735    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1736    # fi
1737    # }
1738    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1739    
1740  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1741  # $1=pname  # $1=pname
# Line 1526  get_highest_magefile() Line 1805  get_highest_magefile()
1805   local magefile   local magefile
1806    
1807   # do not list the content of a directory, only the name (-d)   # do not list the content of a directory, only the name (-d)
1808   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)
1809   do   do
1810   [[ -z ${magefile} ]] && continue   [[ -z ${magefile} ]] && continue
1811   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
# Line 1535  get_highest_magefile() Line 1814  get_highest_magefile()
1814   then   then
1815   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1816   #for debug only   #for debug only
1817   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1818   fi   fi
1819   done   done
1820    
 # 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  
   
1821   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1822   return 0   return 0
1823  }  }
# Line 1664  count_protected_files() Line 1921  count_protected_files()
1921   local filename="${file##*/}"   local filename="${file##*/}"
1922   local count   local count
1923   local output   local output
1924     local oldprotected
1925   local i   local i
1926     local x
1927    
1928     # hack; do not honor a global set IFS like '§'
1929     local IFS
1930    
1931   declare -i count=0   count=0
1932    
1933   # check if there are already protected files   # check if there are already protected files
1934   for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |   for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1935   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1936   sort -t'%' -k3 -k2 | cut -f1 -d'%')   sort -t'%' -k3 -k2 | cut -f1 -d'%')
1937   do   do
1938   count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")   count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1939   done   done
1940   (( count ++ ))  
1941     # convert 0001 -> 1; 0120 -> 120 etc
1942     # use bash internal base functions to this task
1943     x="$((10#${count}))"
1944     for (( i=0; i<x; i++ ))
1945     do
1946     if [[ ${count:${i}:1} != 0 ]]
1947     then
1948     count="${count:${i}}"
1949     break
1950     fi
1951     done
1952    
1953     count="$(( ${count}+1 ))"
1954    
1955   # fill output up with zeros   # fill output up with zeros
1956   for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done   for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
# Line 1965  minclude() Line 2240  minclude()
2240   then   then
2241   for i in $*   for i in $*
2242   do   do
2243   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2244   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2245   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2246   done   done
2247   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2248   fi   fi
2249  }  }
2250    
# Line 1981  sminclude() Line 2256  sminclude()
2256   then   then
2257   for i in $*   for i in $*
2258   do   do
2259   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2260   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2261   done   done
2262   echo   [[ ${SILENT} = 1 ]] || echo
2263   fi   fi
2264  }  }
2265    
# Line 2413  mage_install() Line 2688  mage_install()
2688   if [[ -n ${MAGE_TARGETS} ]]   if [[ -n ${MAGE_TARGETS} ]]
2689   then   then
2690   # basic svn compat   # basic svn compat
2691   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2692   then   then
2693   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
2694   do   do
2695   smage2file="${i}"   smage2file="${i}"
2696   done   done
# Line 2426  mage_install() Line 2701  mage_install()
2701   elif [[ -n ${SPLIT_PACKAGE_BASE} ]]   elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2702   then   then
2703   # basic svn compat   # basic svn compat
2704   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2705   then   then
2706   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
2707   do   do
2708   smage2file="${i}"   smage2file="${i}"
2709   done   done
# Line 2438  mage_install() Line 2713  mage_install()
2713    
2714   else   else
2715   # basic svn compat   # basic svn compat
2716   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2717   then   then
2718   for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2719   do   do
2720   smage2file="${i}"   smage2file="${i}"
2721   done   done
# Line 2465  mage_install() Line 2740  mage_install()
2740   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2741   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2742   then   then
2743     unpack_package "${magefile}"
2744   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
2745   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2746   fi   fi
# Line 2553  md5sum_packages() Line 2829  md5sum_packages()
2829   pname=$(magename2pname ${magefile})   pname=$(magename2pname ${magefile})
2830   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2831   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2832   pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
2833   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2834    
2835   (( count_current++ ))   (( count_current++ ))
# Line 2563  md5sum_packages() Line 2839  md5sum_packages()
2839   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
2840   then   then
2841   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2842   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... "
2843   continue   continue
2844   fi   fi
2845    
# Line 2571  md5sum_packages() Line 2847  md5sum_packages()
2847   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
2848   then   then
2849   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2850   echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... "
2851   continue   continue
2852   fi   fi
2853    
# Line 2579  md5sum_packages() Line 2855  md5sum_packages()
2855   then   then
2856   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2857   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2858   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2859   else   else
2860   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2861   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2619  uninstall_packages() Line 2895  uninstall_packages()
2895   pbuild=$(magename2pbuild ${pkg})   pbuild=$(magename2pbuild ${pkg})
2896   can_pcat="${pcat}"   can_pcat="${pcat}"
2897   can_pname="${pname}"   can_pname="${pname}"
2898    
2899   if [ -z "${can_ver_list}" ]   if [ -z "${can_ver_list}" ]
2900   then   then
2901   can_ver_list=" ${pver}-${pbuild}"   can_ver_list=" ${pver}-${pbuild}"
# Line 2819  pkgsearch() Line 3095  pkgsearch()
3095   local state   local state
3096   local descriptiom   local descriptiom
3097   local homepage   local homepage
3098     local license
3099   local i   local i
3100   local all_installed   local all_installed
3101   local ipver   local ipver
# Line 2855  pkgsearch() Line 3132  pkgsearch()
3132   state="$(get_value_from_magefile STATE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3133   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3134   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3135     license="$(get_value_from_magefile LICENSE ${magefile})"
3136    
3137   # all installed   # all installed
3138   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3139   do   do
3140   ipver="$(magename2pver ${i})"   ipver="$(magename2pver ${i})"
3141   ipbuild="$(magename2pbuild ${i})"   ipbuild="$(magename2pbuild ${i})"
3142    
3143   if [[ -z ${all_installed} ]]   if [[ -z ${all_installed} ]]
3144   then   then
3145   all_installed="${ipver}-${ipbuild}"   all_installed="${ipver}-${ipbuild}"
# Line 2870  pkgsearch() Line 3148  pkgsearch()
3148   fi   fi
3149   done   done
3150   [[ -z ${all_installed} ]] && all_installed="none"   [[ -z ${all_installed} ]] && all_installed="none"
3151    
3152   case ${state} in   case ${state} in
3153   stable) state=${COLGREEN}"[s] ";;   stable) state=${COLGREEN}"[s] ";;
3154   testing) state=${COLYELLOW}"[t] ";;   testing) state=${COLYELLOW}"[t] ";;
# Line 2894  pkgsearch() Line 3172  pkgsearch()
3172   "") continue;;   "") continue;;
3173   esac   esac
3174    
3175   deps="${deps} $(basename ${dep%-*})"   if [[ -z ${deps} ]]
3176     then
3177     deps="$(basename ${dep%-*})"
3178     else
3179     deps="${deps} $(basename ${dep%-*})"
3180     fi
3181   done << EOF   done << EOF
3182  ${depsfull}  ${depsfull}
3183  EOF  EOF
# Line 2905  EOF Line 3188  EOF
3188   "") continue;;   "") continue;;
3189   esac   esac
3190    
3191   sdeps="${sdeps} $(basename ${dep%-*})"   if [[ -z ${sdeps} ]]
3192     then
3193     sdeps="$(basename ${dep%-*})"
3194     else
3195     sdeps="${sdeps} $(basename ${dep%-*})"
3196     fi
3197   done << EOF   done << EOF
3198  ${sdepsfull}  ${sdepsfull}
3199  EOF  EOF
# Line 2915  EOF Line 3203  EOF
3203   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3204   echo "      Description: ${description}"   echo "      Description: ${description}"
3205   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3206   echo "      Depends: ${deps}"   if [[ ! -z ${license} ]]
3207     then
3208     echo "      License:  ${license}"
3209     fi
3210     echo "      Depends:  ${deps}"
3211   echo "      SDepends: ${sdeps}"   echo "      SDepends: ${sdeps}"
3212   echo   echo
3213    
# Line 2955  export_inherits() Line 3247  export_inherits()
3247   eval "${functions}() { ${include}_${functions} ; }"   eval "${functions}() { ${include}_${functions} ; }"
3248    
3249   # debug   # debug
3250   [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"   mqueryfeature "debug" && typeset -f "${functions}"
3251    
3252   shift   shift
3253   done   done
# Line 3027  EOF Line 3319  EOF
3319   return 0   return 0
3320  }  }
3321    
3322    # need_busybox_support ${cmd}
3323    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3324    need_busybox_support()
3325    {
3326     local cmd
3327     local busybox
3328     cmd="$1"
3329    
3330     for busybox in {,/usr}/bin/busybox
3331     do
3332     if [[ -x ${busybox} ]]
3333     then
3334     if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3335     then
3336     # needs busybox support
3337     return 0
3338     fi
3339     fi
3340     done
3341    
3342     # no busybox
3343     return 1
3344    }
3345    
3346    # busybox_filter_wget_options ${wget_opts}
3347    busybox_filter_wget_options()
3348    {
3349     local opts="$@"
3350     local i
3351     local fixed_opts
3352    
3353     if need_busybox_support wget
3354     then
3355     for i in ${opts}
3356     do
3357     # show only the allowed ones
3358     case ${i} in
3359     -c|--continue) fixed_opts+=" -c" ;;
3360     -s|--spider) fixed_opts+=" -s" ;;
3361     -q|--quiet) fixed_opts+=" -q" ;;
3362     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3363     --header) shift; fixed_opts+=" --header $1" ;;
3364     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3365     -P) shift; fixed_opts+=" -P $1" ;;
3366     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3367     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3368     # simply drop all other opts
3369     *) continue ;;
3370     esac
3371     done
3372    
3373     echo "${fixed_opts}"
3374     else
3375     echo "${opts}"
3376     fi
3377    }
3378    
3379    have_root_privileges()
3380    {
3381     local retval
3382    
3383     if [[ $(id -u) = 0 ]]
3384     then
3385     retval=0
3386     else
3387     retval=1
3388     fi
3389    
3390     return ${retval}
3391    }
3392    
3393    known_mage_feature()
3394    {
3395     local feature="$1"
3396     local retval
3397    
3398     case "${feature}" in
3399     autosvc|!autosvc) retval=0 ;;
3400     buildlog|!buildlog) retval=0 ;;
3401     ccache|!ccache) retval=0 ;;
3402     check|!check) retval=0 ;;
3403     compressdoc|!compressdoc) retval=0 ;;
3404     debug|!debug) retval=0 ;;
3405     distcc|!distcc) retval=0 ;;
3406     icecc|!icecc) retval=0 ;;
3407     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3408     libtool|!libtool) retval=0 ;;
3409     linuxsymlink|!linuxsymlink) retval=0 ;;
3410     pkgbuild|!pkgbuild) retval=0 ;;
3411     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3412     purge|!purge) retval=0 ;;
3413     qalint|!qalint) retval=0 ;;
3414     regentree|!regentree) retval=0 ;;
3415     resume|!resume) retval=0 ;;
3416     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3417     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3418     static|!static) retval=0 ;;
3419     stepbystep|!stepbystep) retval=0 ;;
3420     strip|!strip) retval=0 ;;
3421     verbose|!verbose) retval=0 ;;
3422     *) retval=1 ;;
3423     esac
3424    
3425     return "${retval}"
3426    }
3427    
3428    load_mage_features()
3429    {
3430     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3431     do
3432     FVERBOSE=off msetfeature ${i}
3433     done
3434    }
3435    
3436    msetfeature()
3437    {
3438     local feature
3439     local count
3440     local i
3441     local found
3442    
3443     for feature in $@
3444     do
3445     found=0
3446     count="${#MAGE_FEATURES_CURRENT[*]}"
3447    
3448     if ! known_mage_feature "${feature}"
3449     then
3450     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3451     return 3
3452     fi
3453    
3454     for ((i=0; i<count; i++))
3455     do
3456     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3457     then
3458     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3459     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3460     found=1
3461     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3462     then
3463     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3464     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3465     found=1
3466     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3467     then
3468     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3469     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3470     found=1
3471     fi
3472     done
3473    
3474     # if the feature was not found after proccessing the whole array
3475     # it was not declared. in this case enable it
3476     if [[ ${found} = 0 ]]
3477     then
3478     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3479     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3480     fi
3481    
3482     export MAGE_FEATURE_CURRENT
3483     done
3484    }
3485    
3486    mqueryfeature()
3487    {
3488     local feature="$1"
3489     local retval=1
3490     local i
3491    
3492     if known_mage_feature "${feature}"
3493     then
3494     for i in ${MAGE_FEATURES_CURRENT[*]}
3495     do
3496     if [[ ${i} = ${feature} ]]
3497     then
3498     retval=0
3499     break # found break here
3500     fi
3501     done
3502     else
3503     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3504     retval=3
3505     fi
3506    
3507     return ${retval}
3508    }
3509    
3510    mprintfeatures()
3511    {
3512     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3513     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3514     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3515    }

Legend:
Removed from v.1209  
changed lines
  Added in v.2364