Magellan Linux

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

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

revision 1209 by niro, Fri Jan 28 20:37:27 2011 UTC revision 1548 by niro, Tue Dec 27 10:00:34 2011 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 23  unpack_packages() Line 46  unpack_packages()
46   local pkgtype   local pkgtype
47   local count_current   local count_current
48   local count_total   local count_total
49     local tar_opts
50    
51   # get count of total packages   # get count of total packages
52   declare -i count_current=0   declare -i count_current=0
# Line 54  unpack_packages() Line 78  unpack_packages()
78   continue   continue
79   fi   fi
80    
81     # busybox?
82     if need_busybox_support tar
83     then
84     tar_opts="xjf"
85     else
86     tar_opts="xjmf"
87     fi
88    
89   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "
90   tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"   tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"
91   done   done
92    
93   # add a crlf for a better view   # add a crlf for a better view
# Line 132  install_directories() Line 164  install_directories()
164   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
165   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
166    
   
167   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
168   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
169    
# Line 219  install_files() Line 250  install_files()
250   "${user}" \   "${user}" \
251   "${group}" \   "${group}" \
252   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
253   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
254   "${md5sum}"   "${md5sum}"
255   ;;   ;;
256    
# Line 246  install_files() Line 277  install_files()
277   "${user}" \   "${user}" \
278   "${group}" \   "${group}" \
279   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
280   "${dest_protected}")" \   "${dest_protected}")" \
281   "${md5sum}"   "${md5sum}"
282    
283   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
# Line 263  install_files() Line 294  install_files()
294   echo -en "${COLDEFAULT}"   echo -en "${COLDEFAULT}"
295   echo " === FILE: ${MROOT}${pathto}"   echo " === FILE: ${MROOT}${pathto}"
296   fi   fi
297   # simply do nothing here   # simply do nothing here - only fix mtime
298     fix_descriptor ${pkgname}/.files \
299     "${pathto}" \
300     "${posix}" \
301     "${user}" \
302     "${group}" \
303     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
304     "${MROOT}${pathto}")" \
305     "${md5sum}"
306   ;;   ;;
307   esac   esac
308   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
# Line 354  install_blockdevices() Line 393  install_blockdevices()
393   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
394   IFS=§   IFS=§
395    
396   while read pathto posix user group   while read pathto posix major minor user group
397   do   do
398   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
399   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
400    
401   mkfifo -m "${posix}" "${MROOT}${pathto}"   mknod -m "${posix}" "${MROOT}${pathto}"
402   chown "${user}:${group}" "${MROOT}${pathto}"   # make it optional atm !!
403     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
404     then
405     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
406     fi
407   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
408    
409   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 399  install_characterdevices() Line 442  install_characterdevices()
442   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
443   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
444    
445   mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor}   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
446   chown "${user}:${group}" "${MROOT}${pathto}"  
447     # make it optional atm !!
448     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
449     then
450     chown "${user}:${group}" "${MROOT}${pathto}"
451     fi
452   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
453    
454   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 426  install_fifos() Line 474  install_fifos()
474   # check needed global vars   # check needed global vars
475   [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."   [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
476    
477   [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"   # make it optional atm !!
478     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
479     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
480    
481   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
482   IFS=§   IFS=§
# Line 456  build_doinstall() Line 506  build_doinstall()
506    
507   # sanity checks; abort if not given   # sanity checks; abort if not given
508   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
509    
510   # this is only a wrapper   # this is only a wrapper
511    
512   # NOTE:   # NOTE:
# Line 553  install_database_entry() Line 603  install_database_entry()
603   local i   local i
604   for i in .char .dirs .files .pipes .symlinks .fifo   for i in .char .dirs .files .pipes .symlinks .fifo
605   do   do
606   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
607   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
608     then
609     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
610     fi
611   done   done
612   ;;   ;;
613   esac   esac
# Line 1077  remove_fifos() Line 1130  remove_fifos()
1130   # check needed global vars   # check needed global vars
1131   [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."   [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1132    
1133   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"   # make it optional atm !!
1134     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1135     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1136    
1137   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1138   IFS=§   IFS=§
# Line 1239  fetch_packages() Line 1294  fetch_packages()
1294   local opt   local opt
1295   local count_current   local count_current
1296   local count_total   local count_total
1297     local wget_opts
1298    
1299   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1300    
1301     # filter wget command if busybox was found
1302     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1303    
1304   # get count of total packages   # get count of total packages
1305   declare -i count_current=0   declare -i count_current=0
1306   declare -i count_total=0   declare -i count_total=0
# Line 1287  fetch_packages() Line 1346  fetch_packages()
1346   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1347   [[ ${VERBOSE} = off ]] && opt="--quiet"   [[ ${VERBOSE} = off ]] && opt="--quiet"
1348   wget \   wget \
1349   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1350   --directory-prefix=${PKGDIR} \   --directory-prefix=${PKGDIR} \
1351   ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}   ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}
1352   if [[ $? = 0 ]]   if [[ $? = 0 ]]
# Line 1328  syncmage() Line 1387  syncmage()
1387   done   done
1388    
1389   # clean up backup files (foo~)   # clean up backup files (foo~)
1390   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1391    
1392   # check if a newer mage version is available   # check if a newer mage version is available
1393   is_newer_mage_version_available   is_newer_mage_version_available
# Line 1341  syncmage_tarball() Line 1400  syncmage_tarball()
1400   local temp="$(mktemp -d)"   local temp="$(mktemp -d)"
1401   local mirr mymirr   local mirr mymirr
1402   local opt   local opt
1403     local tar_opts
1404     local wget_opts
1405    
1406   # try to get the md5 marked as latest on the server   # try to get the md5 marked as latest on the server
1407   latest_md5="mage-latest.md5"   latest_md5="mage-latest.md5"
# Line 1348  syncmage_tarball() Line 1409  syncmage_tarball()
1409   # try to get the tarball marked as latest on the server   # try to get the tarball marked as latest on the server
1410   latest_tarball="mage-latest.tar.bz2"   latest_tarball="mage-latest.tar.bz2"
1411    
1412     # filter wget command if busybox was found
1413     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1414    
1415   for mirr in ${MIRRORS}   for mirr in ${MIRRORS}
1416   do   do
1417   # path without distribution   # path without distribution
# Line 1357  syncmage_tarball() Line 1421  syncmage_tarball()
1421   echo "fetching latest md5 from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
1422   [[ ${VERBOSE} = off ]] && opt="--quiet"   [[ ${VERBOSE} = off ]] && opt="--quiet"
1423   wget \   wget \
1424   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1425   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1426   ${opt} ${mymirr}/rsync/tarballs/${latest_md5}   ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1427    
1428   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1429   echo "fetching latest tarball from ${mymirr} ..."   echo "fetching latest tarball from ${mymirr} ..."
1430   wget \   wget \
1431   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1432   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1433   ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}   ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1434   if [[ $? = 0 ]]   if [[ $? = 0 ]]
# Line 1384  syncmage_tarball() Line 1448  syncmage_tarball()
1448   else   else
1449   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1450   echo -n "checking md5sum... "   echo -n "checking md5sum... "
1451   ( cd ${temp}; md5sum --check ${latest_md5} ) || die "md5 for ${latest_tarball} failed"   ( cd ${temp}; md5sum -c ${latest_md5} ) || die "md5 for ${latest_tarball} failed"
1452   fi   fi
1453    
1454   if [[ -d ${MAGEDIR} ]]   if [[ -d ${MAGEDIR} ]]
# Line 1394  syncmage_tarball() Line 1458  syncmage_tarball()
1458   rm -rf ${MAGEDIR}   rm -rf ${MAGEDIR}
1459   fi   fi
1460    
1461     if need_busybox_support tar
1462     then
1463     tar_opts="xjf"
1464     else
1465     tar_opts="xjmf"
1466     fi
1467    
1468   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1469   echo "updating mage-tree from tarball ..."   echo "updating mage-tree from tarball ..."
1470   # unpack in dirname of MAGEDIR, as the tarball has already the mage   # unpack in dirname of MAGEDIR, as the tarball has already the mage
1471   tar xjmf ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"   tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1472    
1473   if [[ -d ${temp} ]]   if [[ -d ${temp} ]]
1474   then   then
# Line 1443  xtitleclean() Line 1514  xtitleclean()
1514  }  }
1515    
1516    
1517  # cuts full pathnames or versioniezed names down to basename  # cuts full pathnames or versionized names down to basename
1518  choppkgname()  choppkgname()
1519  {  {
1520   #we want this only if full name was used   #we want this only if full name was used
# Line 1526  get_highest_magefile() Line 1597  get_highest_magefile()
1597   local magefile   local magefile
1598    
1599   # do not list the content of a directory, only the name (-d)   # do not list the content of a directory, only the name (-d)
1600   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)
1601   do   do
1602   [[ -z ${magefile} ]] && continue   [[ -z ${magefile} ]] && continue
1603   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
# Line 1539  get_highest_magefile() Line 1610  get_highest_magefile()
1610   fi   fi
1611   done   done
1612    
 # 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  
   
1613   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1614   return 0   return 0
1615  }  }
# Line 2413  mage_install() Line 2462  mage_install()
2462   if [[ -n ${MAGE_TARGETS} ]]   if [[ -n ${MAGE_TARGETS} ]]
2463   then   then
2464   # basic svn compat   # basic svn compat
2465   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2466   then   then
2467   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
2468   do   do
2469   smage2file="${i}"   smage2file="${i}"
2470   done   done
# Line 2426  mage_install() Line 2475  mage_install()
2475   elif [[ -n ${SPLIT_PACKAGE_BASE} ]]   elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2476   then   then
2477   # basic svn compat   # basic svn compat
2478   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2479   then   then
2480   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
2481   do   do
2482   smage2file="${i}"   smage2file="${i}"
2483   done   done
# Line 2438  mage_install() Line 2487  mage_install()
2487    
2488   else   else
2489   # basic svn compat   # basic svn compat
2490   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2491   then   then
2492   for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2493   do   do
2494   smage2file="${i}"   smage2file="${i}"
2495   done   done
# Line 2579  md5sum_packages() Line 2628  md5sum_packages()
2628   then   then
2629   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2630   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2631   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed"
2632   else   else
2633   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2634   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 3027  EOF Line 3076  EOF
3076   return 0   return 0
3077  }  }
3078    
3079    # need_busybox_support ${cmd}
3080    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3081    need_busybox_support()
3082    {
3083     local cmd
3084     cmd="$1"
3085    
3086     if [[ -x /bin/busybox ]]
3087     then
3088     if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]
3089     then
3090     # needs busybox support
3091     return 0
3092     fi
3093     fi
3094    
3095     # no busybox
3096     return 1
3097    }
3098    
3099    # busybox_filter_wget_options ${wget_opts}
3100    busybox_filter_wget_options()
3101    {
3102     local opts="$@"
3103     local i
3104     local fixed_opts
3105    
3106     if need_busybox_support wget
3107     then
3108     for i in ${opts}
3109     do
3110     # show only the allowed ones
3111     case ${i} in
3112     -c|--continue) fixed_opts+=" -c" ;;
3113     -s|--spider) fixed_opts+=" -s" ;;
3114     -q|--quiet) fixed_opts+=" -q" ;;
3115     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3116     --header) shift; fixed_opts+=" --header $1" ;;
3117     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3118     -P) shift; fixed_opts+=" -P $1" ;;
3119     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3120     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3121     # simply drop all other opts
3122     *) continue ;;
3123     esac
3124     done
3125    
3126     echo "${fixed_opts}"
3127     else
3128     echo "${opts}"
3129     fi
3130    }
3131    
3132    have_root_privileges()
3133    {
3134     local retval
3135    
3136     if [[ $(id -u) = 0 ]]
3137     then
3138     retval=0
3139     else
3140     retval=1
3141     fi
3142    
3143     return ${retval}
3144    }

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