Magellan Linux

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

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

revision 972 by niro, Thu Apr 22 12:22:39 2010 UTC revision 1963 by niro, Fri Oct 26 21:14:51 2012 UTC
# Line 2  Line 2 
2  # Magellan Linux Installer Functions (mage.functions.sh)  # Magellan Linux Installer Functions (mage.functions.sh)
3  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.38 2008-10-05 10:32:24 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.38 2008-10-05 10:32:24 niro Exp $
4    
5    COLRED="\033[1;6m\033[31m"
6    COLGREEN="\033[1;6m\033[32m"
7    COLYELLOW="\033[1;6m\033[33m"
8    COLBLUE="\033[1;6m\033[34m"
9    COLMAGENTA="\033[1;6m\033[35m"
10    COLWHITE="\033[1;6m\033[37m"
11    COLGRAY="\033[0;6m\033[37m"
12    COLBOLD="\033[1m"
13    COLDEFAULT="\033[0m"
14    
15    if [[ ${NOCOLORS} = true ]]
16    then
17     COLRED=""
18     COLGREEN=""
19     COLYELLOW=""
20     COLBLUE=""
21     COLMAGENTA=""
22     COLWHITE=""
23     COLGRAY=""
24     COLBOLD=""
25     COLDEFAULT=""
26    fi
27    
28  mage_setup()  mage_setup()
29  {  {
30   [ ! -d ${MROOT}${INSTALLDB} ] && \   [ ! -d ${MROOT}${INSTALLDB} ] && \
# Line 15  mage_setup() Line 38  mage_setup()
38   return 0   return 0
39  }  }
40    
41    mchecksum()
42    {
43     local i
44     local rundir
45     local file
46     local method
47     local cmd
48     local retval
49    
50     # very basic getops
51     for i in $*
52     do
53     case $1 in
54     --rundir|-r) shift; rundir="$1" ;;
55     --file|-f) shift; file="$1" ;;
56     --method|-m) shift; method="$1" ;;
57     esac
58     shift
59     done
60    
61     # sanity checks
62     [[ -z ${rundir} ]] && die "mchecksum(): rundir missing"
63     [[ -z ${file} ]] && die "mchecksum(): file missing"
64     [[ -z ${method} ]] && die "mchecksum(): method missing"
65    
66     case ${method} in
67     md5) cmd="md5sum" ;;
68     sha256) cmd="sha256sum" ;;
69     *) die "mchecksum(): unknown method '${method}'" ;;
70     esac
71    
72     if [[ -d ${rundir} ]]
73     then
74     pushd ${rundir} &> /dev/null
75     # be verbose here
76     ${cmd} -c ${file} #&> /dev/null
77     retval="$?"
78     popd &> /dev/null
79     else
80     retval=1
81     fi
82    
83     return "${retval}"
84    }
85    
86    mcheckemptydir()
87    {
88     local dir="$1"
89     local retval=1
90    
91     if [[ ! -d ${dir} ]]
92     then
93     echo "mcheckemptydir(): '${dir}' is not a directory!"
94     retval=3
95     else
96     shopt -s nullglob dotglob
97     files=( ${dir}/* )
98     (( ${#files[*]} )) || retval=0
99     shopt -u nullglob dotglob
100     fi
101    
102     return ${retval}
103    }
104    
105  unpack_packages()  unpack_packages()
106  {  {
107   local list="$@"   local list="$@"
# Line 23  unpack_packages() Line 110  unpack_packages()
110   local pkgtype   local pkgtype
111   local count_current   local count_current
112   local count_total   local count_total
113     local tar_opts
114    
115   # get count of total packages   # get count of total packages
116   declare -i count_current=0   declare -i count_current=0
# Line 54  unpack_packages() Line 142  unpack_packages()
142   continue   continue
143   fi   fi
144    
145     # busybox?
146     if need_busybox_support tar
147     then
148     tar_opts="xjf"
149     else
150     tar_opts="xjmf"
151     fi
152    
153   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "
154   tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"   tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"
155   done   done
156    
157   # add a crlf for a better view   # add a crlf for a better view
# Line 75  fix_mtime() Line 171  fix_mtime()
171   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
172   touch \   touch \
173   --no-create \   --no-create \
174     --no-dereference \
175   --time=mtime \   --time=mtime \
176   --reference "${reference}" \   --reference="${reference}" \
177   "${pathto}"   "${pathto}"
178    
179   echo "${mtime}"   echo "${mtime}"
# Line 130  install_directories() Line 227  install_directories()
227   while read pathto posix user group   while read pathto posix user group
228   do   do
229   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
230   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
   
231    
232   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
233   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 207  install_files() Line 303  install_files()
303   case ${retval} in   case ${retval} in
304   # file is not protected - (over)write it   # file is not protected - (over)write it
305   0|3)   0|3)
306   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
307   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
308   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
309   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 219  install_files() Line 315  install_files()
315   "${user}" \   "${user}" \
316   "${group}" \   "${group}" \
317   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
318   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
319   "${md5sum}"   "${md5sum}"
320   ;;   ;;
321    
322   # file is protected, write backup file   # file is protected, write backup file
323   2)   2)
324   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
325   then   then
326   echo -en "${COLRED}"   echo -en "${COLRED}"
327   echo -n "! prot "   echo -n "! prot "
# Line 246  install_files() Line 342  install_files()
342   "${user}" \   "${user}" \
343   "${group}" \   "${group}" \
344   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
345   "${dest_protected}")" \   "${dest_protected}")" \
346   "${md5sum}"   "${md5sum}"
347    
348   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
# Line 256  install_files() Line 352  install_files()
352    
353   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
354   4)   4)
355   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
356   then   then
357   echo -en "${COLRED}"   echo -en "${COLRED}"
358   echo -n "! ignr "   echo -n "! ignr "
359   echo -en "${COLDEFAULT}"   echo -en "${COLDEFAULT}"
360   echo " === FILE: ${MROOT}${pathto}"   echo " === FILE: ${MROOT}${pathto}"
361   fi   fi
362   # simply do nothing here   # simply do nothing here - only fix mtime
363     fix_descriptor ${pkgname}/.files \
364     "${pathto}" \
365     "${posix}" \
366     "${user}" \
367     "${group}" \
368     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
369     "${MROOT}${pathto}")" \
370     "${md5sum}"
371   ;;   ;;
372   esac   esac
373   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
# Line 307  install_symlinks() Line 411  install_symlinks()
411   while read pathto posix link mtime   while read pathto posix link mtime
412   do   do
413   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
414   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
415    
416   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
417    
418  # # fix mtime and db   # fix mtime and db
419  # fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
420  # "${pathto}" \   "${pathto}" \
421  # "${posix}" \   "${posix}" \
422  # "${link}" \   "${link}" \
423  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
424  # "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
425    
426   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
427    
# Line 339  install_blockdevices() Line 443  install_blockdevices()
443   local pkgname="$1"   local pkgname="$1"
444   local pathto   local pathto
445   local posix   local posix
446     local user
447     local group
448   local IFS   local IFS
449    
450   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 352  install_blockdevices() Line 458  install_blockdevices()
458   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
459   IFS=§   IFS=§
460    
461   while read pathto posix   while read pathto posix major minor user group
462   do   do
463   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
464   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
465    
466   mkfifo -m "${posix}" "${MROOT}$pathto"   mknod -m "${posix}" "${MROOT}${pathto}"
467     # make it optional atm !!
468     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
469     then
470     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
471     fi
472   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
473    
474   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 376  install_characterdevices() Line 487  install_characterdevices()
487   local posix   local posix
488   local major   local major
489   local minor   local minor
490     local user
491     local group
492   local IFS   local IFS
493    
494   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 389  install_characterdevices() Line 502  install_characterdevices()
502   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
503   IFS=§   IFS=§
504    
505   while read pathto posix major minor   while read pathto posix major minor user group
506   do   do
507   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
508   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
509    
510     mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
511    
512   mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor}   # make it optional atm !!
513     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
514     then
515     chown "${user}:${group}" "${MROOT}${pathto}"
516     fi
517   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
518    
519   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
520   IFS=$'\n'   IFS=$'\n'
521  }  }
522    
523    ###################################################
524    # function install_fifos                          #
525    # install_fifos $PKGNAME                    #
526    ###################################################
527    install_fifos()
528    {
529     local pkgname="$1"
530     local pathto
531     local posix
532     local user
533     local group
534     local IFS
535    
536     # sanity checks; abort if not given
537     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
538    
539     # check needed global vars
540     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
541    
542     # make it optional atm !!
543     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
544     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
545    
546     # sets fieldseperator to "§" instead of " "
547     IFS=§
548    
549     while read pathto posix user group
550     do
551     [ -z "${pathto}" ] && continue
552     mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
553    
554     mkfifo -m "${posix}" "${MROOT}${pathto}"
555     chown "${user}:${group}" "${MROOT}${pathto}"
556     done < ${BUILDDIR}/${pkgname}/.fifo
557    
558     # very important: unsetting the '§' fieldseperator
559     IFS=$'\n'
560    }
561    
562    
563  ###################################################  ###################################################
564  # function build_doinstall                        #  # function build_doinstall                        #
565  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
566  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
567  ###################################################  ###################################################
568  build_doinstall()  build_doinstall()
569  {  {
# Line 413  build_doinstall() Line 571  build_doinstall()
571    
572   # sanity checks; abort if not given   # sanity checks; abort if not given
573   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
574    
575   # this is only a wrapper   # this is only a wrapper
576    
577   # NOTE:   # NOTE:
# Line 428  build_doinstall() Line 586  build_doinstall()
586   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
587   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
588   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
589     install_fifos ${pkgname} || die "install fifos ${pkgname}"
590  }  }
591    
592    
# Line 489  install_database_entry() Line 648  install_database_entry()
648    
649   # create fake file descriptors   # create fake file descriptors
650   # used by virtual and source packages   # used by virtual and source packages
651   for i in .dirs .symlinks .files .pipes .char   for i in .dirs .symlinks .files .pipes .char .fifo
652   do   do
653   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
654   done   done
# Line 507  install_database_entry() Line 666  install_database_entry()
666    
667   # normal packages needs these files   # normal packages needs these files
668   local i   local i
669   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
670   do   do
671   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
672   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
673     then
674     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
675     fi
676   done   done
677   ;;   ;;
678   esac   esac
# Line 646  compare_mtime() Line 808  compare_mtime()
808    
809   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
810    
811   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
812   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
813   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  
814    
815   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
816    
# Line 721  remove_symlinks() Line 872  remove_symlinks()
872   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
873   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
874   then   then
875   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
876   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
877   continue   continue
878   fi   fi
# Line 733  remove_symlinks() Line 884  remove_symlinks()
884   # 1=keep me   #   # 1=keep me   #
885   case ${retval} in   case ${retval} in
886   0)   0)
887   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
888   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
889   ;;   ;;
890    
891   1)   1)
892   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
893   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
894   ;;   ;;
895   esac   esac
# Line 785  remove_files() Line 936  remove_files()
936   done   done
937    
938   # sanity checks; abort if not given   # sanity checks; abort if not given
939   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
940   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
941   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
942   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
943   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
944    
945   # check needed global vars   # check needed global vars
# Line 805  remove_files() Line 956  remove_files()
956    
957   if [ ! -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
958   then   then
959   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
960   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
961   continue   continue
962   fi   fi
# Line 831  remove_files() Line 982  remove_files()
982   case ${retval} in   case ${retval} in
983   # file is not protected - delete it   # file is not protected - delete it
984   0|3)   0|3)
985   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
986   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
987   ;;   ;;
988    
989   # file is protected, do not delete   # file is protected, do not delete
990   2)   2)
991   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
992   then   then
993   echo -en "${COLRED}"   echo -en "${COLRED}"
994   echo -n "! prot "   echo -n "! prot "
# Line 848  remove_files() Line 999  remove_files()
999    
1000   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
1001   4)   4)
1002   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1003   then   then
1004   echo -en "${COLRED}"   echo -en "${COLRED}"
1005   echo -n "! ignr "   echo -n "! ignr "
# Line 860  remove_files() Line 1011  remove_files()
1011   esac   esac
1012   ;;   ;;
1013   1)   1)
1014   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1015   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1016   ;;   ;;
1017   esac   esac
# Line 879  remove_blockdevices() Line 1030  remove_blockdevices()
1030  {  {
1031   local pathto   local pathto
1032   local posix   local posix
1033     local user
1034     local group
1035   local IFS   local IFS
1036   local pcat   local pcat
1037   local pname   local pname
# Line 902  remove_blockdevices() Line 1055  remove_blockdevices()
1055   done   done
1056    
1057   # sanity checks; abort if not given   # sanity checks; abort if not given
1058   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1059   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1060   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1061   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1062   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1063    
1064   # check needed global vars   # check needed global vars
# Line 916  remove_blockdevices() Line 1069  remove_blockdevices()
1069   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1070   IFS=§   IFS=§
1071    
1072   while read pathto posix   while read pathto posix user group
1073   do   do
1074   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1075    
1076   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1077   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1078   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1079    
# Line 937  remove_characterdevices() Line 1090  remove_characterdevices()
1090  {  {
1091   local pathto   local pathto
1092   local posix   local posix
1093     local user
1094     local group
1095   local IFS   local IFS
1096   local pcat   local pcat
1097   local pname   local pname
# Line 960  remove_characterdevices() Line 1115  remove_characterdevices()
1115   done   done
1116    
1117   # sanity checks; abort if not given   # sanity checks; abort if not given
1118   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1119   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1120   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1121   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1122   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1123    
1124   # check needed global vars   # check needed global vars
# Line 974  remove_characterdevices() Line 1129  remove_characterdevices()
1129   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1130   IFS=§   IFS=§
1131    
1132   while read pathto posix   while read pathto posix user group
1133   do   do
1134   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1135    
1136   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1137   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1138   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1139    
# Line 988  remove_characterdevices() Line 1143  remove_characterdevices()
1143    
1144    
1145  ###################################################  ###################################################
1146    # function remove_fifos                           #
1147    # remove_fifos $PKGNAME                     #
1148    ###################################################
1149    remove_fifos()
1150    {
1151     local pathto
1152     local posix
1153     local user
1154     local group
1155     local IFS
1156     local pcat
1157     local pname
1158     local pver
1159     local pbuild
1160     local i
1161     local pfull
1162    
1163     IFS=$'\n'
1164    
1165     # very basic getops
1166     for i in $*
1167     do
1168     case $1 in
1169     --pcat|-c) shift; pcat="$1" ;;
1170     --pname|-n) shift; pname="$1" ;;
1171     --pver|-v) shift; pver="$1" ;;
1172     --pbuild|-b) shift; pbuild="$1" ;;
1173     esac
1174     shift
1175     done
1176    
1177     # sanity checks; abort if not given
1178     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1179     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1180     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1181     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1182     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1183    
1184     # check needed global vars
1185     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1186    
1187     # make it optional atm !!
1188     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1189     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1190    
1191     # sets fieldseperator to "§" instead of " "
1192     IFS=§
1193    
1194     while read pathto posix user group
1195     do
1196     [ -z "${pathto}" ] && continue
1197    
1198     mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1199     rm "${MROOT}${pathto}"
1200     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1201    
1202     # very important: unsetting the '§' fieldseperator
1203     IFS=$'\n'
1204    }
1205    
1206    
1207    ###################################################
1208  # function remove_direcories                      #  # function remove_direcories                      #
1209  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1210  ###################################################  ###################################################
# Line 1018  remove_directories() Line 1235  remove_directories()
1235   done   done
1236    
1237   # sanity checks; abort if not given   # sanity checks; abort if not given
1238   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1239   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1240   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1241   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1242   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1243    
1244   # check needed global vars   # check needed global vars
# Line 1039  remove_directories() Line 1256  remove_directories()
1256    
1257   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1258   then   then
1259   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1260   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1261   continue   continue
1262   fi   fi
# Line 1047  remove_directories() Line 1264  remove_directories()
1264   # exclude .keep directories   # exclude .keep directories
1265   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1266   then   then
1267   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1268   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1269   continue   continue
1270   fi   fi
# Line 1060  remove_directories() Line 1277  remove_directories()
1277    
1278   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1279   then   then
1280   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1281   else   else
1282   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1283   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1284   fi   fi
1285   done   done
# Line 1075  remove_directories() Line 1292  remove_directories()
1292  ###################################################  ###################################################
1293  # function build_douninstall                      #  # function build_douninstall                      #
1294  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1295  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1296  ###################################################  ###################################################
1297  build_douninstall()  build_douninstall()
1298  {  {
# Line 1109  build_douninstall() Line 1326  build_douninstall()
1326   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1327   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1328    
1329   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1330   do   do
1331   remove_${i} \   remove_${i} \
1332   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1120  build_douninstall() Line 1337  build_douninstall()
1337   done   done
1338  }  }
1339    
1340    # convertmirrors [uri]
1341    convertmirrors()
1342    {
1343     local uri="$1"
1344     local scheme
1345     local mirror
1346     local mirrors
1347     local addon
1348     local real_uri
1349     local output
1350    
1351     # needs
1352     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1353     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1354     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1355     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1356     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1357    
1358     # check known uri schemes
1359     case ${uri} in
1360     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1361     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1362     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1363     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1364     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1365     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1366     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1367     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1368     esac
1369    
1370     if [[ ! -z ${mirrors} ]]
1371     then
1372     for mirror in ${mirrors}
1373     do
1374     # add a whitespace to the output
1375     [[ -z ${output} ]] || output+=" "
1376     output+="${mirror}${addon}/${uri/${scheme}/}"
1377     done
1378     else
1379     output="${uri}"
1380     fi
1381    
1382     echo "${output}"
1383    }
1384    
1385    mdownload()
1386    {
1387     local i
1388     local uri
1389     local real_uris
1390     local mirror
1391     local outputfile
1392     local outputdir
1393     local retval
1394     local wget_opts
1395    
1396     # very basic getops
1397     for i in $*
1398     do
1399     case $1 in
1400     --uri|-u) shift; uri="$1" ;;
1401     --dir|-d) shift; outputdir="$1" ;;
1402     esac
1403     shift
1404     done
1405    
1406     # sanity checks; abort if not given
1407     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1408     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1409    
1410     # convert mirrored uris to the real ones
1411     real_uris="$(convertmirrors ${uri})"
1412    
1413     # verbose or not
1414     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1415    
1416     # filter wget options if busybox was found
1417     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1418    
1419     # create outputdir
1420     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1421    
1422     for mirror in ${real_uris}
1423     do
1424     # get the name of the output file
1425     outputfile="${mirror##*/}"
1426    
1427     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1428     retval="$?"
1429     if [[ ${retval} = 0 ]]
1430     then
1431     break
1432     else
1433     continue
1434     fi
1435     done
1436    
1437     # return wget retval
1438     return "${retval}"
1439    }
1440    
1441  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1442  fetch_packages()  fetch_packages()
1443  {  {
1444     local i
1445   local list="$@"   local list="$@"
1446   local pkg   local pkg
1447   local mirr   local mirr
# Line 1131  fetch_packages() Line 1450  fetch_packages()
1450   local opt   local opt
1451   local count_current   local count_current
1452   local count_total   local count_total
1453     local wget_opts
1454    
1455   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1456    
1457     # filter wget command if busybox was found
1458     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1459    
1460   # get count of total packages   # get count of total packages
1461   declare -i count_current=0   declare -i count_current=0
1462   declare -i count_total=0   declare -i count_total=0
# Line 1172  fetch_packages() Line 1495  fetch_packages()
1495   continue   continue
1496   fi   fi
1497    
1498   for mirr in ${MIRRORS}   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1499   do   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1500   echo -ne " ${COLBLUE}***${COLDEFAULT}"   mdownload --uri "package://${pkg}" --dir "${PKGDIR}" || die "Could not download ${pkg}"
  #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... "  
  echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "  
  [[ ${VERBOSE} = off ]] && opt="--quiet"  
  wget \  
  --passive-ftp \  
  --tries 3 \  
  --continue \  
  --progress bar \  
  --directory-prefix=${PKGDIR} \  
  ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}  
  if [[ $? = 0 ]]  
  then  
  break  
  else  
  continue  
  fi  
  done  
   
1501   if [ ! -f ${PKGDIR}/${pkg} ]   if [ ! -f ${PKGDIR}/${pkg} ]
1502   then   then
1503   die "Could not download ${pkg}"   die "Package '${pkg}' after download not found in '${PKGDIR}'"
1504   fi   fi
1505   done   done
1506    
# Line 1223  syncmage() Line 1528  syncmage()
1528   done   done
1529    
1530   # clean up backup files (foo~)   # clean up backup files (foo~)
1531   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1532    
1533   # check if a newer mage version is available   # check if a newer mage version is available
1534   is_newer_mage_version_available   is_newer_mage_version_available
# Line 1232  syncmage() Line 1537  syncmage()
1537  syncmage_tarball()  syncmage_tarball()
1538  {  {
1539   local latest_tarball   local latest_tarball
1540     local latest_md5
1541   local temp="$(mktemp -d)"   local temp="$(mktemp -d)"
1542   local mirr mymirr   local mirr mymirr
1543     local opt
1544     local tar_opts
1545     local wget_opts
1546    
1547     # try to get the md5 marked as latest on the server
1548     latest_md5="mage-latest.md5"
1549    
1550   # try to get the tarball marked as latest on the server   # try to get the tarball marked as latest on the server
1551   latest_tarball="mage-latest.tar.bz2"   latest_tarball="mage-latest.tar.bz2"
1552    
1553     # filter wget command if busybox was found
1554     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1555    
1556   for mirr in ${MIRRORS}   for mirr in ${MIRRORS}
1557   do   do
1558   # path without distribution   # path without distribution
1559   mymirr="${mirr%/*}"   # (only for stable|testing|unstable and not DISTROTAG)
1560     case ${mirr##*/} in
1561     stable|testing|unstable) mymirr="${mirr%/*}";;
1562     *) mymirr="${mirr}";;
1563     esac
1564    
1565   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1566   echo "fetching latest tarball from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
1567     mqueryfeature "!verbose" && opt="--quiet"
1568     wget \
1569     ${wget_opts} \
1570     --directory-prefix=${temp} \
1571     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1572    
1573     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1574     echo "fetching latest tarball from ${mymirr} ..."
1575   wget \   wget \
1576   --passive-ftp \   ${wget_opts} \
  --tries 3 \  
  --continue \  
  --progress bar \  
1577   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1578   ${mymirr}/rsync/tarballs/${latest_tarball}   ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1579   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1580   then   then
1581   break   break
# Line 1263  syncmage_tarball() Line 1586  syncmage_tarball()
1586    
1587   if [[ -f ${temp}/${latest_tarball} ]]   if [[ -f ${temp}/${latest_tarball} ]]
1588   then   then
1589     # check md5
1590     if [[ ! -f ${temp}/${latest_md5} ]]
1591     then
1592     die "md5 is missing ... aborting"
1593     else
1594     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1595     echo -n "checking md5sum... "
1596     mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1597     fi
1598    
1599   if [[ -d ${MAGEDIR} ]]   if [[ -d ${MAGEDIR} ]]
1600   then   then
1601   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1602   echo "cleaning old mage-tree ${MAGEDIR}..."   echo "cleaning old mage-tree ${MAGEDIR}..."
1603   rm -rf ${MAGEDIR}   # honor mountpoints and empty dirs
1604     if mountpoint -q ${MAGEDIR}
1605     then
1606     if ! mcheckemptydir ${MAGEDIR}
1607     then
1608     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1609     fi
1610     else
1611     rm -rf ${MAGEDIR}
1612     fi
1613     fi
1614    
1615     if need_busybox_support tar
1616     then
1617     tar_opts="xjf"
1618     else
1619     tar_opts="xjmf"
1620   fi   fi
1621    
1622   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1623   echo "updating mage-tree from tarball ..."   echo "updating mage-tree from tarball ..."
1624   # unpack in dirname of MAGEDIR, as the tarball has already the mage   # unpack in dirname of MAGEDIR, as the tarball has already the mage
1625   tar xjmf ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"   tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1626    
1627   if [[ -d ${temp} ]]   if [[ -d ${temp} ]]
1628   then   then
# Line 1319  xtitleclean() Line 1668  xtitleclean()
1668  }  }
1669    
1670    
1671  # cuts full pathnames or versioniezed names down to basename  # unused?
1672  choppkgname()  #
1673  {  # # cuts full pathnames or versionized names down to basename
1674   #we want this only if full name was used  # choppkgname()
1675   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1676   then  # #we want this only if full name was used
1677   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1678   #ARCH comes from ${MAGERC}  # then
1679   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1680    # #ARCH comes from ${MAGERC}
1681    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1682    #
1683    # #cuts version number
1684    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1685    # fi
1686    # }
1687    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1688    
1689  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1690  # $1=pname  # $1=pname
# Line 1402  get_highest_magefile() Line 1754  get_highest_magefile()
1754   local magefile   local magefile
1755    
1756   # do not list the content of a directory, only the name (-d)   # do not list the content of a directory, only the name (-d)
1757   for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/*)   for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1758   do   do
1759   [[ -z ${magefile} ]] && continue   [[ -z ${magefile} ]] && continue
1760   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
# Line 1411  get_highest_magefile() Line 1763  get_highest_magefile()
1763   then   then
1764   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1765   #for debug only   #for debug only
1766   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"
1767   fi   fi
1768   done   done
1769    
 # 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  
   
1770   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1771   return 0   return 0
1772  }  }
# Line 1540  count_protected_files() Line 1870  count_protected_files()
1870   local filename="${file##*/}"   local filename="${file##*/}"
1871   local count   local count
1872   local output   local output
1873     local oldprotected
1874   local i   local i
1875     local x
1876    
1877     # hack; do not honor a global set IFS like '§'
1878     local IFS
1879    
1880   declare -i count=0   count=0
1881    
1882   # check if there are already protected files   # check if there are already protected files
1883   for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |   for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1884   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1885   sort -t'%' -k3 -k2 | cut -f1 -d'%')   sort -t'%' -k3 -k2 | cut -f1 -d'%')
1886   do   do
1887   count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")   count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1888   done   done
1889   (( count ++ ))  
1890     # convert 0001 -> 1; 0120 -> 120 etc
1891     # use bash internal base functions to this task
1892     x="$((10#${count}))"
1893     for (( i=0; i<x; i++ ))
1894     do
1895     if [[ ${count:${i}:1} != 0 ]]
1896     then
1897     count="${count:${i}}"
1898     break
1899     fi
1900     done
1901    
1902     count="$(( ${count}+1 ))"
1903    
1904   # fill output up with zeros   # fill output up with zeros
1905   for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done   for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
# Line 1729  virtuals_add() Line 2077  virtuals_add()
2077    
2078  #deletes pakages from virtual database  #deletes pakages from virtual database
2079  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
2080  virtuals_del() {  virtuals_del()
2081    {
2082    
2083   local virtualname="$1"   local virtualname="$1"
2084   local pkgname="$2"   local pkgname="$2"
# Line 1840  minclude() Line 2189  minclude()
2189   then   then
2190   for i in $*   for i in $*
2191   do   do
2192   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2193   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2194   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2195   done   done
2196   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2197   fi   fi
2198  }  }
2199    
# Line 2288  mage_install() Line 2637  mage_install()
2637   if [[ -n ${MAGE_TARGETS} ]]   if [[ -n ${MAGE_TARGETS} ]]
2638   then   then
2639   # basic svn compat   # basic svn compat
2640   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2641   then   then
2642   for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2643   do   do
2644   smage2file="${i}"   smage2file="${i}"
2645   done   done
# Line 2301  mage_install() Line 2650  mage_install()
2650   elif [[ -n ${SPLIT_PACKAGE_BASE} ]]   elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2651   then   then
2652   # basic svn compat   # basic svn compat
2653   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2654   then   then
2655   for i in ${SMAGESCRIPTSDIR}/trunk/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2656   do   do
2657   smage2file="${i}"   smage2file="${i}"
2658   done   done
# Line 2313  mage_install() Line 2662  mage_install()
2662    
2663   else   else
2664   # basic svn compat   # basic svn compat
2665   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2666   then   then
2667   for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2668   do   do
2669   smage2file="${i}"   smage2file="${i}"
2670   done   done
# Line 2454  md5sum_packages() Line 2803  md5sum_packages()
2803   then   then
2804   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2805   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2806   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2807   else   else
2808   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2809   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2667  mage_uninstall() Line 3016  mage_uninstall()
3016   unset -f postremove   unset -f postremove
3017  }  }
3018    
3019  show_etc_update_mesg() {  show_etc_update_mesg()
3020    {
3021   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
3022    
3023   echo   echo
# Line 2693  pkgsearch() Line 3043  pkgsearch()
3043   local state   local state
3044   local descriptiom   local descriptiom
3045   local homepage   local homepage
3046     local license
3047   local i   local i
3048   local all_installed   local all_installed
3049   local ipver   local ipver
# Line 2729  pkgsearch() Line 3080  pkgsearch()
3080   state="$(get_value_from_magefile STATE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3081   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3082   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3083     license="$(get_value_from_magefile LICENSE ${magefile})"
3084    
3085   # all installed   # all installed
3086   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3087   do   do
3088   ipver="$(magename2pver ${i})"   ipver="$(magename2pver ${i})"
3089   ipbuild="$(magename2pbuild ${i})"   ipbuild="$(magename2pbuild ${i})"
3090    
3091   if [[ -z ${all_installed} ]]   if [[ -z ${all_installed} ]]
3092   then   then
3093   all_installed="${ipver}-${ipbuild}"   all_installed="${ipver}-${ipbuild}"
# Line 2744  pkgsearch() Line 3096  pkgsearch()
3096   fi   fi
3097   done   done
3098   [[ -z ${all_installed} ]] && all_installed="none"   [[ -z ${all_installed} ]] && all_installed="none"
3099    
3100   case ${state} in   case ${state} in
3101   stable) state=${COLGREEN}"[s] ";;   stable) state=${COLGREEN}"[s] ";;
3102   testing) state=${COLYELLOW}"[t] ";;   testing) state=${COLYELLOW}"[t] ";;
# Line 2768  pkgsearch() Line 3120  pkgsearch()
3120   "") continue;;   "") continue;;
3121   esac   esac
3122    
3123   deps="${deps} $(basename ${dep%-*})"   if [[ -z ${deps} ]]
3124     then
3125     deps="$(basename ${dep%-*})"
3126     else
3127     deps="${deps} $(basename ${dep%-*})"
3128     fi
3129   done << EOF   done << EOF
3130  ${depsfull}  ${depsfull}
3131  EOF  EOF
# Line 2779  EOF Line 3136  EOF
3136   "") continue;;   "") continue;;
3137   esac   esac
3138    
3139   sdeps="${sdeps} $(basename ${dep%-*})"   if [[ -z ${sdeps} ]]
3140     then
3141     sdeps="$(basename ${dep%-*})"
3142     else
3143     sdeps="${sdeps} $(basename ${dep%-*})"
3144     fi
3145   done << EOF   done << EOF
3146  ${sdepsfull}  ${sdepsfull}
3147  EOF  EOF
# Line 2789  EOF Line 3151  EOF
3151   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3152   echo "      Description: ${description}"   echo "      Description: ${description}"
3153   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3154   echo "      Depends: ${deps}"   if [[ ! -z ${license} ]]
3155     then
3156     echo "      License:  ${license}"
3157     fi
3158     echo "      Depends:  ${deps}"
3159   echo "      SDepends: ${sdeps}"   echo "      SDepends: ${sdeps}"
3160   echo   echo
3161    
# Line 2829  export_inherits() Line 3195  export_inherits()
3195   eval "${functions}() { ${include}_${functions} ; }"   eval "${functions}() { ${include}_${functions} ; }"
3196    
3197   # debug   # debug
3198   [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"   mqueryfeature "debug" && typeset -f "${functions}"
3199    
3200   shift   shift
3201   done   done
# Line 2901  EOF Line 3267  EOF
3267   return 0   return 0
3268  }  }
3269    
3270    # need_busybox_support ${cmd}
3271    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3272    need_busybox_support()
3273    {
3274     local cmd
3275     local busybox
3276     cmd="$1"
3277    
3278     for busybox in {,/usr}/bin/busybox
3279     do
3280     if [[ -x ${busybox} ]]
3281     then
3282     if [[ $(readlink $(which ${cmd})) = ${busybox} ]]
3283     then
3284     # needs busybox support
3285     return 0
3286     fi
3287     fi
3288     done
3289    
3290     # no busybox
3291     return 1
3292    }
3293    
3294    # busybox_filter_wget_options ${wget_opts}
3295    busybox_filter_wget_options()
3296    {
3297     local opts="$@"
3298     local i
3299     local fixed_opts
3300    
3301     if need_busybox_support wget
3302     then
3303     for i in ${opts}
3304     do
3305     # show only the allowed ones
3306     case ${i} in
3307     -c|--continue) fixed_opts+=" -c" ;;
3308     -s|--spider) fixed_opts+=" -s" ;;
3309     -q|--quiet) fixed_opts+=" -q" ;;
3310     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3311     --header) shift; fixed_opts+=" --header $1" ;;
3312     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3313     -P) shift; fixed_opts+=" -P $1" ;;
3314     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3315     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3316     # simply drop all other opts
3317     *) continue ;;
3318     esac
3319     done
3320    
3321     echo "${fixed_opts}"
3322     else
3323     echo "${opts}"
3324     fi
3325    }
3326    
3327    have_root_privileges()
3328    {
3329     local retval
3330    
3331     if [[ $(id -u) = 0 ]]
3332     then
3333     retval=0
3334     else
3335     retval=1
3336     fi
3337    
3338     return ${retval}
3339    }
3340    
3341    known_mage_feature()
3342    {
3343     local feature="$1"
3344     local retval
3345    
3346     case "${feature}" in
3347     autosvc|!autosvc) retval=0 ;;
3348     buildlog|!buildlog) retval=0 ;;
3349     ccache|!ccache) retval=0 ;;
3350     check|!check) retval=0 ;;
3351     compressdoc|!compressdoc) retval=0 ;;
3352     debug|!debug) retval=0 ;;
3353     distcc|!distcc) retval=0 ;;
3354     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3355     libtool|!libtool) retval=0 ;;
3356     linuxsymlink|!linuxsymlink) retval=0 ;;
3357     pkgbuild|!pkgbuild) retval=0 ;;
3358     pkgdistrotag|!pkgdistrotag) 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_FEATURE_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.972  
changed lines
  Added in v.1963