Magellan Linux

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

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

trunk/mage/usr/lib/mage/mage4.functions.sh revision 1502 by niro, Tue Aug 30 10:39:28 2011 UTC branches/mage-next/src/mage4.functions.sh.in revision 2811 by niro, Wed Sep 3 12:01:21 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  mage_setup()  mage_setup()
6  {  {
# Line 15  mage_setup() Line 15  mage_setup()
15   return 0   return 0
16  }  }
17    
18    mchecksum()
19    {
20     local i
21     local rundir
22     local file
23     local method
24     local cmd
25     local retval
26     local sum
27     local dest
28    
29     # very basic getops
30     for i in $*
31     do
32     case $1 in
33     --rundir|-r) shift; rundir="$1" ;;
34     --file|-f) shift; file="$1" ;;
35     --method|-m) shift; method="$1" ;;
36     esac
37     shift
38     done
39    
40     # sanity checks
41     [[ -z ${rundir} ]] && die "mchecksum(): rundir missing"
42     [[ -z ${file} ]] && die "mchecksum(): file missing"
43     [[ -z ${method} ]] && die "mchecksum(): method missing"
44    
45     case ${method} in
46     md5) cmd="md5sum" ;;
47     sha256) cmd="sha256sum" ;;
48     *) die "mchecksum(): unknown method '${method}'" ;;
49     esac
50    
51     if [[ -d ${rundir} ]]
52     then
53     pushd ${rundir} &> /dev/null
54    
55     # all file must be non-zero
56     retval=0
57     while read sum dest
58     do
59     if [ ! -s ${dest} ]
60     then
61     echo "${dest}: file is empty ;("
62     retval=127
63     fi
64     done < ${file}
65     if [[ ${retval} != 127 ]]
66     then
67     # be verbose here
68     ${cmd} -c ${file} #&> /dev/null
69     retval="$?"
70     fi
71    
72     popd &> /dev/null
73     else
74     retval=1
75     fi
76    
77     return "${retval}"
78    }
79    
80    mcheckemptydir()
81    {
82     local dir="$1"
83     local retval=1
84    
85     if [[ ! -d ${dir} ]]
86     then
87     echo "mcheckemptydir(): '${dir}' is not a directory!"
88     retval=3
89     else
90     shopt -s nullglob dotglob
91     files=( ${dir}/* )
92     (( ${#files[*]} )) || retval=0
93     shopt -u nullglob dotglob
94     fi
95    
96     return ${retval}
97    }
98    
99    unpack_package()
100    {
101     local magefile="$1"
102     local pkgname
103     local pkgfile
104     local pkgtype
105     local tar_opts
106    
107     pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
108     pkgfile="${pkgname}.${PKGSUFFIX}"
109     pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
110    
111     xtitle "[ Unpacking ${pkg} ]"
112    
113     # abort on virtual pkg
114     if [[ ${pkgtype} = virtual ]]
115     then
116     echo -ne " ${COLBLUE}---${COLDEFAULT}"
117     echo " !unpack virtual ${pkgname} ... "
118     continue
119     fi
120    
121     # abort on sources pkg
122     if [[ ${pkgtype} = sources ]]
123     then
124     echo -ne " ${COLBLUE}---${COLDEFAULT}"
125     echo " !unpack sources ${pkgname} ... "
126     continue
127     fi
128    
129     # busybox?
130     if need_busybox_support tar
131     then
132     tar_opts="xjf"
133     else
134     tar_opts="xjmf"
135     fi
136    
137     echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkgfile} ... "
138     tar ${tar_opts} ${PKGDIR}/${pkgfile} -C ${BUILDDIR} || die "Unpacking package ${pkgfile}"
139    }
140    
141  unpack_packages()  unpack_packages()
142  {  {
143   local list="$@"   local list="$@"
144   local magefile   local magefile
  local pkg  
  local pkgtype  
145   local count_current   local count_current
146   local count_total   local count_total
147   local tar_opts   local tar_opts
# Line 33  unpack_packages() Line 154  unpack_packages()
154    
155   for magefile in ${list}   for magefile in ${list}
156   do   do
157   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   unpack_package "${magefile}"
  pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"  
   
158   (( 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}"  
159   done   done
160    
161   # add a crlf for a better view   # add a crlf for a better view
162   if [ ${count_total} -gt 1 ]; then echo; fi   if [ ${count_total} -gt 1 ]; then echo; fi
163  }  }
164    
   
165  # fix_mtime path/to/$mtime/reffile $pathto/file  # fix_mtime path/to/$mtime/reffile $pathto/file
166  # creates a given reference file and fixes given file  # creates a given reference file and fixes given file
167  # returns new mtime  # returns new mtime
# Line 84  fix_mtime() Line 174  fix_mtime()
174   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
175   touch \   touch \
176   --no-create \   --no-create \
177     --no-dereference \
178   --time=mtime \   --time=mtime \
179   --reference "${reference}" \   --reference="${reference}" \
180   "${pathto}"   "${pathto}"
181    
182   echo "${mtime}"   echo "${mtime}"
# Line 139  install_directories() Line 230  install_directories()
230   while read pathto posix user group   while read pathto posix user group
231   do   do
232   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
233   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
   
234    
235   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
236   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 216  install_files() Line 306  install_files()
306   case ${retval} in   case ${retval} in
307   # file is not protected - (over)write it   # file is not protected - (over)write it
308   0|3)   0|3)
309   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
310   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
311   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
312   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 234  install_files() Line 324  install_files()
324    
325   # file is protected, write backup file   # file is protected, write backup file
326   2)   2)
327   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
328   then   then
329   echo -en "${COLRED}"   echo -en "${COLRED}"
330   echo -n "! prot "   echo -n "! prot "
# Line 265  install_files() Line 355  install_files()
355    
356   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
357   4)   4)
358   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
359   then   then
360   echo -en "${COLRED}"   echo -en "${COLRED}"
361   echo -n "! ignr "   echo -n "! ignr "
# Line 324  install_symlinks() Line 414  install_symlinks()
414   while read pathto posix link mtime   while read pathto posix link mtime
415   do   do
416   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
417   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
418    
419   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
420    
421  # # fix mtime and db   # fix mtime and db
422  # fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
423  # "${pathto}" \   "${pathto}" \
424  # "${posix}" \   "${posix}" \
425  # "${link}" \   "${link}" \
426  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
427  # "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
428    
429   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
430    
# Line 374  install_blockdevices() Line 464  install_blockdevices()
464   while read pathto posix major minor user group   while read pathto posix major minor user group
465   do   do
466   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
467   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
468    
469   mknod -m "${posix}" "${MROOT}${pathto}"   mknod -m "${posix}" "${MROOT}${pathto}"
470   # make it optional atm !!   # make it optional atm !!
# Line 418  install_characterdevices() Line 508  install_characterdevices()
508   while read pathto posix major minor user group   while read pathto posix major minor user group
509   do   do
510   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
511   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
512    
513   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
514    
# Line 462  install_fifos() Line 552  install_fifos()
552   while read pathto posix user group   while read pathto posix user group
553   do   do
554   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
555   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FIFO: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
556    
557   mkfifo -m "${posix}" "${MROOT}${pathto}"   mkfifo -m "${posix}" "${MROOT}${pathto}"
558   chown "${user}:${group}" "${MROOT}${pathto}"   chown "${user}:${group}" "${MROOT}${pathto}"
# Line 647  remove_database_entry() Line 737  remove_database_entry()
737   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
738    
739   # remove virtuals only if no other exist   # remove virtuals only if no other exist
740   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]   if [[ $(count_installed_pkgs --pcat=${pcat} --pname=${pname}) -le 1 ]]
741   then   then
742   # first unregister virtuals   # first unregister virtuals
743   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
# Line 676  count_installed_pkgs() Line 766  count_installed_pkgs()
766   local i   local i
767    
768   # very basic getops   # very basic getops
769   for i in $*   for i in $@
770   do   do
771   case $1 in   case ${i} in
772   --pcat|-c) shift; pcat="$1" ;;   --pcat*) pcat="${i#*=}" ;;
773   --pname|-n) shift; pname="$1" ;;   --pname*) pname="${i#*=}" ;;
774   esac   esac
  shift  
775   done   done
776    
777   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 721  compare_mtime() Line 810  compare_mtime()
810    
811   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
812    
813   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
814   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
815   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  
816    
817   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
818    
# Line 796  remove_symlinks() Line 874  remove_symlinks()
874   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
875   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
876   then   then
877   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
878   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
879   continue   continue
880   fi   fi
# Line 808  remove_symlinks() Line 886  remove_symlinks()
886   # 1=keep me   #   # 1=keep me   #
887   case ${retval} in   case ${retval} in
888   0)   0)
889   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
890   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
891   ;;   ;;
892    
893   1)   1)
894   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
895   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
896   ;;   ;;
897   esac   esac
# Line 880  remove_files() Line 958  remove_files()
958    
959   if [ ! -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
960   then   then
961   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
962   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
963   continue   continue
964   fi   fi
# Line 906  remove_files() Line 984  remove_files()
984   case ${retval} in   case ${retval} in
985   # file is not protected - delete it   # file is not protected - delete it
986   0|3)   0|3)
987   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
988   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
989   ;;   ;;
990    
991   # file is protected, do not delete   # file is protected, do not delete
992   2)   2)
993   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
994   then   then
995   echo -en "${COLRED}"   echo -en "${COLRED}"
996   echo -n "! prot "   echo -n "! prot "
# Line 923  remove_files() Line 1001  remove_files()
1001    
1002   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
1003   4)   4)
1004   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1005   then   then
1006   echo -en "${COLRED}"   echo -en "${COLRED}"
1007   echo -n "! ignr "   echo -n "! ignr "
# Line 935  remove_files() Line 1013  remove_files()
1013   esac   esac
1014   ;;   ;;
1015   1)   1)
1016   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1017   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1018   ;;   ;;
1019   esac   esac
# Line 997  remove_blockdevices() Line 1075  remove_blockdevices()
1075   do   do
1076   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1077    
1078   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1079   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1080   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1081    
# Line 1057  remove_characterdevices() Line 1135  remove_characterdevices()
1135   do   do
1136   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1137    
1138   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1139   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1140   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1141    
# Line 1119  remove_fifos() Line 1197  remove_fifos()
1197   do   do
1198   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1199    
1200   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1201   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1202   done < ${MROOT}${INSTALLDB}/${pfull}/.fifo   done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1203    
# Line 1180  remove_directories() Line 1258  remove_directories()
1258    
1259   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1260   then   then
1261   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1262   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1263   continue   continue
1264   fi   fi
# Line 1188  remove_directories() Line 1266  remove_directories()
1266   # exclude .keep directories   # exclude .keep directories
1267   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1268   then   then
1269   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1270   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1271   continue   continue
1272   fi   fi
# Line 1201  remove_directories() Line 1279  remove_directories()
1279    
1280   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1281   then   then
1282   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1283   else   else
1284   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1285   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1286   fi   fi
1287   done   done
# Line 1261  build_douninstall() Line 1339  build_douninstall()
1339   done   done
1340  }  }
1341    
1342    # convertmirrors [uri]
1343    convertmirrors()
1344    {
1345     local uri="$1"
1346     local scheme
1347     local mirror
1348     local mirrors
1349     local addon
1350     local real_uri
1351     local output
1352    
1353     # needs
1354     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1355     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1356     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1357     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1358     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1359    
1360     # check known uri schemes
1361     case ${uri} in
1362     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1363     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1364     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1365     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1366     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1367     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1368     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1369     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1370     esac
1371    
1372     if [[ ! -z ${mirrors} ]]
1373     then
1374     for mirror in ${mirrors}
1375     do
1376     # add a whitespace to the output
1377     [[ -z ${output} ]] || output+=" "
1378     output+="${mirror}${addon}/${uri/${scheme}/}"
1379     done
1380     else
1381     output="${uri}"
1382     fi
1383    
1384     echo "${output}"
1385    }
1386    
1387    mdownload()
1388    {
1389     local i
1390     local uri
1391     local real_uris
1392     local mirror
1393     local outputfile
1394     local outputdir
1395     local retval
1396     local wget_opts
1397    
1398     # very basic getops
1399     for i in $*
1400     do
1401     case $1 in
1402     --uri|-u) shift; uri="$1" ;;
1403     --dir|-d) shift; outputdir="$1" ;;
1404     esac
1405     shift
1406     done
1407    
1408     # sanity checks; abort if not given
1409     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1410     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1411    
1412     # convert mirrored uris to the real ones
1413     real_uris="$(convertmirrors ${uri})"
1414    
1415     # verbose or not
1416     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1417    
1418     # filter wget options if busybox was found
1419     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1420    
1421     # create outputdir
1422     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1423    
1424     for mirror in ${real_uris}
1425     do
1426     # get the name of the output file
1427     outputfile="${mirror##*/}"
1428    
1429     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1430     retval="$?"
1431     if [[ ${retval} = 0 ]]
1432     then
1433     break
1434     else
1435     continue
1436     fi
1437     done
1438    
1439     # return wget retval
1440     return "${retval}"
1441    }
1442    
1443  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1444  fetch_packages()  fetch_packages()
1445  {  {
1446     local i
1447   local list="$@"   local list="$@"
1448   local pkg   local pkgname
1449     local pkgfile
1450     local pcat
1451     local pname
1452   local mirr   local mirr
1453   local magefile   local magefile
1454   local md5file   local md5file
# Line 1273  fetch_packages() Line 1456  fetch_packages()
1456   local count_current   local count_current
1457   local count_total   local count_total
1458   local wget_opts   local wget_opts
1459     local fetching
1460    
1461   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1462    
# Line 1287  fetch_packages() Line 1471  fetch_packages()
1471    
1472   for magefile in ${list}   for magefile in ${list}
1473   do   do
1474   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1475     pkgfile="${pkgname}.${PKGSUFFIX}"
1476   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1477    
1478     pcat=$(magename2pcat ${magefile})
1479     pname=$(magename2pname ${magefile})
1480     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
1481    
1482   (( count_current++ ))   (( count_current++ ))
1483   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1484    
1485   # abort on virtual pkg   # abort on virtual pkg
1486   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1487   then   then
1488   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1489   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1490   continue   continue
1491   fi   fi
1492    
# Line 1305  fetch_packages() Line 1494  fetch_packages()
1494   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1495   then   then
1496   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1497   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1498   continue   continue
1499   fi   fi
1500    
1501   # abort if already exist   # check if FETCHING is required
1502   if [ -f ${PKGDIR}/${pkg} ]   if [ ! -f "${md5file}" ]
1503   then   then
1504   echo -ne " ${COLBLUE}***${COLDEFAULT}"   fetching=true
1505   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   else
1506   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 ]]  
1507   then   then
1508   break   # md5's ok, no fetching required
1509     fetching=false
1510   else   else
1511   continue   fetching=true
1512   fi   fi
1513   done   fi
1514    
1515     if [[ ${fetching} = false ]]
1516     then
1517     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1518     echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1519     continue
1520     else
1521     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1522     echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1523     mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1524     fi
1525    
1526   if [ ! -f ${PKGDIR}/${pkg} ]   # sanity check, not really needed but to be sure
1527     if [ ! -f ${PKGDIR}/${pkgfile} ]
1528   then   then
1529   die "Could not download ${pkg}"   die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1530   fi   fi
1531   done   done
1532    
# Line 1392  syncmage_tarball() Line 1581  syncmage_tarball()
1581    
1582   for mirr in ${MIRRORS}   for mirr in ${MIRRORS}
1583   do   do
1584   # path without distribution   # path without distribution
1585   mymirr="${mirr%/*}"   # (only for stable|testing|unstable and not DISTROTAG)
1586     case ${mirr##*/} in
1587     stable|testing|unstable) mymirr="${mirr%/*}";;
1588     *) mymirr="${mirr}";;
1589     esac
1590    
1591   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1592   echo "fetching latest md5 from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
1593   [[ ${VERBOSE} = off ]] && opt="--quiet"   mqueryfeature "!verbose" && opt="--quiet"
1594   wget \   wget \
1595   ${wget_opts} \   ${wget_opts} \
1596   --directory-prefix=${temp} \   --directory-prefix=${temp} \
# Line 1426  syncmage_tarball() Line 1619  syncmage_tarball()
1619   else   else
1620   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1621   echo -n "checking md5sum... "   echo -n "checking md5sum... "
1622   ( cd ${temp}; md5sum -c ${latest_md5} ) || die "md5 for ${latest_tarball} failed"   mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1623   fi   fi
1624    
1625   if [[ -d ${MAGEDIR} ]]   if [[ -d ${MAGEDIR} ]]
1626   then   then
1627   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1628   echo "cleaning old mage-tree ${MAGEDIR}..."   echo "cleaning old mage-tree ${MAGEDIR}..."
1629   rm -rf ${MAGEDIR}   # honor mountpoints and empty dirs
1630     if mountpoint -q ${MAGEDIR}
1631     then
1632     if ! mcheckemptydir ${MAGEDIR}
1633     then
1634     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1635     fi
1636     else
1637     rm -rf ${MAGEDIR}
1638     fi
1639   fi   fi
1640    
1641   if need_busybox_support tar   if need_busybox_support tar
# Line 1472  cleanpkg() Line 1674  cleanpkg()
1674   fi   fi
1675  }  }
1676    
1677  xtitle()  # unused?
1678  {  #
1679   if [[ ${TERM} = xterm ]]  # # cuts full pathnames or versionized names down to basename
1680   then  # choppkgname()
1681   echo -ne "\033]0;Mage: $1\007"  # {
1682   fi  # #we want this only if full name was used
1683   return 0  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1684  }  # then
1685    # #cuts ARCH and PBUILD
1686    # #ARCH comes from ${MAGERC}
1687  xtitleclean()  # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1688  {  #
1689   if [[ ${TERM} = xterm ]]  # #cuts version number
1690   then  # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1691   echo -ne "\033]0;\007"  # fi
1692   fi  # }
  return 0  
 }  
   
   
 # cuts full pathnames or versioniezed names down to basename  
 choppkgname()  
 {  
  #we want this only if full name was used  
  if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  
  then  
  #cuts ARCH and PBUILD  
  #ARCH comes from ${MAGERC}  
  MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  
1693    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1694    
1695  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1696  # $1=pname  # $1=pname
# Line 1528  pname2pcat() Line 1713  pname2pcat()
1713   echo "${categorie}"   echo "${categorie}"
1714  }  }
1715    
 # check_stable_package /path/to/foo.mage  
 # returns 0=stable 1=unstable  
 check_stable_package()  
 {  
  # first check if this magefile is not blacklisted  
  blacklisted "$1" || return 1  
   
  local STATE  
  STATE="$(get_value_from_magefile STATE "$1")"  
   
  # state testing  
  if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]  
  then  
  case ${STATE} in  
  testing|stable) return 0 ;;  
  *) return 1 ;;  
  esac  
  fi  
   
  # state unstable  
  if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]  
  then  
  case ${STATE} in  
  unstable|testing|stable) return 0 ;;  
  *) return 1 ;;  
  esac  
  fi  
   
  # no use_state given = stable  
  case ${STATE} in  
  stable) return 0 ;;  
  *) return 1 ;;  
  esac  
 }  
   
   
1716  # get_highest_magefile ${PCAT} ${PNAME}  # get_highest_magefile ${PCAT} ${PNAME}
1717  # fake at moment returns only stable pkgs (must set to be one)  # returns $HIGHEST_MAGEFILE
 # return $HIGHEST_MAGEFILE  
1718  get_highest_magefile()  get_highest_magefile()
1719  {  {
1720   local HIGHEST_MAGEFILE   local pcat="$1"
1721   local PCAT="$1"   local pname="$2"
  local PNAME="$2"  
  local magefile  
1722    
1723   # do not list the content of a directory, only the name (-d)   ${MLIBDIR}/highest_magefile ${MAGEDIR}/${pcat}/${pname}
  for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)  
  do  
  [[ -z ${magefile} ]] && continue  
  # we exclude subdirs (for stuff like a md5sum dir)  
  [[ -d ${magefile} ]] && continue  
  if check_stable_package ${magefile}  
  then  
  HIGHEST_MAGEFILE=${magefile}  
  #for debug only  
  [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"  
  fi  
  done  
   
 # 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  
   
  echo "${HIGHEST_MAGEFILE}"  
1724   return 0   return 0
1725  }  }
1726    
   
1727  ###################################################  ###################################################
1728  # function is_config_protected                    #  # function is_config_protected                    #
1729  #       is_config_protected /path/to/file         #  #       is_config_protected /path/to/file         #
# Line 1713  count_protected_files() Line 1822  count_protected_files()
1822   local filename="${file##*/}"   local filename="${file##*/}"
1823   local count   local count
1824   local output   local output
1825     local oldprotected
1826   local i   local i
1827     local x
1828    
1829     # hack; do not honor a global set IFS like '§'
1830     local IFS
1831    
1832   declare -i count=0   count=0
1833    
1834   # check if there are already protected files   # check if there are already protected files
1835   for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |   for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1836   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1837   sort -t'%' -k3 -k2 | cut -f1 -d'%')   sort -t'%' -k3 -k2 | cut -f1 -d'%')
1838   do   do
1839   count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")   count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1840     done
1841    
1842     # convert 0001 -> 1; 0120 -> 120 etc
1843     # use bash internal base functions to this task
1844     x="$((10#${count}))"
1845     for (( i=0; i<x; i++ ))
1846     do
1847     if [[ ${count:${i}:1} != 0 ]]
1848     then
1849     count="${count:${i}}"
1850     break
1851     fi
1852   done   done
1853   (( count ++ ))  
1854     count="$(( ${count}+1 ))"
1855    
1856   # fill output up with zeros   # fill output up with zeros
1857   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 2141  minclude()
2141   then   then
2142   for i in $*   for i in $*
2143   do   do
2144   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2145   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2146   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2147   done   done
2148   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2149   fi   fi
2150  }  }
2151    
# Line 2030  sminclude() Line 2157  sminclude()
2157   then   then
2158   for i in $*   for i in $*
2159   do   do
2160   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2161   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2162   done   done
2163   echo   [[ ${SILENT} = 1 ]] || echo
2164   fi   fi
2165  }  }
2166    
# Line 2060  is_newer_mage_version_available() Line 2187  is_newer_mage_version_available()
2187   fi   fi
2188  }  }
2189    
   
2190  # returns pname from pkgname  # returns pname from pkgname
2191  # pkgname2pname $PKGNAME  # pkgname2pname $PKGNAME
2192  pkgname2pname()  pkgname2pname()
# Line 2337  get_value_from_magefile() Line 2463  get_value_from_magefile()
2463   local SDEPEND   local SDEPEND
2464   local PROVIDE   local PROVIDE
2465   local PKGTYPE   local PKGTYPE
  local MAGE_TARGETS  
2466   local SPLIT_PACKAGE_BASE   local SPLIT_PACKAGE_BASE
2467   local preinstall   local preinstall
2468   local postinstall   local postinstall
# Line 2459  mage_install() Line 2584  mage_install()
2584   echo B:${pbuild}   echo B:${pbuild}
2585   fi   fi
2586    
2587   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} ]]  
2588   then   then
2589   # basic svn compat   # basic svn compat
2590   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
# Line 2514  mage_install() Line 2626  mage_install()
2626   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2627   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2628   then   then
2629     unpack_package "${magefile}"
2630   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
2631   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2632   fi   fi
# Line 2558  mage_install() Line 2671  mage_install()
2671   then   then
2672   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2673   echo -n "rebuilding environment ... "   echo -n "rebuilding environment ... "
2674   ${MLIBDIR}/env-rebuild.sh > /dev/null && \   ${MLIBDIR}/env-rebuild > /dev/null && \
2675   echo "done." || echo "failure."   echo "done." || echo "failure."
2676   unset MAGE_ENV_REBUILD   unset MAGE_ENV_REBUILD
2677   fi   fi
# Line 2602  md5sum_packages() Line 2715  md5sum_packages()
2715   pname=$(magename2pname ${magefile})   pname=$(magename2pname ${magefile})
2716   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2717   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2718   pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
2719   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2720    
2721   (( count_current++ ))   (( count_current++ ))
# Line 2612  md5sum_packages() Line 2725  md5sum_packages()
2725   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
2726   then   then
2727   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2728   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... "
2729   continue   continue
2730   fi   fi
2731    
# Line 2620  md5sum_packages() Line 2733  md5sum_packages()
2733   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
2734   then   then
2735   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2736   echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... "
2737   continue   continue
2738   fi   fi
2739    
# Line 2628  md5sum_packages() Line 2741  md5sum_packages()
2741   then   then
2742   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2743   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2744   ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2745   else   else
2746   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2747   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2668  uninstall_packages() Line 2781  uninstall_packages()
2781   pbuild=$(magename2pbuild ${pkg})   pbuild=$(magename2pbuild ${pkg})
2782   can_pcat="${pcat}"   can_pcat="${pcat}"
2783   can_pname="${pname}"   can_pname="${pname}"
2784    
2785   if [ -z "${can_ver_list}" ]   if [ -z "${can_ver_list}" ]
2786   then   then
2787   can_ver_list=" ${pver}-${pbuild}"   can_ver_list=" ${pver}-${pbuild}"
# Line 2823  mage_uninstall() Line 2936  mage_uninstall()
2936   then   then
2937   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2938   echo -n "rebuilding environment ... "   echo -n "rebuilding environment ... "
2939   ${MLIBDIR}/env-rebuild.sh > /dev/null && \   ${MLIBDIR}/env-rebuild > /dev/null && \
2940   echo "done." || echo "failure."   echo "done." || echo "failure."
2941   unset MAGE_ENV_REBUILD   unset MAGE_ENV_REBUILD
2942   fi   fi
# Line 2841  mage_uninstall() Line 2954  mage_uninstall()
2954   unset -f postremove   unset -f postremove
2955  }  }
2956    
2957    # rerun_pkgfunctions [method] pkg1 pkg2 pkg3
2958    rerun_pkgfunctions()
2959    {
2960     local method
2961     local list
2962     local pcat
2963     local pname
2964     local pver
2965     local pbuild
2966     local magefile
2967     local i
2968    
2969     # very basic getops
2970     case $1 in
2971     --method) shift; method="$1" ;;
2972     esac
2973     shift
2974     local list="$@"
2975    
2976     # sanity check
2977     case ${method} in
2978     preinstall|postinstall) ;;
2979     preremove|postremove) ;;
2980     *) die "rerun_pkgfunctions(): Unknown method '${method}'." ;;
2981     esac
2982    
2983     if [[ -n ${MROOT} ]]
2984     then
2985     echo -ne ${COLRED}
2986     echo "!! running in MROOT=${MROOT}"
2987     echo -ne ${COLDEFAULT}
2988     echo
2989     fi
2990    
2991     for pkg in ${list}
2992     do
2993     pcat=$(dep2pcat ${pkg})
2994     pname=$(magename2pname ${pkg})
2995     pver=$(magename2pver ${pkg})
2996     pbuild=$(magename2pbuild ${pkg})
2997     magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2998    
2999     if [ -e ${magefile} ]
3000     then
3001     source ${magefile}
3002     if [ -n "$(typeset -f ${method})" ]
3003     then
3004     echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... "
3005     ${method}
3006     else
3007     echo "No ${method}() for pkg '${pkg}' defined. Doing nothing."
3008     fi
3009     unset -f preinstall postinstall preremove postremove
3010     else
3011     die "Magefile '${magefile}' does not exist."
3012     fi
3013     done
3014    }
3015    
3016  show_etc_update_mesg()  show_etc_update_mesg()
3017  {  {
3018   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
# Line 2868  pkgsearch() Line 3040  pkgsearch()
3040   local state   local state
3041   local descriptiom   local descriptiom
3042   local homepage   local homepage
3043     local license
3044   local i   local i
3045   local all_installed   local all_installed
3046   local ipver   local ipver
# Line 2904  pkgsearch() Line 3077  pkgsearch()
3077   state="$(get_value_from_magefile STATE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3078   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3079   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3080     license="$(get_value_from_magefile LICENSE ${magefile})"
3081    
3082   # all installed   # all installed
3083   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3084   do   do
3085   ipver="$(magename2pver ${i})"   ipver="$(magename2pver ${i})"
3086   ipbuild="$(magename2pbuild ${i})"   ipbuild="$(magename2pbuild ${i})"
3087    
3088   if [[ -z ${all_installed} ]]   if [[ -z ${all_installed} ]]
3089   then   then
3090   all_installed="${ipver}-${ipbuild}"   all_installed="${ipver}-${ipbuild}"
# Line 2919  pkgsearch() Line 3093  pkgsearch()
3093   fi   fi
3094   done   done
3095   [[ -z ${all_installed} ]] && all_installed="none"   [[ -z ${all_installed} ]] && all_installed="none"
3096    
3097   case ${state} in   case ${state} in
3098   stable) state=${COLGREEN}"[s] ";;   stable) state=${COLGREEN}"[s] ";;
3099   testing) state=${COLYELLOW}"[t] ";;   testing) state=${COLYELLOW}"[t] ";;
# Line 2943  pkgsearch() Line 3117  pkgsearch()
3117   "") continue;;   "") continue;;
3118   esac   esac
3119    
3120   deps="${deps} $(basename ${dep%-*})"   if [[ -z ${deps} ]]
3121     then
3122     deps="$(basename ${dep%-*})"
3123     else
3124     deps="${deps} $(basename ${dep%-*})"
3125     fi
3126   done << EOF   done << EOF
3127  ${depsfull}  ${depsfull}
3128  EOF  EOF
# Line 2954  EOF Line 3133  EOF
3133   "") continue;;   "") continue;;
3134   esac   esac
3135    
3136   sdeps="${sdeps} $(basename ${dep%-*})"   if [[ -z ${sdeps} ]]
3137     then
3138     sdeps="$(basename ${dep%-*})"
3139     else
3140     sdeps="${sdeps} $(basename ${dep%-*})"
3141     fi
3142   done << EOF   done << EOF
3143  ${sdepsfull}  ${sdepsfull}
3144  EOF  EOF
# Line 2964  EOF Line 3148  EOF
3148   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3149   echo "      Description: ${description}"   echo "      Description: ${description}"
3150   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3151   echo "      Depends: ${deps}"   if [[ ! -z ${license} ]]
3152     then
3153     echo "      License:  ${license}"
3154     fi
3155     echo "      Depends:  ${deps}"
3156   echo "      SDepends: ${sdeps}"   echo "      SDepends: ${sdeps}"
3157   echo   echo
3158    
# Line 3004  export_inherits() Line 3192  export_inherits()
3192   eval "${functions}() { ${include}_${functions} ; }"   eval "${functions}() { ${include}_${functions} ; }"
3193    
3194   # debug   # debug
3195   [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"   mqueryfeature "debug" && typeset -f "${functions}"
3196    
3197   shift   shift
3198   done   done
# Line 3081  EOF Line 3269  EOF
3269  need_busybox_support()  need_busybox_support()
3270  {  {
3271   local cmd   local cmd
3272     local busybox
3273   cmd="$1"   cmd="$1"
3274    
3275   if [[ -x /bin/busybox ]]   for busybox in {,/usr}/bin/busybox
3276   then   do
3277   if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]   if [[ -x ${busybox} ]]
3278   then   then
3279   # needs busybox support   if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3280   return 0   then
3281     # needs busybox support
3282     return 0
3283     fi
3284   fi   fi
3285   fi   done
3286    
3287   # no busybox   # no busybox
3288   return 1   return 1
# Line 3128  busybox_filter_wget_options() Line 3320  busybox_filter_wget_options()
3320   echo "${opts}"   echo "${opts}"
3321   fi   fi
3322  }  }
3323    
3324    have_root_privileges()
3325    {
3326     local retval
3327    
3328     if [[ $(id -u) = 0 ]]
3329     then
3330     retval=0
3331     else
3332     retval=1
3333     fi
3334    
3335     return ${retval}
3336    }
3337    
3338    known_mage_feature()
3339    {
3340     local feature="$1"
3341     local retval
3342    
3343     case "${feature}" in
3344     autosvc|!autosvc) retval=0 ;;
3345     buildlog|!buildlog) retval=0 ;;
3346     ccache|!ccache) retval=0 ;;
3347     check|!check) retval=0 ;;
3348     compressdoc|!compressdoc) retval=0 ;;
3349     debug|!debug) retval=0 ;;
3350     distcc|!distcc) retval=0 ;;
3351     icecc|!icecc) retval=0 ;;
3352     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3353     libtool|!libtool) retval=0 ;;
3354     linuxsymlink|!linuxsymlink) retval=0 ;;
3355     multilib|!multilib) reval=0 ;;
3356     pkgbuild|!pkgbuild) retval=0 ;;
3357     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3358     pkgmetadata|!pkgmetadata) retval=0 ;;
3359     purge|!purge) retval=0 ;;
3360     qalint|!qalint) retval=0 ;;
3361     regentree|!regentree) retval=0 ;;
3362     resume|!resume) retval=0 ;;
3363     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3364     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3365     static|!static) retval=0 ;;
3366     stepbystep|!stepbystep) retval=0 ;;
3367     strip|!strip) retval=0 ;;
3368     verbose|!verbose) retval=0 ;;
3369     *) retval=1 ;;
3370     esac
3371    
3372     return "${retval}"
3373    }
3374    
3375    load_mage_features()
3376    {
3377     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3378     do
3379     FVERBOSE=off msetfeature ${i}
3380     done
3381    }
3382    
3383    msetfeature()
3384    {
3385     local feature
3386     local count
3387     local i
3388     local found
3389    
3390     for feature in $@
3391     do
3392     found=0
3393     count="${#MAGE_FEATURES_CURRENT[*]}"
3394    
3395     if ! known_mage_feature "${feature}"
3396     then
3397     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3398     return 3
3399     fi
3400    
3401     for ((i=0; i<count; i++))
3402     do
3403     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3404     then
3405     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3406     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3407     found=1
3408     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3409     then
3410     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3411     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3412     found=1
3413     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3414     then
3415     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3416     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3417     found=1
3418     fi
3419     done
3420    
3421     # if the feature was not found after proccessing the whole array
3422     # it was not declared. in this case enable it
3423     if [[ ${found} = 0 ]]
3424     then
3425     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3426     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3427     fi
3428    
3429     export MAGE_FEATURES_CURRENT
3430     done
3431    }
3432    
3433    mqueryfeature()
3434    {
3435     local feature="$1"
3436     local retval=1
3437     local i
3438    
3439     if known_mage_feature "${feature}"
3440     then
3441     for i in ${MAGE_FEATURES_CURRENT[*]}
3442     do
3443     if [[ ${i} = ${feature} ]]
3444     then
3445     retval=0
3446     break # found break here
3447     fi
3448     done
3449     else
3450     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3451     retval=3
3452     fi
3453    
3454     return ${retval}
3455    }
3456    
3457    mprintfeatures()
3458    {
3459     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3460     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3461     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3462    }

Legend:
Removed from v.1502  
changed lines
  Added in v.2811