--- trunk/mage/usr/lib/mage/mage4.functions.sh 2011/01/28 20:37:27 1209 +++ trunk/mage/usr/lib/mage/mage4.functions.sh 2011/12/27 10:00:34 1548 @@ -2,6 +2,29 @@ # Magellan Linux Installer Functions (mage.functions.sh) # $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 $ +COLRED="\033[1;6m\033[31m" +COLGREEN="\033[1;6m\033[32m" +COLYELLOW="\033[1;6m\033[33m" +COLBLUE="\033[1;6m\033[34m" +COLMAGENTA="\033[1;6m\033[35m" +COLWHITE="\033[1;6m\033[37m" +COLGRAY="\033[0;6m\033[37m" +COLBOLD="\033[1m" +COLDEFAULT="\033[0m" + +if [[ ${NOCOLORS} = true ]] +then + COLRED="" + COLGREEN="" + COLYELLOW="" + COLBLUE="" + COLMAGENTA="" + COLWHITE="" + COLGRAY="" + COLBOLD="" + COLDEFAULT="" +fi + mage_setup() { [ ! -d ${MROOT}${INSTALLDB} ] && \ @@ -23,6 +46,7 @@ local pkgtype local count_current local count_total + local tar_opts # get count of total packages declare -i count_current=0 @@ -54,8 +78,16 @@ continue fi + # busybox? + if need_busybox_support tar + then + tar_opts="xjf" + else + tar_opts="xjmf" + fi + echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... " - tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}" + tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}" done # add a crlf for a better view @@ -132,7 +164,6 @@ [ -z "${pathto}" ] && continue [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR: ${MROOT}${pathto}" - # monitors /etc/env.d -> env-rebuild [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true @@ -219,7 +250,7 @@ "${user}" \ "${group}" \ "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ - "${MROOT}${pathto}")" \ + "${MROOT}${pathto}")" \ "${md5sum}" ;; @@ -246,7 +277,7 @@ "${user}" \ "${group}" \ "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ - "${dest_protected}")" \ + "${dest_protected}")" \ "${md5sum}" # update global MAGE_PROTECT_COUNTER @@ -263,7 +294,15 @@ echo -en "${COLDEFAULT}" echo " === FILE: ${MROOT}${pathto}" fi - # simply do nothing here + # simply do nothing here - only fix mtime + fix_descriptor ${pkgname}/.files \ + "${pathto}" \ + "${posix}" \ + "${user}" \ + "${group}" \ + "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ + "${MROOT}${pathto}")" \ + "${md5sum}" ;; esac done < ${BUILDDIR}/${pkgname}/.files @@ -354,13 +393,17 @@ # sets fieldseperator to "§" instead of " " IFS=§ - while read pathto posix user group + while read pathto posix major minor user group do [ -z "${pathto}" ] && continue [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}" - mkfifo -m "${posix}" "${MROOT}${pathto}" - chown "${user}:${group}" "${MROOT}${pathto}" + mknod -m "${posix}" "${MROOT}${pathto}" + # make it optional atm !! + if [[ ! -z ${user} ]] && [[ ! -z ${group} ]] + then + chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}" + fi done < ${BUILDDIR}/${pkgname}/.pipes # very important: unsetting the '§' fieldseperator @@ -399,8 +442,13 @@ [ -z "${pathto}" ] && continue [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}" - mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor} - chown "${user}:${group}" "${MROOT}${pathto}" + mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}" + + # make it optional atm !! + if [[ ! -z ${user} ]] && [[ ! -z ${group} ]] + then + chown "${user}:${group}" "${MROOT}${pathto}" + fi done < ${BUILDDIR}/${pkgname}/.char # very important: unsetting the '§' fieldseperator @@ -426,7 +474,9 @@ # check needed global vars [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set." - [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found" + # make it optional atm !! + #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found" + [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return # sets fieldseperator to "§" instead of " " IFS=§ @@ -456,7 +506,7 @@ # sanity checks; abort if not given [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given." - + # this is only a wrapper # NOTE: @@ -553,8 +603,11 @@ local i for i in .char .dirs .files .pipes .symlinks .fifo do - install -m 0644 ${BUILDDIR}/${pkgname}/${i} \ - ${dbrecorddir}/${i} + # make .fifo optional atm + if [[ -f ${BUILDDIR}/${pkgname}/${i} ]] + then + install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i} + fi done ;; esac @@ -1077,7 +1130,9 @@ # check needed global vars [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set." - [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found" + # make it optional atm !! + #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found" + [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return # sets fieldseperator to "§" instead of " " IFS=§ @@ -1239,9 +1294,13 @@ local opt local count_current local count_total + local wget_opts [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}." + # filter wget command if busybox was found + wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})" + # get count of total packages declare -i count_current=0 declare -i count_total=0 @@ -1287,7 +1346,7 @@ echo -e " fetching (${count_current}/${count_total}): ${pkg} ... " [[ ${VERBOSE} = off ]] && opt="--quiet" wget \ - ${WGET_FETCH_OPTIONS} \ + ${wget_opts} \ --directory-prefix=${PKGDIR} \ ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg} if [[ $? = 0 ]] @@ -1328,7 +1387,7 @@ done # clean up backup files (foo~) - find ${MAGEDIR} -name *~ -exec rm '{}' ';' + find ${MAGEDIR} -name \*~ -exec rm '{}' ';' # check if a newer mage version is available is_newer_mage_version_available @@ -1341,6 +1400,8 @@ local temp="$(mktemp -d)" local mirr mymirr local opt + local tar_opts + local wget_opts # try to get the md5 marked as latest on the server latest_md5="mage-latest.md5" @@ -1348,6 +1409,9 @@ # try to get the tarball marked as latest on the server latest_tarball="mage-latest.tar.bz2" + # filter wget command if busybox was found + wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})" + for mirr in ${MIRRORS} do # path without distribution @@ -1357,14 +1421,14 @@ echo "fetching latest md5 from ${mymirr} ..." [[ ${VERBOSE} = off ]] && opt="--quiet" wget \ - ${WGET_FETCH_OPTIONS} \ + ${wget_opts} \ --directory-prefix=${temp} \ ${opt} ${mymirr}/rsync/tarballs/${latest_md5} echo -ne "${COLBLUE} --- ${COLDEFAULT}" echo "fetching latest tarball from ${mymirr} ..." wget \ - ${WGET_FETCH_OPTIONS} \ + ${wget_opts} \ --directory-prefix=${temp} \ ${opt} ${mymirr}/rsync/tarballs/${latest_tarball} if [[ $? = 0 ]] @@ -1384,7 +1448,7 @@ else echo -ne "${COLBLUE} --- ${COLDEFAULT}" echo -n "checking md5sum... " - ( cd ${temp}; md5sum --check ${latest_md5} ) || die "md5 for ${latest_tarball} failed" + ( cd ${temp}; md5sum -c ${latest_md5} ) || die "md5 for ${latest_tarball} failed" fi if [[ -d ${MAGEDIR} ]] @@ -1394,10 +1458,17 @@ rm -rf ${MAGEDIR} fi + if need_busybox_support tar + then + tar_opts="xjf" + else + tar_opts="xjmf" + fi + echo -ne "${COLBLUE} --- ${COLDEFAULT}" echo "updating mage-tree from tarball ..." # unpack in dirname of MAGEDIR, as the tarball has already the mage - tar xjmf ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball" + tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball" if [[ -d ${temp} ]] then @@ -1443,7 +1514,7 @@ } -# cuts full pathnames or versioniezed names down to basename +# cuts full pathnames or versionized names down to basename choppkgname() { #we want this only if full name was used @@ -1526,7 +1597,7 @@ local magefile # do not list the content of a directory, only the name (-d) - 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) do [[ -z ${magefile} ]] && continue # we exclude subdirs (for stuff like a md5sum dir) @@ -1539,28 +1610,6 @@ fi done -# do not so anything -# # stop here if HIGHEST_MAGEFILE is zero -# # this package must be unstable or old -# if [ -z "${HIGHEST_MAGEFILE}" ] -# then -# echo -# echo -n "All packages named " -# echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT} -# echo -n " are marked " -# echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT} -# echo "." -# echo "You need to declare USE_UNSTABLE=true to install this." -# echo -# echo "Example:" -# echo " USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}" -# echo -# echo "Be warned that these packages are not stable and may cause serious problems." -# echo "You should know what you are doing, so don't complain about any damage." -# echo -# return 1 -# fi - echo "${HIGHEST_MAGEFILE}" return 0 } @@ -2413,9 +2462,9 @@ if [[ -n ${MAGE_TARGETS} ]] then # basic svn compat - if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] + if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] then - 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 do smage2file="${i}" done @@ -2426,9 +2475,9 @@ elif [[ -n ${SPLIT_PACKAGE_BASE} ]] then # basic svn compat - if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] + if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] then - 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 do smage2file="${i}" done @@ -2438,9 +2487,9 @@ else # basic svn compat - if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] + if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] then - for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2 + for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2 do smage2file="${i}" done @@ -2579,7 +2628,7 @@ then echo -ne "${COLBLUE} *** ${COLDEFAULT}" echo -ne "checking md5sum (${count_current}/${count_total}): " - ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed" + ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed" else echo -ne "${COLBLUE} --- ${COLDEFAULT}" echo -e "!! no md5sum file found for ${pkgfile} :(" @@ -3027,3 +3076,69 @@ return 0 } +# need_busybox_support ${cmd} +# return 0 (no error = needs busybox support) or return 1 (error = no busybox support required) +need_busybox_support() +{ + local cmd + cmd="$1" + + if [[ -x /bin/busybox ]] + then + if [[ $(readlink $(which ${cmd})) = /bin/busybox ]] + then + # needs busybox support + return 0 + fi + fi + + # no busybox + return 1 +} + +# busybox_filter_wget_options ${wget_opts} +busybox_filter_wget_options() +{ + local opts="$@" + local i + local fixed_opts + + if need_busybox_support wget + then + for i in ${opts} + do + # show only the allowed ones + case ${i} in + -c|--continue) fixed_opts+=" -c" ;; + -s|--spider) fixed_opts+=" -s" ;; + -q|--quiet) fixed_opts+=" -q" ;; + -O|--output-document) shift; fixed_opts+=" -O $1" ;; + --header) shift; fixed_opts+=" --header $1" ;; + -Y|--proxy) shift; fixed_opts+=" -Y $1" ;; + -P) shift; fixed_opts+=" -P $1" ;; + --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;; + -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;; + # simply drop all other opts + *) continue ;; + esac + done + + echo "${fixed_opts}" + else + echo "${opts}" + fi +} + +have_root_privileges() +{ + local retval + + if [[ $(id -u) = 0 ]] + then + retval=0 + else + retval=1 + fi + + return ${retval} +}