Magellan Linux

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

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

revision 1271 by niro, Wed Apr 27 08:42:24 2011 UTC revision 1547 by niro, Tue Dec 27 09:58:03 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 219  install_files() Line 251  install_files()
251   "${user}" \   "${user}" \
252   "${group}" \   "${group}" \
253   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
254   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
255   "${md5sum}"   "${md5sum}"
256   ;;   ;;
257    
# Line 246  install_files() Line 278  install_files()
278   "${user}" \   "${user}" \
279   "${group}" \   "${group}" \
280   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
281   "${dest_protected}")" \   "${dest_protected}")" \
282   "${md5sum}"   "${md5sum}"
283    
284   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
# Line 263  install_files() Line 295  install_files()
295   echo -en "${COLDEFAULT}"   echo -en "${COLDEFAULT}"
296   echo " === FILE: ${MROOT}${pathto}"   echo " === FILE: ${MROOT}${pathto}"
297   fi   fi
298   # simply do nothing here   # simply do nothing here - only fix mtime
299     fix_descriptor ${pkgname}/.files \
300     "${pathto}" \
301     "${posix}" \
302     "${user}" \
303     "${group}" \
304     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
305     "${MROOT}${pathto}")" \
306     "${md5sum}"
307   ;;   ;;
308   esac   esac
309   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
# Line 467  build_doinstall() Line 507  build_doinstall()
507    
508   # sanity checks; abort if not given   # sanity checks; abort if not given
509   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
510    
511   # this is only a wrapper   # this is only a wrapper
512    
513   # NOTE:   # NOTE:
# Line 1255  fetch_packages() Line 1295  fetch_packages()
1295   local opt   local opt
1296   local count_current   local count_current
1297   local count_total   local count_total
1298     local wget_opts
1299    
1300   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1301    
1302     # filter wget command if busybox was found
1303     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1304    
1305   # get count of total packages   # get count of total packages
1306   declare -i count_current=0   declare -i count_current=0
1307   declare -i count_total=0   declare -i count_total=0
# Line 1303  fetch_packages() Line 1347  fetch_packages()
1347   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1348   [[ ${VERBOSE} = off ]] && opt="--quiet"   [[ ${VERBOSE} = off ]] && opt="--quiet"
1349   wget \   wget \
1350   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1351   --directory-prefix=${PKGDIR} \   --directory-prefix=${PKGDIR} \
1352   ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}   ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}
1353   if [[ $? = 0 ]]   if [[ $? = 0 ]]
# Line 1344  syncmage() Line 1388  syncmage()
1388   done   done
1389    
1390   # clean up backup files (foo~)   # clean up backup files (foo~)
1391   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1392    
1393   # check if a newer mage version is available   # check if a newer mage version is available
1394   is_newer_mage_version_available   is_newer_mage_version_available
# Line 1357  syncmage_tarball() Line 1401  syncmage_tarball()
1401   local temp="$(mktemp -d)"   local temp="$(mktemp -d)"
1402   local mirr mymirr   local mirr mymirr
1403   local opt   local opt
1404     local tar_opts
1405     local wget_opts
1406    
1407   # try to get the md5 marked as latest on the server   # try to get the md5 marked as latest on the server
1408   latest_md5="mage-latest.md5"   latest_md5="mage-latest.md5"
# Line 1364  syncmage_tarball() Line 1410  syncmage_tarball()
1410   # try to get the tarball marked as latest on the server   # try to get the tarball marked as latest on the server
1411   latest_tarball="mage-latest.tar.bz2"   latest_tarball="mage-latest.tar.bz2"
1412    
1413     # filter wget command if busybox was found
1414     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1415    
1416   for mirr in ${MIRRORS}   for mirr in ${MIRRORS}
1417   do   do
1418   # path without distribution   # path without distribution
# Line 1373  syncmage_tarball() Line 1422  syncmage_tarball()
1422   echo "fetching latest md5 from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
1423   [[ ${VERBOSE} = off ]] && opt="--quiet"   [[ ${VERBOSE} = off ]] && opt="--quiet"
1424   wget \   wget \
1425   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1426   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1427   ${opt} ${mymirr}/rsync/tarballs/${latest_md5}   ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1428    
1429   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1430   echo "fetching latest tarball from ${mymirr} ..."   echo "fetching latest tarball from ${mymirr} ..."
1431   wget \   wget \
1432   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1433   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1434   ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}   ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1435   if [[ $? = 0 ]]   if [[ $? = 0 ]]
# Line 1400  syncmage_tarball() Line 1449  syncmage_tarball()
1449   else   else
1450   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1451   echo -n "checking md5sum... "   echo -n "checking md5sum... "
1452   ( cd ${temp}; md5sum --check ${latest_md5} ) || die "md5 for ${latest_tarball} failed"   ( cd ${temp}; md5sum -c ${latest_md5} ) || die "md5 for ${latest_tarball} failed"
1453   fi   fi
1454    
1455   if [[ -d ${MAGEDIR} ]]   if [[ -d ${MAGEDIR} ]]
# Line 1410  syncmage_tarball() Line 1459  syncmage_tarball()
1459   rm -rf ${MAGEDIR}   rm -rf ${MAGEDIR}
1460   fi   fi
1461    
1462     if need_busybox_support tar
1463     then
1464     tar_opts="xjf"
1465     else
1466     tar_opts="xjmf"
1467     fi
1468    
1469   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1470   echo "updating mage-tree from tarball ..."   echo "updating mage-tree from tarball ..."
1471   # unpack in dirname of MAGEDIR, as the tarball has already the mage   # unpack in dirname of MAGEDIR, as the tarball has already the mage
1472   tar xjmf ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"   tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1473    
1474   if [[ -d ${temp} ]]   if [[ -d ${temp} ]]
1475   then   then
# Line 1542  get_highest_magefile() Line 1598  get_highest_magefile()
1598   local magefile   local magefile
1599    
1600   # do not list the content of a directory, only the name (-d)   # do not list the content of a directory, only the name (-d)
1601   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)
1602   do   do
1603   [[ -z ${magefile} ]] && continue   [[ -z ${magefile} ]] && continue
1604   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
# Line 2429  mage_install() Line 2485  mage_install()
2485   if [[ -n ${MAGE_TARGETS} ]]   if [[ -n ${MAGE_TARGETS} ]]
2486   then   then
2487   # basic svn compat   # basic svn compat
2488   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2489   then   then
2490   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
2491   do   do
2492   smage2file="${i}"   smage2file="${i}"
2493   done   done
# Line 2442  mage_install() Line 2498  mage_install()
2498   elif [[ -n ${SPLIT_PACKAGE_BASE} ]]   elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2499   then   then
2500   # basic svn compat   # basic svn compat
2501   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2502   then   then
2503   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
2504   do   do
2505   smage2file="${i}"   smage2file="${i}"
2506   done   done
# Line 2454  mage_install() Line 2510  mage_install()
2510    
2511   else   else
2512   # basic svn compat   # basic svn compat
2513   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2514   then   then
2515   for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2516   do   do
2517   smage2file="${i}"   smage2file="${i}"
2518   done   done
# Line 2595  md5sum_packages() Line 2651  md5sum_packages()
2651   then   then
2652   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2653   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2654   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed"
2655   else   else
2656   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2657   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 3043  EOF Line 3099  EOF
3099   return 0   return 0
3100  }  }
3101    
3102    # need_busybox_support ${cmd}
3103    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3104    need_busybox_support()
3105    {
3106     local cmd
3107     cmd="$1"
3108    
3109     if [[ -x /bin/busybox ]]
3110     then
3111     if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]
3112     then
3113     # needs busybox support
3114     return 0
3115     fi
3116     fi
3117    
3118     # no busybox
3119     return 1
3120    }
3121    
3122    # busybox_filter_wget_options ${wget_opts}
3123    busybox_filter_wget_options()
3124    {
3125     local opts="$@"
3126     local i
3127     local fixed_opts
3128    
3129     if need_busybox_support wget
3130     then
3131     for i in ${opts}
3132     do
3133     # show only the allowed ones
3134     case ${i} in
3135     -c|--continue) fixed_opts+=" -c" ;;
3136     -s|--spider) fixed_opts+=" -s" ;;
3137     -q|--quiet) fixed_opts+=" -q" ;;
3138     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3139     --header) shift; fixed_opts+=" --header $1" ;;
3140     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3141     -P) shift; fixed_opts+=" -P $1" ;;
3142     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3143     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3144     # simply drop all other opts
3145     *) continue ;;
3146     esac
3147     done
3148    
3149     echo "${fixed_opts}"
3150     else
3151     echo "${opts}"
3152     fi
3153    }
3154    
3155    have_root_privileges()
3156    {
3157     local retval
3158    
3159     if [[ $(id -u) = 0 ]]
3160     then
3161     retval=0
3162     else
3163     retval=1
3164     fi
3165    
3166     return ${retval}
3167    }

Legend:
Removed from v.1271  
changed lines
  Added in v.1547