--- trunk/mage/usr/lib/mage/mage4.functions.sh 2010/06/28 18:08:15 1084 +++ trunk/mage/usr/lib/mage/mage4.functions.sh 2011/04/27 09:45:07 1273 @@ -23,6 +23,7 @@ local pkgtype local count_current local count_total + local tar_opts # get count of total packages declare -i count_current=0 @@ -54,8 +55,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 @@ -339,6 +348,8 @@ local pkgname="$1" local pathto local posix + local user + local group local IFS # sanity checks; abort if not given @@ -352,12 +363,17 @@ # sets fieldseperator to "§" instead of " " IFS=§ - while read pathto posix + 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" + 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 @@ -376,6 +392,8 @@ local posix local major local minor + local user + local group local IFS # sanity checks; abort if not given @@ -389,23 +407,68 @@ # sets fieldseperator to "§" instead of " " IFS=§ - while read pathto posix major minor + while read pathto posix major minor user group do [ -z "${pathto}" ] && continue [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}" - mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor} + 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 IFS=$'\n' } +################################################### +# function install_fifos # +# install_fifos $PKGNAME # +################################################### +install_fifos() +{ + local pkgname="$1" + local pathto + local posix + local user + local group + local IFS + + # sanity checks; abort if not given + [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given." + + # check needed global vars + [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set." + + # 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=§ + + while read pathto posix user group + do + [ -z "${pathto}" ] && continue + [[ ${VERBOSE} = on ]] && echo -e "\t>>> FIFO: ${MROOT}${pathto}" + + mkfifo -m "${posix}" "${MROOT}${pathto}" + chown "${user}:${group}" "${MROOT}${pathto}" + done < ${BUILDDIR}/${pkgname}/.fifo + + # very important: unsetting the '§' fieldseperator + IFS=$'\n' +} + ################################################### # function build_doinstall # # build_doinstall $PKGNAME # -# NOTE: this is an wrapper do install packages # +# NOTE: this is an wrapper to install packages # ################################################### build_doinstall() { @@ -428,6 +491,7 @@ install_symlinks ${pkgname} || die "install symlinks ${pkgname}" install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}" install_characterdevices ${pkgname} || die "install chardevices ${pkgname}" + install_fifos ${pkgname} || die "install fifos ${pkgname}" } @@ -489,7 +553,7 @@ # create fake file descriptors # used by virtual and source packages - for i in .dirs .symlinks .files .pipes .char + for i in .dirs .symlinks .files .pipes .char .fifo do touch ${dbrecorddir}/${i} done @@ -507,10 +571,13 @@ # normal packages needs these files local i - for i in .char .dirs .files .pipes .symlinks + 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 @@ -785,10 +852,10 @@ done # sanity checks; abort if not given - [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." - [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." - [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." - [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." + [ -z "${pcat}" ] && die "remove_files() \$pcat not given." + [ -z "${pname}" ] && die "remove_files() \$pname not given." + [ -z "${pver}" ] && die "remove_files() \$pver not given." + [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given." pfull="${pcat}/${pname}-${pver}-${pbuild}" # check needed global vars @@ -879,6 +946,8 @@ { local pathto local posix + local user + local group local IFS local pcat local pname @@ -902,10 +971,10 @@ done # sanity checks; abort if not given - [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." - [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." - [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." - [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." + [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given." + [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given." + [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given." + [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given." pfull="${pcat}/${pname}-${pver}-${pbuild}" # check needed global vars @@ -916,7 +985,7 @@ # sets fieldseperator to "§" instead of " " IFS=§ - while read pathto posix + while read pathto posix user group do [ -z "${pathto}" ] && continue @@ -937,6 +1006,8 @@ { local pathto local posix + local user + local group local IFS local pcat local pname @@ -960,10 +1031,10 @@ done # sanity checks; abort if not given - [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." - [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." - [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." - [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." + [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given." + [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given." + [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given." + [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given." pfull="${pcat}/${pname}-${pver}-${pbuild}" # check needed global vars @@ -974,7 +1045,7 @@ # sets fieldseperator to "§" instead of " " IFS=§ - while read pathto posix + while read pathto posix user group do [ -z "${pathto}" ] && continue @@ -988,6 +1059,68 @@ ################################################### +# function remove_fifos # +# remove_fifos $PKGNAME # +################################################### +remove_fifos() +{ + local pathto + local posix + local user + local group + local IFS + local pcat + local pname + local pver + local pbuild + local i + local pfull + + IFS=$'\n' + + # very basic getops + for i in $* + do + case $1 in + --pcat|-c) shift; pcat="$1" ;; + --pname|-n) shift; pname="$1" ;; + --pver|-v) shift; pver="$1" ;; + --pbuild|-b) shift; pbuild="$1" ;; + esac + shift + done + + # sanity checks; abort if not given + [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given." + [ -z "${pname}" ] && die "remove_fifos() \$pname not given." + [ -z "${pver}" ] && die "remove_fifos() \$pver not given." + [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given." + pfull="${pcat}/${pname}-${pver}-${pbuild}" + + # check needed global vars + [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set." + + # 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=§ + + while read pathto posix user group + do + [ -z "${pathto}" ] && continue + + [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}" + rm "${MROOT}${pathto}" + done < ${MROOT}${INSTALLDB}/${pfull}/.fifo + + # very important: unsetting the '§' fieldseperator + IFS=$'\n' +} + + +################################################### # function remove_direcories # # remove_direcories $PKGNAME # ################################################### @@ -1018,10 +1151,10 @@ done # sanity checks; abort if not given - [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." - [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." - [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." - [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." + [ -z "${pcat}" ] && die "remove_directories() \$pcat not given." + [ -z "${pname}" ] && die "remove_directories() \$pname not given." + [ -z "${pver}" ] && die "remove_directories() \$pver not given." + [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given." pfull="${pcat}/${pname}-${pver}-${pbuild}" # check needed global vars @@ -1075,7 +1208,7 @@ ################################################### # function build_douninstall # # build_douninstall $PKGNAME # -# NOTE: this is an wrapper do remove packages # +# NOTE: this is an wrapper to remove packages # ################################################### build_douninstall() { @@ -1109,7 +1242,7 @@ # !! we use § as field seperator !! # doing so prevent us to get errors by filenames with spaces - for i in symlinks files blockdevices characterdevices directories + for i in symlinks files blockdevices characterdevices directories fifos do remove_${i} \ --pcat "${pcat}" \ @@ -1131,9 +1264,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 @@ -1179,10 +1316,7 @@ echo -e " fetching (${count_current}/${count_total}): ${pkg} ... " [[ ${VERBOSE} = off ]] && opt="--quiet" wget \ - --passive-ftp \ - --tries 3 \ - --continue \ - --progress bar \ + ${wget_opts} \ --directory-prefix=${PKGDIR} \ ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg} if [[ $? = 0 ]] @@ -1235,6 +1369,8 @@ local latest_md5 local temp="$(mktemp -d)" local mirr mymirr + local opt + local tar_opts # try to get the md5 marked as latest on the server latest_md5="mage-latest.md5" @@ -1249,23 +1385,18 @@ echo -ne "${COLBLUE} --- ${COLDEFAULT}" echo "fetching latest md5 from ${mymirr} ..." + [[ ${VERBOSE} = off ]] && opt="--quiet" wget \ - --passive-ftp \ - --tries 3 \ - --continue \ - --progress bar \ + ${WGET_FETCH_OPTIONS} \ --directory-prefix=${temp} \ - ${mymirr}/rsync/tarballs/${latest_md5} + ${opt} ${mymirr}/rsync/tarballs/${latest_md5} echo -ne "${COLBLUE} --- ${COLDEFAULT}" echo "fetching latest tarball from ${mymirr} ..." wget \ - --passive-ftp \ - --tries 3 \ - --continue \ - --progress bar \ + ${WGET_FETCH_OPTIONS} \ --directory-prefix=${temp} \ - ${mymirr}/rsync/tarballs/${latest_tarball} + ${opt} ${mymirr}/rsync/tarballs/${latest_tarball} if [[ $? = 0 ]] then break @@ -1281,7 +1412,9 @@ then die "md5 is missing ... aborting" else - ( cd ${temp}; md5sum --check ${lastest_md5} ) || die "md5 for ${lastest_tarball} failed" + echo -ne "${COLBLUE} --- ${COLDEFAULT}" + echo -n "checking md5sum... " + ( cd ${temp}; md5sum -c ${latest_md5} ) || die "md5 for ${latest_tarball} failed" fi if [[ -d ${MAGEDIR} ]] @@ -1291,10 +1424,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 @@ -1750,7 +1890,8 @@ #deletes pakages from virtual database #$1 virtualname; $2 pkgname -virtuals_del() { +virtuals_del() +{ local virtualname="$1" local pkgname="$2" @@ -2475,7 +2616,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} :(" @@ -2688,7 +2829,8 @@ unset -f postremove } -show_etc_update_mesg() { +show_etc_update_mesg() +{ [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0 echo @@ -2922,3 +3064,55 @@ 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 + else + # no busybox + return 1 + fi + fi +} + +# 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 +}