Magellan Linux

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

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

revision 1548 by niro, Tue Dec 27 10:00:34 2011 UTC revision 3054 by niro, Tue Aug 1 15:51:22 2017 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"  COLRED="\033[1;6m\033[31m"
6  COLGREEN="\033[1;6m\033[32m"  COLGREEN="\033[1;6m\033[32m"
# Line 38  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 [[ -f ${file} ]]
75     then
76     if [[ -d ${rundir} ]]
77     then
78     pushd ${rundir} &> /dev/null
79    
80     # all file must be non-zero
81     retval=0
82     while read sum dest
83     do
84     if [ ! -s ${dest} ]
85     then
86     echo "${dest}: file is empty ;("
87     retval=127
88     fi
89     done < ${file}
90     if [[ ${retval} != 127 ]]
91     then
92     # be verbose here
93     ${cmd} -c ${file} #&> /dev/null
94     retval="$?"
95     fi
96    
97     popd &> /dev/null
98     else
99     retval=1
100     fi
101     else
102     echo "missing checksum file '${file}' ;("
103     retval=1
104     fi
105    
106     return "${retval}"
107    }
108    
109    mcheckemptydir()
110    {
111     local dir="$1"
112     local retval=1
113    
114     if [[ ! -d ${dir} ]]
115     then
116     echo "mcheckemptydir(): '${dir}' is not a directory!"
117     retval=3
118     else
119     shopt -s nullglob dotglob
120     files=( ${dir}/* )
121     (( ${#files[*]} )) || retval=0
122     shopt -u nullglob dotglob
123     fi
124    
125     return ${retval}
126    }
127    
128    unpack_package()
129    {
130     local magefile="$1"
131     local pkgname
132     local pkgfile
133     local pkgtype
134     local tar_opts
135    
136     pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
137     pkgfile="${pkgname}.${PKGSUFFIX}"
138     pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
139    
140     xtitle "[ Unpacking ${pkg} ]"
141    
142     # abort on virtual pkg
143     if [[ ${pkgtype} = virtual ]]
144     then
145     echo -ne " ${COLBLUE}---${COLDEFAULT}"
146     echo " !unpack virtual ${pkgname} ... "
147     continue
148     fi
149    
150     # abort on sources pkg
151     if [[ ${pkgtype} = sources ]]
152     then
153     echo -ne " ${COLBLUE}---${COLDEFAULT}"
154     echo " !unpack sources ${pkgname} ... "
155     continue
156     fi
157    
158     # busybox?
159     if need_busybox_support tar
160     then
161     tar_opts="xjf"
162     else
163     tar_opts="xjmf"
164     fi
165    
166     echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkgfile} ... "
167     tar ${tar_opts} ${PKGDIR}/${pkgfile} -C ${BUILDDIR} || die "Unpacking package ${pkgfile}"
168    }
169    
170  unpack_packages()  unpack_packages()
171  {  {
172   local list="$@"   local list="$@"
173   local magefile   local magefile
  local pkg  
  local pkgtype  
174   local count_current   local count_current
175   local count_total   local count_total
176   local tar_opts   local tar_opts
# Line 56  unpack_packages() Line 183  unpack_packages()
183    
184   for magefile in ${list}   for magefile in ${list}
185   do   do
186   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   unpack_package "${magefile}"
  pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"  
   
187   (( 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}"  
188   done   done
189    
190   # add a crlf for a better view   # add a crlf for a better view
# Line 107  fix_mtime() Line 204  fix_mtime()
204   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
205   touch \   touch \
206   --no-create \   --no-create \
207     --no-dereference \
208   --time=mtime \   --time=mtime \
209   --reference "${reference}" \   --reference="${reference}" \
210   "${pathto}"   "${pathto}"
211    
212   echo "${mtime}"   echo "${mtime}"
# Line 162  install_directories() Line 260  install_directories()
260   while read pathto posix user group   while read pathto posix user group
261   do   do
262   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
263   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
264    
265   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
266   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 238  install_files() Line 336  install_files()
336   case ${retval} in   case ${retval} in
337   # file is not protected - (over)write it   # file is not protected - (over)write it
338   0|3)   0|3)
339   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
340   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
341   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
342   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 256  install_files() Line 354  install_files()
354    
355   # file is protected, write backup file   # file is protected, write backup file
356   2)   2)
357   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
358   then   then
359   echo -en "${COLRED}"   echo -en "${COLRED}"
360   echo -n "! prot "   echo -n "! prot "
# Line 287  install_files() Line 385  install_files()
385    
386   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
387   4)   4)
388   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
389   then   then
390   echo -en "${COLRED}"   echo -en "${COLRED}"
391   echo -n "! ignr "   echo -n "! ignr "
# Line 346  install_symlinks() Line 444  install_symlinks()
444   while read pathto posix link mtime   while read pathto posix link mtime
445   do   do
446   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
447   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
448    
449   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
450    
451  # # fix mtime and db   # fix mtime and db
452  # fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
453  # "${pathto}" \   "${pathto}" \
454  # "${posix}" \   "${posix}" \
455  # "${link}" \   "${link}" \
456  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
457  # "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
458    
459   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
460    
# Line 396  install_blockdevices() Line 494  install_blockdevices()
494   while read pathto posix major minor user group   while read pathto posix major minor user group
495   do   do
496   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
497   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
498    
499   mknod -m "${posix}" "${MROOT}${pathto}"   mknod -m "${posix}" "${MROOT}${pathto}"
500   # make it optional atm !!   # make it optional atm !!
# Line 440  install_characterdevices() Line 538  install_characterdevices()
538   while read pathto posix major minor user group   while read pathto posix major minor user group
539   do   do
540   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
541   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
542    
543   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
544    
# Line 484  install_fifos() Line 582  install_fifos()
582   while read pathto posix user group   while read pathto posix user group
583   do   do
584   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
585   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FIFO: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
586    
587   mkfifo -m "${posix}" "${MROOT}${pathto}"   mkfifo -m "${posix}" "${MROOT}${pathto}"
588   chown "${user}:${group}" "${MROOT}${pathto}"   chown "${user}:${group}" "${MROOT}${pathto}"
# Line 669  remove_database_entry() Line 767  remove_database_entry()
767   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
768    
769   # remove virtuals only if no other exist   # remove virtuals only if no other exist
770   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]   if [[ $(count_installed_pkgs --pcat=${pcat} --pname=${pname}) -le 1 ]]
771   then   then
772   # first unregister virtuals   # first unregister virtuals
773   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
# Line 698  count_installed_pkgs() Line 796  count_installed_pkgs()
796   local i   local i
797    
798   # very basic getops   # very basic getops
799   for i in $*   for i in $@
800   do   do
801   case $1 in   case ${i} in
802   --pcat|-c) shift; pcat="$1" ;;   --pcat*) pcat="${i#*=}" ;;
803   --pname|-n) shift; pname="$1" ;;   --pname*) pname="${i#*=}" ;;
804   esac   esac
  shift  
805   done   done
806    
807   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 743  compare_mtime() Line 840  compare_mtime()
840    
841   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
842    
843   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
844   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
845   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  
846    
847   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
848    
# Line 818  remove_symlinks() Line 904  remove_symlinks()
904   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
905   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
906   then   then
907   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
908   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
909   continue   continue
910   fi   fi
# Line 830  remove_symlinks() Line 916  remove_symlinks()
916   # 1=keep me   #   # 1=keep me   #
917   case ${retval} in   case ${retval} in
918   0)   0)
919   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
920   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
921   ;;   ;;
922    
923   1)   1)
924   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
925   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
926   ;;   ;;
927   esac   esac
# Line 902  remove_files() Line 988  remove_files()
988    
989   if [ ! -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
990   then   then
991   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
992   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
993   continue   continue
994   fi   fi
# Line 928  remove_files() Line 1014  remove_files()
1014   case ${retval} in   case ${retval} in
1015   # file is not protected - delete it   # file is not protected - delete it
1016   0|3)   0|3)
1017   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
1018   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1019   ;;   ;;
1020    
1021   # file is protected, do not delete   # file is protected, do not delete
1022   2)   2)
1023   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1024   then   then
1025   echo -en "${COLRED}"   echo -en "${COLRED}"
1026   echo -n "! prot "   echo -n "! prot "
# Line 945  remove_files() Line 1031  remove_files()
1031    
1032   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
1033   4)   4)
1034   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1035   then   then
1036   echo -en "${COLRED}"   echo -en "${COLRED}"
1037   echo -n "! ignr "   echo -n "! ignr "
# Line 957  remove_files() Line 1043  remove_files()
1043   esac   esac
1044   ;;   ;;
1045   1)   1)
1046   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1047   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1048   ;;   ;;
1049   esac   esac
# Line 1019  remove_blockdevices() Line 1105  remove_blockdevices()
1105   do   do
1106   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1107    
1108   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1109   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1110   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1111    
# Line 1079  remove_characterdevices() Line 1165  remove_characterdevices()
1165   do   do
1166   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1167    
1168   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1169   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1170   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1171    
# Line 1141  remove_fifos() Line 1227  remove_fifos()
1227   do   do
1228   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1229    
1230   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1231   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1232   done < ${MROOT}${INSTALLDB}/${pfull}/.fifo   done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1233    
# Line 1202  remove_directories() Line 1288  remove_directories()
1288    
1289   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1290   then   then
1291   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1292   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1293   continue   continue
1294   fi   fi
# Line 1210  remove_directories() Line 1296  remove_directories()
1296   # exclude .keep directories   # exclude .keep directories
1297   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1298   then   then
1299   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1300   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1301   continue   continue
1302   fi   fi
# Line 1223  remove_directories() Line 1309  remove_directories()
1309    
1310   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1311   then   then
1312   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1313   else   else
1314   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1315   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1316   fi   fi
1317   done   done
# Line 1283  build_douninstall() Line 1369  build_douninstall()
1369   done   done
1370  }  }
1371    
1372    # convertmirrors [uri]
1373    convertmirrors()
1374    {
1375     local uri="$1"
1376     local scheme
1377     local mirror
1378     local mirrors
1379     local addon
1380     local real_uri
1381     local output
1382    
1383     # needs
1384     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1385     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1386     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1387     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1388     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1389    
1390     # check known uri schemes
1391     case ${uri} in
1392     http://*|https://*|ftp://*|ftps://*|file://*) mirrors="" ;;
1393     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1394     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1395     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1396     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1397     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1398     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1399     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1400     esac
1401    
1402     if [[ ! -z ${mirrors} ]]
1403     then
1404     for mirror in ${mirrors}
1405     do
1406     # add a whitespace to the output
1407     [[ -z ${output} ]] || output+=" "
1408     output+="${mirror}${addon}/${uri/${scheme}/}"
1409     done
1410     else
1411     output="${uri}"
1412     fi
1413    
1414     echo "${output}"
1415    }
1416    
1417    mdownload()
1418    {
1419     local i
1420     local uri
1421     local real_uris
1422     local mirror
1423     local outputfile
1424     local outputdir
1425     local retval
1426     local wget_opts
1427    
1428     # very basic getops
1429     for i in $*
1430     do
1431     case $1 in
1432     --uri|-u) shift; uri="$1" ;;
1433     --dir|-d) shift; outputdir="$1" ;;
1434     esac
1435     shift
1436     done
1437    
1438     # sanity checks; abort if not given
1439     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1440     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1441    
1442     # convert mirrored uris to the real ones
1443     real_uris="$(convertmirrors ${uri})"
1444    
1445     # verbose or not
1446     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1447    
1448     # filter wget options if busybox was found
1449     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1450    
1451     # create outputdir
1452     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1453    
1454     for mirror in ${real_uris}
1455     do
1456     # get the name of the output file
1457     outputfile="${mirror##*/}"
1458    
1459     case ${mirror} in
1460     file://*)
1461     cp -v "${mirror//file:\/\/}" "${outputdir}/${outputfile}"
1462     retval="$?"
1463     ;;
1464     *)
1465     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1466     retval="$?"
1467     ;;
1468     esac
1469    
1470     if [[ ${retval} = 0 ]]
1471     then
1472     break
1473     else
1474     continue
1475     fi
1476     done
1477    
1478     # return wget retval
1479     return "${retval}"
1480    }
1481    
1482  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1483  fetch_packages()  fetch_packages()
1484  {  {
1485     local i
1486   local list="$@"   local list="$@"
1487   local pkg   local pkgname
1488     local pkgfile
1489     local pcat
1490     local pname
1491   local mirr   local mirr
1492   local magefile   local magefile
1493   local md5file   local md5file
# Line 1295  fetch_packages() Line 1495  fetch_packages()
1495   local count_current   local count_current
1496   local count_total   local count_total
1497   local wget_opts   local wget_opts
1498     local fetching
1499    
1500   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1501    
# Line 1309  fetch_packages() Line 1510  fetch_packages()
1510    
1511   for magefile in ${list}   for magefile in ${list}
1512   do   do
1513   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1514     pkgfile="${pkgname}.${PKGSUFFIX}"
1515   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1516    
1517     pcat=$(magename2pcat ${magefile})
1518     pname=$(magename2pname ${magefile})
1519     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
1520    
1521   (( count_current++ ))   (( count_current++ ))
1522   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1523    
1524   # abort on virtual pkg   # abort on virtual pkg
1525   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1526   then   then
1527   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1528   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1529   continue   continue
1530   fi   fi
1531    
# Line 1327  fetch_packages() Line 1533  fetch_packages()
1533   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1534   then   then
1535   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1536   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1537   continue   continue
1538   fi   fi
1539    
1540   # abort if already exist   # check if FETCHING is required
1541   if [ -f ${PKGDIR}/${pkg} ]   if [ ! -f "${md5file}" ]
1542   then   then
1543   echo -ne " ${COLBLUE}***${COLDEFAULT}"   fetching=true
1544   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   else
1545   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 ]]  
1546   then   then
1547   break   # md5's ok, no fetching required
1548     fetching=false
1549   else   else
1550   continue   fetching=true
1551   fi   fi
1552   done   fi
1553    
1554   if [ ! -f ${PKGDIR}/${pkg} ]   if [[ ${fetching} = false ]]
1555   then   then
1556   die "Could not download ${pkg}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1557     echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1558     continue
1559     else
1560     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1561     echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1562     mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1563     fi
1564    
1565     # sanity check, not really needed but to be sure
1566     if [ ! -f ${PKGDIR}/${pkgfile} ]
1567     then
1568     die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1569   fi   fi
1570   done   done
1571    
# Line 1414  syncmage_tarball() Line 1620  syncmage_tarball()
1620    
1621   for mirr in ${MIRRORS}   for mirr in ${MIRRORS}
1622   do   do
1623   # path without distribution   # path without distribution
1624   mymirr="${mirr%/*}"   # (only for stable|testing|unstable and not DISTROTAG)
1625     case ${mirr##*/} in
1626     stable|testing|unstable) mymirr="${mirr%/*}";;
1627     *) mymirr="${mirr}";;
1628     esac
1629    
1630   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1631   echo "fetching latest md5 from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
1632   [[ ${VERBOSE} = off ]] && opt="--quiet"   mqueryfeature "!verbose" && opt="--quiet"
1633   wget \   wget \
1634   ${wget_opts} \   ${wget_opts} \
1635   --directory-prefix=${temp} \   --directory-prefix=${temp} \
# Line 1448  syncmage_tarball() Line 1658  syncmage_tarball()
1658   else   else
1659   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1660   echo -n "checking md5sum... "   echo -n "checking md5sum... "
1661   ( cd ${temp}; md5sum -c ${latest_md5} ) || die "md5 for ${latest_tarball} failed"   mchecksum --rundir "${temp}" --file "${temp}/${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1662   fi   fi
1663    
1664   if [[ -d ${MAGEDIR} ]]   if [[ -d ${MAGEDIR} ]]
1665   then   then
1666   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1667   echo "cleaning old mage-tree ${MAGEDIR}..."   echo "cleaning old mage-tree ${MAGEDIR}..."
1668   rm -rf ${MAGEDIR}   # honor mountpoints and empty dirs
1669     if mountpoint -q ${MAGEDIR}
1670     then
1671     if ! mcheckemptydir ${MAGEDIR}
1672     then
1673     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1674     fi
1675     else
1676     rm -rf ${MAGEDIR}
1677     fi
1678   fi   fi
1679    
1680   if need_busybox_support tar   if need_busybox_support tar
# Line 1514  xtitleclean() Line 1733  xtitleclean()
1733  }  }
1734    
1735    
1736  # cuts full pathnames or versionized names down to basename  # unused?
1737  choppkgname()  #
1738  {  # # cuts full pathnames or versionized names down to basename
1739   #we want this only if full name was used  # choppkgname()
1740   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1741   then  # #we want this only if full name was used
1742   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1743   #ARCH comes from ${MAGERC}  # then
1744   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1745    # #ARCH comes from ${MAGERC}
1746    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1747    #
1748    # #cuts version number
1749    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1750    # fi
1751    # }
1752    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1753    
1754  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1755  # $1=pname  # $1=pname
# Line 1606  get_highest_magefile() Line 1828  get_highest_magefile()
1828   then   then
1829   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1830   #for debug only   #for debug only
1831   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1832   fi   fi
1833   done   done
1834    
# Line 1713  count_protected_files() Line 1935  count_protected_files()
1935   local filename="${file##*/}"   local filename="${file##*/}"
1936   local count   local count
1937   local output   local output
1938     local oldprotected
1939   local i   local i
1940     local x
1941    
1942   declare -i count=0   # hack; do not honor a global set IFS like '§'
1943     local IFS
1944    
1945     count=0
1946    
1947   # check if there are already protected files   # check if there are already protected files
1948   for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |   for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1949   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1950   sort -t'%' -k3 -k2 | cut -f1 -d'%')   sort -t'%' -k3 -k2 | cut -f1 -d'%')
1951   do   do
1952   count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")   count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1953     done
1954    
1955     # convert 0001 -> 1; 0120 -> 120 etc
1956     # use bash internal base functions to this task
1957     x="$((10#${count}))"
1958     for (( i=0; i<x; i++ ))
1959     do
1960     if [[ ${count:${i}:1} != 0 ]]
1961     then
1962     count="${count:${i}}"
1963     break
1964     fi
1965   done   done
1966   (( count ++ ))  
1967     count="$(( ${count}+1 ))"
1968    
1969   # fill output up with zeros   # fill output up with zeros
1970   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 2254  minclude()
2254   then   then
2255   for i in $*   for i in $*
2256   do   do
2257   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2258   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2259   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2260   done   done
2261   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2262   fi   fi
2263  }  }
2264    
# Line 2030  sminclude() Line 2270  sminclude()
2270   then   then
2271   for i in $*   for i in $*
2272   do   do
2273   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2274   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2275   done   done
2276   echo   [[ ${SILENT} = 1 ]] || echo
2277   fi   fi
2278  }  }
2279    
# Line 2337  get_value_from_magefile() Line 2577  get_value_from_magefile()
2577   local SDEPEND   local SDEPEND
2578   local PROVIDE   local PROVIDE
2579   local PKGTYPE   local PKGTYPE
  local MAGE_TARGETS  
2580   local SPLIT_PACKAGE_BASE   local SPLIT_PACKAGE_BASE
2581   local preinstall   local preinstall
2582   local postinstall   local postinstall
# Line 2459  mage_install() Line 2698  mage_install()
2698   echo B:${pbuild}   echo B:${pbuild}
2699   fi   fi
2700    
2701   if [[ -n ${MAGE_TARGETS} ]]   if [[ -n ${SPLIT_PACKAGE_BASE} ]]
  then  
  # basic svn compat  
  if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]  
  then  
  for i in ${SMAGESCRIPTSDIR}/*/${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} ]]  
2702   then   then
2703   # basic svn compat   # basic svn compat
2704   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
# Line 2514  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 2602  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 2612  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 2620  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 2628  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 -c ${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 2668  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 2841  mage_uninstall() Line 3068  mage_uninstall()
3068   unset -f postremove   unset -f postremove
3069  }  }
3070    
3071    # rerun_pkgfunctions [method] pkg1 pkg2 pkg3
3072    rerun_pkgfunctions()
3073    {
3074     local method
3075     local list
3076     local pcat
3077     local pname
3078     local pver
3079     local pbuild
3080     local magefile
3081     local i
3082    
3083     # very basic getops
3084     case $1 in
3085     --method) shift; method="$1" ;;
3086     esac
3087     shift
3088     local list="$@"
3089    
3090     # sanity check
3091     case ${method} in
3092     preinstall|postinstall) ;;
3093     preremove|postremove) ;;
3094     *) die "rerun_pkgfunctions(): Unknown method '${method}'." ;;
3095     esac
3096    
3097     if [[ -n ${MROOT} ]]
3098     then
3099     echo -ne ${COLRED}
3100     echo "!! running in MROOT=${MROOT}"
3101     echo -ne ${COLDEFAULT}
3102     echo
3103     fi
3104    
3105     for pkg in ${list}
3106     do
3107     pcat=$(dep2pcat ${pkg})
3108     pname=$(magename2pname ${pkg})
3109     pver=$(magename2pver ${pkg})
3110     pbuild=$(magename2pbuild ${pkg})
3111     magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
3112    
3113     if [ -e ${magefile} ]
3114     then
3115     source ${magefile}
3116     if [ -n "$(typeset -f ${method})" ]
3117     then
3118     echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... "
3119     ${method}
3120     else
3121     echo "No ${method}() for pkg '${pkg}' defined. Doing nothing."
3122     fi
3123     unset -f preinstall postinstall preremove postremove
3124     else
3125     die "Magefile '${magefile}' does not exist."
3126     fi
3127     done
3128    }
3129    
3130  show_etc_update_mesg()  show_etc_update_mesg()
3131  {  {
3132   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
# Line 2868  pkgsearch() Line 3154  pkgsearch()
3154   local state   local state
3155   local descriptiom   local descriptiom
3156   local homepage   local homepage
3157     local license
3158   local i   local i
3159   local all_installed   local all_installed
3160   local ipver   local ipver
# Line 2904  pkgsearch() Line 3191  pkgsearch()
3191   state="$(get_value_from_magefile STATE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3192   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3193   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3194     license="$(get_value_from_magefile LICENSE ${magefile})"
3195    
3196   # all installed   # all installed
3197   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3198   do   do
3199   ipver="$(magename2pver ${i})"   ipver="$(magename2pver ${i})"
3200   ipbuild="$(magename2pbuild ${i})"   ipbuild="$(magename2pbuild ${i})"
3201    
3202   if [[ -z ${all_installed} ]]   if [[ -z ${all_installed} ]]
3203   then   then
3204   all_installed="${ipver}-${ipbuild}"   all_installed="${ipver}-${ipbuild}"
# Line 2919  pkgsearch() Line 3207  pkgsearch()
3207   fi   fi
3208   done   done
3209   [[ -z ${all_installed} ]] && all_installed="none"   [[ -z ${all_installed} ]] && all_installed="none"
3210    
3211   case ${state} in   case ${state} in
3212   stable) state=${COLGREEN}"[s] ";;   stable) state=${COLGREEN}"[s] ";;
3213   testing) state=${COLYELLOW}"[t] ";;   testing) state=${COLYELLOW}"[t] ";;
# Line 2943  pkgsearch() Line 3231  pkgsearch()
3231   "") continue;;   "") continue;;
3232   esac   esac
3233    
3234   deps="${deps} $(basename ${dep%-*})"   if [[ -z ${deps} ]]
3235     then
3236     deps="$(basename ${dep%-*})"
3237     else
3238     deps="${deps} $(basename ${dep%-*})"
3239     fi
3240   done << EOF   done << EOF
3241  ${depsfull}  ${depsfull}
3242  EOF  EOF
# Line 2954  EOF Line 3247  EOF
3247   "") continue;;   "") continue;;
3248   esac   esac
3249    
3250   sdeps="${sdeps} $(basename ${dep%-*})"   if [[ -z ${sdeps} ]]
3251     then
3252     sdeps="$(basename ${dep%-*})"
3253     else
3254     sdeps="${sdeps} $(basename ${dep%-*})"
3255     fi
3256   done << EOF   done << EOF
3257  ${sdepsfull}  ${sdepsfull}
3258  EOF  EOF
# Line 2964  EOF Line 3262  EOF
3262   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3263   echo "      Description: ${description}"   echo "      Description: ${description}"
3264   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3265   echo "      Depends: ${deps}"   if [[ ! -z ${license} ]]
3266     then
3267     echo "      License:  ${license}"
3268     fi
3269     echo "      Depends:  ${deps}"
3270   echo "      SDepends: ${sdeps}"   echo "      SDepends: ${sdeps}"
3271   echo   echo
3272    
# Line 3004  export_inherits() Line 3306  export_inherits()
3306   eval "${functions}() { ${include}_${functions} ; }"   eval "${functions}() { ${include}_${functions} ; }"
3307    
3308   # debug   # debug
3309   [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"   mqueryfeature "debug" && typeset -f "${functions}"
3310    
3311   shift   shift
3312   done   done
# Line 3081  EOF Line 3383  EOF
3383  need_busybox_support()  need_busybox_support()
3384  {  {
3385   local cmd   local cmd
3386     local busybox
3387   cmd="$1"   cmd="$1"
3388    
3389   if [[ -x /bin/busybox ]]   for busybox in {,/usr}/bin/busybox
3390   then   do
3391   if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]   if [[ -x ${busybox} ]]
3392   then   then
3393   # needs busybox support   if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3394   return 0   then
3395     # needs busybox support
3396     return 0
3397     fi
3398   fi   fi
3399   fi   done
3400    
3401   # no busybox   # no busybox
3402   return 1   return 1
# Line 3142  have_root_privileges() Line 3448  have_root_privileges()
3448    
3449   return ${retval}   return ${retval}
3450  }  }
3451    
3452    known_mage_feature()
3453    {
3454     local feature="$1"
3455     local retval
3456    
3457     case "${feature}" in
3458     autosvc|!autosvc) retval=0 ;;
3459     buildlog|!buildlog) retval=0 ;;
3460     ccache|!ccache) retval=0 ;;
3461     check|!check) retval=0 ;;
3462     compressdoc|!compressdoc) retval=0 ;;
3463     debug|!debug) retval=0 ;;
3464     distcc|!distcc) retval=0 ;;
3465     icecc|!icecc) retval=0 ;;
3466     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3467     libtool|!libtool) retval=0 ;;
3468     linuxsymlink|!linuxsymlink) retval=0 ;;
3469     pkgbuild|!pkgbuild) retval=0 ;;
3470     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3471     purge|!purge) retval=0 ;;
3472     qalint|!qalint) retval=0 ;;
3473     regentree|!regentree) retval=0 ;;
3474     resume|!resume) retval=0 ;;
3475     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3476     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3477     static|!static) retval=0 ;;
3478     stepbystep|!stepbystep) retval=0 ;;
3479     strip|!strip) retval=0 ;;
3480     verbose|!verbose) retval=0 ;;
3481     *) retval=1 ;;
3482     esac
3483    
3484     return "${retval}"
3485    }
3486    
3487    load_mage_features()
3488    {
3489     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3490     do
3491     FVERBOSE=off msetfeature ${i}
3492     done
3493    }
3494    
3495    msetfeature()
3496    {
3497     local feature
3498     local count
3499     local i
3500     local found
3501    
3502     for feature in $@
3503     do
3504     found=0
3505     count="${#MAGE_FEATURES_CURRENT[*]}"
3506    
3507     if ! known_mage_feature "${feature}"
3508     then
3509     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3510     return 3
3511     fi
3512    
3513     for ((i=0; i<count; i++))
3514     do
3515     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3516     then
3517     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3518     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3519     found=1
3520     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3521     then
3522     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3523     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3524     found=1
3525     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3526     then
3527     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3528     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3529     found=1
3530     fi
3531     done
3532    
3533     # if the feature was not found after proccessing the whole array
3534     # it was not declared. in this case enable it
3535     if [[ ${found} = 0 ]]
3536     then
3537     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3538     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3539     fi
3540    
3541     export MAGE_FEATURES_CURRENT
3542     done
3543    }
3544    
3545    mqueryfeature()
3546    {
3547     local feature="$1"
3548     local retval=1
3549     local i
3550    
3551     if known_mage_feature "${feature}"
3552     then
3553     for i in ${MAGE_FEATURES_CURRENT[*]}
3554     do
3555     if [[ ${i} = ${feature} ]]
3556     then
3557     retval=0
3558     break # found break here
3559     fi
3560     done
3561     else
3562     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3563     retval=3
3564     fi
3565    
3566     return ${retval}
3567    }
3568    
3569    mprintfeatures()
3570    {
3571     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3572     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3573     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3574    }

Legend:
Removed from v.1548  
changed lines
  Added in v.3054