Magellan Linux

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

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

revision 294 by niro, Sun Dec 4 11:54:15 2005 UTC revision 1549 by niro, Tue Dec 27 10:43:40 2011 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.11 2005-12-04 11:54:15 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  {  {
# 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(): unkown method '${method}'" ;;
70     esac
71    
72     if [[ -d ${rundir} ]]
73     then
74     pushd ${rundir} &> /dev/null
75     ${cmd} -c ${file} &> /dev/null
76     retval="$?"
77     popd &> /dev/null
78     else
79     retval=1
80     fi
81    
82     return "${retval}"
83    }
84    
85  unpack_packages()  unpack_packages()
86  {  {
87   local list="$@"   local list="$@"
# Line 23  unpack_packages() Line 90  unpack_packages()
90   local pkgtype   local pkgtype
91   local count_current   local count_current
92   local count_total   local count_total
93     local tar_opts
94    
95   # get count of total packages   # get count of total packages
96   declare -i count_current=0   declare -i count_current=0
# Line 54  unpack_packages() Line 122  unpack_packages()
122   continue   continue
123   fi   fi
124    
125     # busybox?
126     if need_busybox_support tar
127     then
128     tar_opts="xjf"
129     else
130     tar_opts="xjmf"
131     fi
132    
133   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "
134   tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"   tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"
135   done   done
136    
137   # add a crlf for a better view   # add a crlf for a better view
# Line 132  install_directories() Line 208  install_directories()
208   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
209   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
210    
   
211   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
212   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
213    
# Line 198  install_files() Line 273  install_files()
273   is_config_protected "${pathto}"   is_config_protected "${pathto}"
274   retval="$?"   retval="$?"
275    
276   # 0 - not protected        #   # 0 - not protected         #
277   # 1 - error                #   # 1 - error                 #
278   # 2 - protected            #   # 2 - protected             #
279   # 3 - protected but masked #   # 3 - protected but masked  #
280     # 4 - protected but ignored #
281    
282   case ${retval} in   case ${retval} in
283   # file is not protected - (over)write it   # file is not protected - (over)write it
# Line 218  install_files() Line 294  install_files()
294   "${user}" \   "${user}" \
295   "${group}" \   "${group}" \
296   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
297   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
298   "${md5sum}"   "${md5sum}"
299   ;;   ;;
300    
# Line 245  install_files() Line 321  install_files()
321   "${user}" \   "${user}" \
322   "${group}" \   "${group}" \
323   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
324   "${dest_protected}")" \   "${dest_protected}")" \
325   "${md5sum}"   "${md5sum}"
326    
327   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
328   (( MAGE_PROTECT_COUNTER++ ))   (( MAGE_PROTECT_COUNTER++ ))
329   export MAGE_PROTECT_COUNTER   export MAGE_PROTECT_COUNTER
330   ;;   ;;
331    
332     # file is protected but ignored, delete the update/do nothing
333     4)
334     if [[ ${VERBOSE} = on ]]
335     then
336     echo -en "${COLRED}"
337     echo -n "! ignr "
338     echo -en "${COLDEFAULT}"
339     echo " === FILE: ${MROOT}${pathto}"
340     fi
341     # simply do nothing here - only fix mtime
342     fix_descriptor ${pkgname}/.files \
343     "${pathto}" \
344     "${posix}" \
345     "${user}" \
346     "${group}" \
347     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
348     "${MROOT}${pathto}")" \
349     "${md5sum}"
350     ;;
351   esac   esac
352   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
353    
# Line 298  install_symlinks() Line 394  install_symlinks()
394    
395   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
396    
397   # fix mtime and db  # # fix mtime and db
398   fix_descriptor ${pkgname}/.symlinks \  # fix_descriptor ${pkgname}/.symlinks \
399   "${pathto}" \  # "${pathto}" \
400   "${posix}" \  # "${posix}" \
401   "${link}" \  # "${link}" \
402   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
403   "${MROOT}${pathto}")"  # "${MROOT}${pathto}")"
404    
405   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
406    
407   # now copy the fixed file over the old one  # # now copy the fixed file over the old one
408   [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \  # [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \
409   cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}  # cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}
410    
411   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
412   IFS=$'\n'   IFS=$'\n'
# Line 326  install_blockdevices() Line 422  install_blockdevices()
422   local pkgname="$1"   local pkgname="$1"
423   local pathto   local pathto
424   local posix   local posix
425     local user
426     local group
427   local IFS   local IFS
428    
429   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 339  install_blockdevices() Line 437  install_blockdevices()
437   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
438   IFS=§   IFS=§
439    
440   while read pathto posix   while read pathto posix major minor user group
441   do   do
442   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
443   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
444    
445   mkfifo -m "${posix}" "${MROOT}$pathto"   mknod -m "${posix}" "${MROOT}${pathto}"
446     # make it optional atm !!
447     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
448     then
449     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
450     fi
451   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
452    
453   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 361  install_characterdevices() Line 464  install_characterdevices()
464   local pkgname="$1"   local pkgname="$1"
465   local pathto   local pathto
466   local posix   local posix
467     local major
468     local minor
469     local user
470     local group
471   local IFS   local IFS
472    
473   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 374  install_characterdevices() Line 481  install_characterdevices()
481   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
482   IFS=§   IFS=§
483    
484   while read pathto posix   while read pathto posix major minor user group
485   do   do
486   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
487   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
488    
489   mknode -m ${posix} -c "${MROOT}${pathto}"   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
490    
491     # make it optional atm !!
492     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
493     then
494     chown "${user}:${group}" "${MROOT}${pathto}"
495     fi
496   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
497    
498   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
499   IFS=$'\n'   IFS=$'\n'
500  }  }
501    
502    ###################################################
503    # function install_fifos                          #
504    # install_fifos $PKGNAME                    #
505    ###################################################
506    install_fifos()
507    {
508     local pkgname="$1"
509     local pathto
510     local posix
511     local user
512     local group
513     local IFS
514    
515     # sanity checks; abort if not given
516     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
517    
518     # check needed global vars
519     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
520    
521     # make it optional atm !!
522     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
523     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
524    
525     # sets fieldseperator to "§" instead of " "
526     IFS=§
527    
528     while read pathto posix user group
529     do
530     [ -z "${pathto}" ] && continue
531     [[ ${VERBOSE} = on ]] && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
532    
533     mkfifo -m "${posix}" "${MROOT}${pathto}"
534     chown "${user}:${group}" "${MROOT}${pathto}"
535     done < ${BUILDDIR}/${pkgname}/.fifo
536    
537     # very important: unsetting the '§' fieldseperator
538     IFS=$'\n'
539    }
540    
541    
542  ###################################################  ###################################################
543  # function build_doinstall                        #  # function build_doinstall                        #
544  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
545  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
546  ###################################################  ###################################################
547  build_doinstall()  build_doinstall()
548  {  {
# Line 398  build_doinstall() Line 550  build_doinstall()
550    
551   # sanity checks; abort if not given   # sanity checks; abort if not given
552   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
553    
554   # this is only a wrapper   # this is only a wrapper
555    
556   # NOTE:   # NOTE:
# Line 413  build_doinstall() Line 565  build_doinstall()
565   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
566   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
567   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
568     install_fifos ${pkgname} || die "install fifos ${pkgname}"
569  }  }
570    
571    
# Line 474  install_database_entry() Line 627  install_database_entry()
627    
628   # create fake file descriptors   # create fake file descriptors
629   # used by virtual and source packages   # used by virtual and source packages
630   for i in .dirs .symlinks .files .pipes .char   for i in .dirs .symlinks .files .pipes .char .fifo
631   do   do
632   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
633   done   done
# Line 492  install_database_entry() Line 645  install_database_entry()
645    
646   # normal packages needs these files   # normal packages needs these files
647   local i   local i
648   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
649   do   do
650   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
651   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
652     then
653     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
654     fi
655   done   done
656   ;;   ;;
657   esac   esac
# Line 770  remove_files() Line 926  remove_files()
926   done   done
927    
928   # sanity checks; abort if not given   # sanity checks; abort if not given
929   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
930   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
931   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
932   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
933   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
934    
935   # check needed global vars   # check needed global vars
# Line 807  remove_files() Line 963  remove_files()
963   is_config_protected "${pathto}"   is_config_protected "${pathto}"
964   retval="$?"   retval="$?"
965    
966   # 0 - not protected        #   # 0 - not protected         #
967   # 1 - error                #   # 1 - error                 #
968   # 2 - protected            #   # 2 - protected             #
969   # 3 - protected but masked #   # 3 - protected but masked  #
970     # 4 - protected but ignored #
971    
972   case ${retval} in   case ${retval} in
973   # file is not protected - delete it   # file is not protected - delete it
# Line 829  remove_files() Line 986  remove_files()
986   echo " === FILE: ${MROOT}${pathto}"   echo " === FILE: ${MROOT}${pathto}"
987   fi   fi
988   ;;   ;;
989    
990     # file is protected but ignored, delete the update/do nothing
991     4)
992     if [[ ${VERBOSE} = on ]]
993     then
994     echo -en "${COLRED}"
995     echo -n "! ignr "
996     echo -en "${COLDEFAULT}"
997     echo " === FILE: ${MROOT}${pathto}"
998     fi
999     # simply do nothing here
1000     ;;
1001   esac   esac
1002   ;;   ;;
1003   1)   1)
# Line 851  remove_blockdevices() Line 1020  remove_blockdevices()
1020  {  {
1021   local pathto   local pathto
1022   local posix   local posix
1023     local user
1024     local group
1025   local IFS   local IFS
1026   local pcat   local pcat
1027   local pname   local pname
# Line 874  remove_blockdevices() Line 1045  remove_blockdevices()
1045   done   done
1046    
1047   # sanity checks; abort if not given   # sanity checks; abort if not given
1048   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1049   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1050   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1051   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1052   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1053    
1054   # check needed global vars   # check needed global vars
# Line 888  remove_blockdevices() Line 1059  remove_blockdevices()
1059   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1060   IFS=§   IFS=§
1061    
1062   while read pathto posix   while read pathto posix user group
1063   do   do
1064   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1065    
# Line 909  remove_characterdevices() Line 1080  remove_characterdevices()
1080  {  {
1081   local pathto   local pathto
1082   local posix   local posix
1083     local user
1084     local group
1085   local IFS   local IFS
1086   local pcat   local pcat
1087   local pname   local pname
# Line 932  remove_characterdevices() Line 1105  remove_characterdevices()
1105   done   done
1106    
1107   # sanity checks; abort if not given   # sanity checks; abort if not given
1108   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1109   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1110   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1111   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1112   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1113    
1114   # check needed global vars   # check needed global vars
# Line 946  remove_characterdevices() Line 1119  remove_characterdevices()
1119   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1120   IFS=§   IFS=§
1121    
1122   while read pathto posix   while read pathto posix user group
1123   do   do
1124   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1125    
# Line 960  remove_characterdevices() Line 1133  remove_characterdevices()
1133    
1134    
1135  ###################################################  ###################################################
1136    # function remove_fifos                           #
1137    # remove_fifos $PKGNAME                     #
1138    ###################################################
1139    remove_fifos()
1140    {
1141     local pathto
1142     local posix
1143     local user
1144     local group
1145     local IFS
1146     local pcat
1147     local pname
1148     local pver
1149     local pbuild
1150     local i
1151     local pfull
1152    
1153     IFS=$'\n'
1154    
1155     # very basic getops
1156     for i in $*
1157     do
1158     case $1 in
1159     --pcat|-c) shift; pcat="$1" ;;
1160     --pname|-n) shift; pname="$1" ;;
1161     --pver|-v) shift; pver="$1" ;;
1162     --pbuild|-b) shift; pbuild="$1" ;;
1163     esac
1164     shift
1165     done
1166    
1167     # sanity checks; abort if not given
1168     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1169     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1170     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1171     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1172     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1173    
1174     # check needed global vars
1175     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1176    
1177     # make it optional atm !!
1178     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1179     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1180    
1181     # sets fieldseperator to "§" instead of " "
1182     IFS=§
1183    
1184     while read pathto posix user group
1185     do
1186     [ -z "${pathto}" ] && continue
1187    
1188     [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1189     rm "${MROOT}${pathto}"
1190     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1191    
1192     # very important: unsetting the '§' fieldseperator
1193     IFS=$'\n'
1194    }
1195    
1196    
1197    ###################################################
1198  # function remove_direcories                      #  # function remove_direcories                      #
1199  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1200  ###################################################  ###################################################
# Line 990  remove_directories() Line 1225  remove_directories()
1225   done   done
1226    
1227   # sanity checks; abort if not given   # sanity checks; abort if not given
1228   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1229   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1230   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1231   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1232   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1233    
1234   # check needed global vars   # check needed global vars
# Line 1047  remove_directories() Line 1282  remove_directories()
1282  ###################################################  ###################################################
1283  # function build_douninstall                      #  # function build_douninstall                      #
1284  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1285  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1286  ###################################################  ###################################################
1287  build_douninstall()  build_douninstall()
1288  {  {
# Line 1081  build_douninstall() Line 1316  build_douninstall()
1316   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1317   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1318    
1319   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1320   do   do
1321   remove_${i} \   remove_${i} \
1322   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1092  build_douninstall() Line 1327  build_douninstall()
1327   done   done
1328  }  }
1329    
1330    # convertmirrors [uri]
1331    convertmirrors()
1332    {
1333     local uri="$1"
1334     local scheme
1335     local mirror
1336     local mirrors
1337     local addon
1338     local real_uri
1339     local output
1340    
1341     # needs
1342     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1343     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1344     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1345     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1346     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1347    
1348     # check known uri schemes
1349     case ${uri} in
1350     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1351     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1352     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1353     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1354     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1355     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1356     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1357     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1358     esac
1359    
1360     if [[ ! -z ${mirrors} ]]
1361     then
1362     for mirror in ${mirrors}
1363     do
1364     # add a whitespace to the output
1365     [[ -z ${output} ]] || output+=" "
1366     output+="${mirror}${addon}/${uri/${scheme}/}"
1367     done
1368     else
1369     output="${uri}"
1370     fi
1371    
1372     echo "${output}"
1373    }
1374    
1375    mdownload()
1376    {
1377     local i
1378     local uri
1379     local real_uris
1380     local mirror
1381     local outputfile
1382     local outputdir
1383     local retval
1384     local wget_opts
1385    
1386     # very basic getops
1387     for i in $*
1388     do
1389     case $1 in
1390     --uri|-u) shift; uri="$1" ;;
1391     --dir|-d) shift; outputdir="$1" ;;
1392     esac
1393     shift
1394     done
1395    
1396     # sanity checks; abort if not given
1397     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1398     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1399    
1400     # convert mirrored uris to the real ones
1401     real_uris="$(convertmirrors ${uri})"
1402    
1403     # verbose or not
1404     [[ ${VERBOSE} = off ]] && wget_opts="--quiet"
1405    
1406     # filter wget options if busybox was found
1407     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1408    
1409     # create outputdir
1410     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1411    
1412     for mirror in ${real_uris}
1413     do
1414     # get the name of the output file
1415     outputfile="${mirror##*/}"
1416    
1417     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1418     retval="$?"
1419     if [[ ${retval} = 0 ]]
1420     then
1421     break
1422     else
1423     continue
1424     fi
1425     done
1426    
1427     # return wget retval
1428     return "${retval}"
1429    }
1430    
1431  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1432  fetch_packages()  fetch_packages()
1433  {  {
1434     local i
1435   local list="$@"   local list="$@"
1436   local pkg   local pkg
1437   local mirr   local mirr
# Line 1103  fetch_packages() Line 1440  fetch_packages()
1440   local opt   local opt
1441   local count_current   local count_current
1442   local count_total   local count_total
1443     local wget_opts
1444    
1445     [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1446    
1447   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc."   # filter wget command if busybox was found
1448     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1449    
1450   # get count of total packages   # get count of total packages
1451   declare -i count_current=0   declare -i count_current=0
# Line 1144  fetch_packages() Line 1485  fetch_packages()
1485   continue   continue
1486   fi   fi
1487    
1488   for mirr in ${MIRRORS}   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1489   do   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1490   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  
1491    
1492   if [ ! -f ${PKGDIR}/${pkg} ]   if [ ! -f ${PKGDIR}/${pkg} ]
1493   then   then
1494   die "Could not download ${pkg}"   die "Package '${pkg}' after download not found in '${PKGDIR}'"
1495   fi   fi
1496   done   done
1497    
# Line 1179  syncmage() Line 1503  syncmage()
1503  {  {
1504   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1505   then   then
1506   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1507   fi   fi
1508    
1509   local i   local i
1510   for i in ${RSYNC}   for i in ${RSYNC}
1511   do   do
1512   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
  --recursive \  
  --links \  
  --perms \  
  --times \  
  --devices \  
  --timeout=600 \  
  --verbose \  
  --compress \  
  --progress \  
  --stats \  
  --delete \  
  --delete-after \  
  ${i} ${MAGEDIR}  
1513   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1514   then   then
1515   break   break
# Line 1208  syncmage() Line 1519  syncmage()
1519   done   done
1520    
1521   # clean up backup files (foo~)   # clean up backup files (foo~)
1522   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1523    
1524   # check if an newer mage version is available   # check if a newer mage version is available
1525   is_newer_mage_version_available   is_newer_mage_version_available
1526  }  }
1527    
1528    syncmage_tarball()
1529    {
1530     local latest_tarball
1531     local latest_md5
1532     local temp="$(mktemp -d)"
1533     local mirr mymirr
1534     local opt
1535     local tar_opts
1536     local wget_opts
1537    
1538     # try to get the md5 marked as latest on the server
1539     latest_md5="mage-latest.md5"
1540    
1541     # try to get the tarball marked as latest on the server
1542     latest_tarball="mage-latest.tar.bz2"
1543    
1544     # filter wget command if busybox was found
1545     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1546    
1547     for mirr in ${MIRRORS}
1548     do
1549     # path without distribution
1550     mymirr="${mirr%/*}"
1551    
1552     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1553     echo "fetching latest md5 from ${mymirr} ..."
1554     [[ ${VERBOSE} = off ]] && opt="--quiet"
1555     wget \
1556     ${wget_opts} \
1557     --directory-prefix=${temp} \
1558     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1559    
1560     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1561     echo "fetching latest tarball from ${mymirr} ..."
1562     wget \
1563     ${wget_opts} \
1564     --directory-prefix=${temp} \
1565     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1566     if [[ $? = 0 ]]
1567     then
1568     break
1569     else
1570     continue
1571     fi
1572     done
1573    
1574     if [[ -f ${temp}/${latest_tarball} ]]
1575     then
1576     # check md5
1577     if [[ ! -f ${temp}/${latest_md5} ]]
1578     then
1579     die "md5 is missing ... aborting"
1580     else
1581     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1582     echo -n "checking md5sum... "
1583     ( cd ${temp}; md5sum -c ${latest_md5} ) || die "md5 for ${latest_tarball} failed"
1584     fi
1585    
1586     if [[ -d ${MAGEDIR} ]]
1587     then
1588     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1589     echo "cleaning old mage-tree ${MAGEDIR}..."
1590     rm -rf ${MAGEDIR}
1591     fi
1592    
1593     if need_busybox_support tar
1594     then
1595     tar_opts="xjf"
1596     else
1597     tar_opts="xjmf"
1598     fi
1599    
1600     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1601     echo "updating mage-tree from tarball ..."
1602     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1603     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1604    
1605     if [[ -d ${temp} ]]
1606     then
1607     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1608     echo "cleaning temp-files ..."
1609     rm -rf ${temp}
1610     fi
1611    
1612     # check if a newer mage version is available
1613     is_newer_mage_version_available
1614     else
1615     die "Could not fetch the latest tarball ... aborting"
1616     fi
1617    }
1618    
1619  cleanpkg()  cleanpkg()
1620  {  {
1621   if [ -d "${PKGDIR}" ]   if [ -d "${PKGDIR}" ]
# Line 1244  xtitleclean() Line 1646  xtitleclean()
1646  }  }
1647    
1648    
1649  # cuts full pathnames or versioniezed names down to basename  # cuts full pathnames or versionized names down to basename
1650  choppkgname()  choppkgname()
1651  {  {
1652   #we want this only if full name was used   #we want this only if full name was used
1653   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1654   then   then
1655   #cuts ARCH and PBUILD   #cuts ARCH and PBUILD
1656   #ARCH comes from /etc/mage.rc   #ARCH comes from ${MAGERC}
1657   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")
1658    
1659   #cuts version number   #cuts version number
# Line 1284  pname2pcat() Line 1686  pname2pcat()
1686  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1687  check_stable_package()  check_stable_package()
1688  {  {
1689     # first check if this magefile is not blacklisted
1690     blacklisted "$1" || return 1
1691    
1692   local STATE   local STATE
1693   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1694    
# Line 1323  get_highest_magefile() Line 1728  get_highest_magefile()
1728   local PNAME="$2"   local PNAME="$2"
1729   local magefile   local magefile
1730    
1731   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1732     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1733   do   do
1734     [[ -z ${magefile} ]] && continue
1735   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1736   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1737   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1738   then   then
1739   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
# Line 1335  get_highest_magefile() Line 1742  get_highest_magefile()
1742   fi   fi
1743   done   done
1744    
  # 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  
   
1745   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1746   return 0   return 0
1747  }  }
# Line 1370  get_highest_magefile() Line 1756  get_highest_magefile()
1756  #        1 - error                                #  #        1 - error                                #
1757  #        2 - protected                            #  #        2 - protected                            #
1758  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1759    #        4 - protected but ignored                #
1760  #                                                 #  #                                                 #
1761  ###################################################  ###################################################
1762  is_config_protected()  is_config_protected()
# Line 1378  is_config_protected() Line 1765  is_config_protected()
1765   local TEST   local TEST
1766   local PROTECTED   local PROTECTED
1767   local IFS   local IFS
1768     local i
1769     local x
1770    
1771   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1772    
1773   # file does not exist; it can be written   # file does not exist; it can be written
1774   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1775    
1776   # to be safe; it may be '§'   # to be safe; it may be '§'
1777   IFS=' '   IFS=' '
1778    
1779   # check ob in config protect   # check if config protected
1780   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1781   do   do
1782   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1783   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1784   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1785   then   then
1786   # setzen das es protected ist   # file is config proteced
1787   PROTECTED=TRUE   PROTECTED=TRUE
1788    
1789   # check ob nicht doch maskiert   # check if not masked
1790   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1791   do   do
1792   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1793   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1794   then   then
1795   PROTECTED=MASKED   PROTECTED=MASKED
1796   fi   fi
1797   done   done
1798    
1799     # check if not ignored
1800     for x in ${CONFIG_PROTECT_IGNORE}
1801     do
1802     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1803     if [[ ${TEST} != ${EXPFILE} ]]
1804     then
1805     PROTECTED=IGNORED
1806     fi
1807     done
1808   fi   fi
1809   done   done
1810    
# Line 1420  is_config_protected() Line 1819  is_config_protected()
1819   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1820   return 3   return 3
1821   ;;   ;;
1822     IGNORED)
1823     #echo "I'm protected, but ignored - keep me, del update"
1824     return 4
1825     ;;
1826   *)   *)
1827   #echo "delete me"   #echo "delete me"
1828   return 0   return 0
# Line 1437  is_config_protected() Line 1840  is_config_protected()
1840  ###################################################  ###################################################
1841  count_protected_files()  count_protected_files()
1842  {  {
1843   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1844     local dirname="${file%/*}"
1845     local filename="${file##*/}"
1846     local count
1847     local output
1848     local i
1849    
1850     declare -i count=0
1851    
1852     # check if there are already protected files
1853     for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |
1854     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1855     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1856     do
1857     count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")
1858     done
1859     (( count ++ ))
1860    
1861     # fill output up with zeros
1862     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1863     output="${output}${count}"
1864    
1865     echo "${output}"
1866  }  }
1867    
1868  # call with  # call with
# Line 1454  get_uninstall_candidates() Line 1879  get_uninstall_candidates()
1879   local list   local list
1880   local pcatdir   local pcatdir
1881   local protected   local protected
1882     local i
1883    
1884   # very basic getops   # very basic getops
1885   for i in $*   for i in $*
# Line 1466  get_uninstall_candidates() Line 1892  get_uninstall_candidates()
1892   shift   shift
1893   done   done
1894    
1895   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1896   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1897    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1898    
1899    
1900   # check needed global vars   # check needed global vars
1901   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1902    
1903   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1904   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1905    
1906   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1907   do   do
# Line 1563  virtuals_add() Line 1990  virtuals_add()
1990    
1991   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
1992   then   then
1993   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1994   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1995   do   do
1996   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1607  virtuals_add() Line 2034  virtuals_add()
2034    
2035  #deletes pakages from virtual database  #deletes pakages from virtual database
2036  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
2037  virtuals_del() {  virtuals_del()
2038    {
2039    
2040   local virtualname="$1"   local virtualname="$1"
2041   local pkgname="$2"   local pkgname="$2"
# Line 1714  minclude() Line 2142  minclude()
2142  {  {
2143   local i   local i
2144    
2145   if [ -n "$@" ]   if [[ -n $* ]]
2146   then   then
2147   for i in $@   for i in $*
2148   do   do
2149   [[ ${MAGEDEBUG} = on ]] && \   [[ ${MAGEDEBUG} = on ]] && \
2150   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
# Line 1730  sminclude() Line 2158  sminclude()
2158  {  {
2159   local i   local i
2160    
2161   if [ -n "$@" ]   if [[ -n $* ]]
2162   then   then
2163   for i in $@   for i in $*
2164   do   do
2165   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2166   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
# Line 1756  is_newer_mage_version_available() Line 2184  is_newer_mage_version_available()
2184   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2185   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2186   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
2187   echo "or your current system installation may brake."   echo "or your current system installation may break."
2188   echo   echo
2189   echo -en "Please update mage by running "   echo -en "Please update mage by running "
2190   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 2028  get_value_from_magefile() Line 2456  get_value_from_magefile()
2456   local magefile="$2"   local magefile="$2"
2457   local value   local value
2458    
2459     [[ -z ${var} ]] && return 1
2460     [[ -z ${magefile} ]] && return 1
2461    
2462   # local all possible vars of a mage file   # local all possible vars of a mage file
2463   # to prevent bad issues   # to prevent bad issues
2464   local PKGNAME   local PKGNAME
# Line 2038  get_value_from_magefile() Line 2469  get_value_from_magefile()
2469   local SDEPEND   local SDEPEND
2470   local PROVIDE   local PROVIDE
2471   local PKGTYPE   local PKGTYPE
2472     local MAGE_TARGETS
2473     local SPLIT_PACKAGE_BASE
2474   local preinstall   local preinstall
2475   local postinstall   local postinstall
2476   local preremove   local preremove
# Line 2084  mage_install() Line 2517  mage_install()
2517   local count_current   local count_current
2518   local magefile   local magefile
2519   local src_install   local src_install
2520     local i
2521    
2522   # very basic getops   # very basic getops
2523   for i in $*   for i in $*
# Line 2157  mage_install() Line 2591  mage_install()
2591   echo B:${pbuild}   echo B:${pbuild}
2592   fi   fi
2593    
2594   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${MAGE_TARGETS} ]]
2595     then
2596     # basic svn compat
2597     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2598     then
2599     for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2600     do
2601     smage2file="${i}"
2602     done
2603     else
2604     smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2605     fi
2606    
2607     elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2608     then
2609     # basic svn compat
2610     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2611     then
2612     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2613     do
2614     smage2file="${i}"
2615     done
2616     else
2617     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2618     fi
2619    
2620     else
2621     # basic svn compat
2622     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2623     then
2624     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2625     do
2626     smage2file="${i}"
2627     done
2628     else
2629     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2630     fi
2631     fi
2632    
2633   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2634   then   then
2635     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2636   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2637   else   else
2638   echo   echo
# Line 2173  mage_install() Line 2646  mage_install()
2646   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2647   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2648   then   then
2649   # show a verbose message on src-install   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
  if [[ ${src_install} = true ]]  
  then  
  echo -ne "${COLBLUE} *** ${COLDEFAULT}"  
  echo -ne "merging files: "  
  echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  
  echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"  
  fi  
2650   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2651   fi   fi
2652    
# Line 2294  md5sum_packages() Line 2760  md5sum_packages()
2760   then   then
2761   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2762   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2763   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed"
2764   else   else
2765   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2766   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2437  mage_uninstall() Line 2903  mage_uninstall()
2903   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2904   echo -n "removing: "   echo -n "removing: "
2905   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2906   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2907    
2908   magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2909   source ${magefile}   source ${magefile}
2910    
2911   ## preremove scripts   ## preremove scripts
# Line 2507  mage_uninstall() Line 2973  mage_uninstall()
2973   unset -f postremove   unset -f postremove
2974  }  }
2975    
2976  show_etc_update_mesg() {  show_etc_update_mesg()
2977    {
2978   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
2979    
2980   echo   echo
# Line 2537  pkgsearch() Line 3004  pkgsearch()
3004   local all_installed   local all_installed
3005   local ipver   local ipver
3006   local ipbuild   local ipbuild
3007     local latest_available
3008     local depsfull
3009     local sdepsfull
3010     local deps
3011     local sdeps
3012     local dep
3013     local sign
3014    
3015   # only names no versions   # only names no versions
3016   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name *${string}*)"   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
3017   #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)"   #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
3018    
3019   # nothing found   # nothing found
3020   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
# Line 2554  pkgsearch() Line 3028  pkgsearch()
3028   # get highest version available   # get highest version available
3029   magefile=$(get_highest_magefile ${pcat} ${pname})   magefile=$(get_highest_magefile ${pcat} ${pname})
3030    
3031   # now get all needed infos to print a nice output   if [[ ! -z ${magefile} ]]
3032   pver="$(magename2pver ${magefile})"   then
3033   pbuild="$(magename2pbuild ${magefile})"   # now get all needed infos to print a nice output
3034   state="$(get_value_from_magefile STATE ${magefile})"   pver="$(magename2pver ${magefile})"
3035   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   pbuild="$(magename2pbuild ${magefile})"
3036   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3037     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3038     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3039    
3040     # all installed
3041     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3042     do
3043     ipver="$(magename2pver ${i})"
3044     ipbuild="$(magename2pbuild ${i})"
3045    
3046     if [[ -z ${all_installed} ]]
3047     then
3048     all_installed="${ipver}-${ipbuild}"
3049     else
3050     all_installed="${all_installed} ${ipver}-${ipbuild}"
3051     fi
3052     done
3053     [[ -z ${all_installed} ]] && all_installed="none"
3054    
3055     case ${state} in
3056     stable) state=${COLGREEN}"[s] ";;
3057     testing) state=${COLYELLOW}"[t] ";;
3058     unstable) state=${COLRED}"[u] ";;
3059     old) state=${COLGRAY}"[o] ";;
3060     esac
3061    
3062     latest_available="${pver}-${pbuild}"
3063     else
3064     # package is masked
3065     state="${COLRED}[m] "
3066     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
3067     fi
3068    
3069   # all installed   depsfull="$(get_value_from_magefile DEPEND ${magefile})"
3070   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
  do  
  ipver="$(magename2pver ${i})"  
  ipbuild="$(magename2pbuild ${i})"  
3071    
3072   if [[ -z ${all_installed} ]]   while read sign dep
3073   then   do
3074   all_installed="${ipver}-${ipbuild}"   case ${dep} in
3075   else   "") continue;;
3076   all_installed="${all_installed} ${ipver}-${ipbuild}"   esac
3077   fi  
3078   done   deps="${deps} $(basename ${dep%-*})"
3079   [[ -z ${all_installed} ]] && all_installed="none"   done << EOF
3080    ${depsfull}
3081    EOF
3082    
3083   case ${state} in   while read sign dep
3084   stable) state=${COLGREEN}"[s] ";;   do
3085   testing) state=${COLYELLOW}"[t] ";;   case ${dep} in
3086   unstable) state=${COLRED}"[u] ";;   "") continue;;
3087   old) state=${COLGRAY}"[o] ";;   esac
3088   esac  
3089     sdeps="${sdeps} $(basename ${dep%-*})"
3090     done << EOF
3091    ${sdepsfull}
3092    EOF
3093    
3094   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
3095   echo "      Latest available:   ${pver}-${pbuild}"   echo -e "      Latest available:   ${latest_available}"
3096   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3097   echo "      Description: ${description}"   echo "      Description: ${description}"
3098   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3099     echo "      Depends: ${deps}"
3100     echo "      SDepends: ${sdeps}"
3101   echo   echo
3102    
3103   unset pcat   unset pcat
# Line 2601  pkgsearch() Line 3111  pkgsearch()
3111   unset all_installed   unset all_installed
3112   unset ipver   unset ipver
3113   unset ipbuild   unset ipbuild
3114     unset depsfull
3115     unset sdepsfull
3116     unset deps
3117     unset sdeps
3118     unset dep
3119     unset sign
3120   done   done
3121  }  }
3122    
# Line 2625  export_inherits() Line 3141  export_inherits()
3141   shift   shift
3142   done   done
3143  }  }
3144    
3145    mlibdir()
3146    {
3147     local libdir=lib
3148     [[ ${ARCH} = x86_64 ]] && libdir=lib64
3149    
3150     echo "${libdir}"
3151    }
3152    
3153    ## blacklisted ${magefile}
3154    blacklisted()
3155    {
3156     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
3157    
3158     # compat
3159     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3160     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3161    
3162     # support both types for the moment
3163     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3164     then
3165     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3166     else
3167     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3168     fi
3169    
3170     # return 0 if the list not exist; nothin is masked
3171     [[ ! -f ${EXCLUDED} ]] && return 0
3172    
3173     local MAGEFILE="$1"
3174    
3175     local PCAT="$(magename2pcat ${MAGEFILE})"
3176     local PNAME="$(magename2pname ${MAGEFILE})"
3177     local PVER="$(magename2pver ${MAGEFILE})"
3178     local PBUILD="$(magename2pbuild ${MAGEFILE})"
3179    
3180     local EXPCAT EXPNAME EXPVER EXPBUILD
3181     while read EXPCAT EXPNAME EXPVER EXPBUILD
3182     do
3183     # ignore spaces and comments
3184             case "${EXPCAT}" in
3185                     \#*|"") continue ;;
3186             esac
3187    
3188     # exclude full pver
3189     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3190     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3191     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3192     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3193     then
3194     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3195     fi
3196    
3197     # exclude pcat/pname only
3198     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3199     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3200     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3201     then
3202     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3203     fi
3204     done << EOF
3205    $( cat ${EXCLUDED}; echo)
3206    EOF
3207    
3208     return 0
3209    }
3210    
3211    # need_busybox_support ${cmd}
3212    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3213    need_busybox_support()
3214    {
3215     local cmd
3216     cmd="$1"
3217    
3218     if [[ -x /bin/busybox ]]
3219     then
3220     if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]
3221     then
3222     # needs busybox support
3223     return 0
3224     fi
3225     fi
3226    
3227     # no busybox
3228     return 1
3229    }
3230    
3231    # busybox_filter_wget_options ${wget_opts}
3232    busybox_filter_wget_options()
3233    {
3234     local opts="$@"
3235     local i
3236     local fixed_opts
3237    
3238     if need_busybox_support wget
3239     then
3240     for i in ${opts}
3241     do
3242     # show only the allowed ones
3243     case ${i} in
3244     -c|--continue) fixed_opts+=" -c" ;;
3245     -s|--spider) fixed_opts+=" -s" ;;
3246     -q|--quiet) fixed_opts+=" -q" ;;
3247     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3248     --header) shift; fixed_opts+=" --header $1" ;;
3249     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3250     -P) shift; fixed_opts+=" -P $1" ;;
3251     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3252     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3253     # simply drop all other opts
3254     *) continue ;;
3255     esac
3256     done
3257    
3258     echo "${fixed_opts}"
3259     else
3260     echo "${opts}"
3261     fi
3262    }
3263    
3264    have_root_privileges()
3265    {
3266     local retval
3267    
3268     if [[ $(id -u) = 0 ]]
3269     then
3270     retval=0
3271     else
3272     retval=1
3273     fi
3274    
3275     return ${retval}
3276    }

Legend:
Removed from v.294  
changed lines
  Added in v.1549