--- trunk/mage/usr/lib/mage/mage4.functions.sh 2005/10/21 14:50:13 273 +++ trunk/mage/usr/lib/mage/mage4.functions.sh 2012/01/13 23:20:39 1654 @@ -1,6 +1,29 @@ #!/bin/bash # Magellan Linux Installer Functions (mage.functions.sh) -# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.8 2005-10-21 14:50:13 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 $ + +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() { @@ -15,6 +38,69 @@ return 0 } +mchecksum() +{ + local i + local rundir + local file + local method + local cmd + local retval + + # very basic getops + for i in $* + do + case $1 in + --rundir|-r) shift; rundir="$1" ;; + --file|-f) shift; file="$1" ;; + --method|-m) shift; method="$1" ;; + esac + shift + done + + # sanity checks + [[ -z ${rundir} ]] && die "mchecksum(): rundir missing" + [[ -z ${file} ]] && die "mchecksum(): file missing" + [[ -z ${method} ]] && die "mchecksum(): method missing" + + case ${method} in + md5) cmd="md5sum" ;; + sha256) cmd="sha256sum" ;; + *) die "mchecksum(): unknown method '${method}'" ;; + esac + + if [[ -d ${rundir} ]] + then + pushd ${rundir} &> /dev/null + ${cmd} -c ${file} &> /dev/null + retval="$?" + popd &> /dev/null + else + retval=1 + fi + + return "${retval}" +} + +mcheckemptydir() +{ + local dir="$1" + local retval=1 + + if [[ ! -d ${dir} ]] + then + echo "mcheckemptydir(): '${dir}' is not a directory!" + retval=3 + else + shopt -s nullglob dotglob + files=( ${dir}/* ) + (( ${#files[*]} )) || retval=0 + shopt -u nullglob dotglob + fi + + return ${retval} +} + unpack_packages() { local list="$@" @@ -23,6 +109,7 @@ local pkgtype local count_current local count_total + local tar_opts # get count of total packages declare -i count_current=0 @@ -54,8 +141,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 @@ -130,8 +225,7 @@ while read pathto posix user group do [ -z "${pathto}" ] && continue - [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR: ${MROOT}${pathto}" - + mqueryfeature "verbose" && echo -e "\t>>> DIR: ${MROOT}${pathto}" # monitors /etc/env.d -> env-rebuild [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true @@ -198,15 +292,16 @@ is_config_protected "${pathto}" retval="$?" - # 0 - not protected # - # 1 - error # - # 2 - protected # - # 3 - protected but masked # + # 0 - not protected # + # 1 - error # + # 2 - protected # + # 3 - protected but masked # + # 4 - protected but ignored # case ${retval} in # file is not protected - (over)write it 0|3) - [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}" install -m "${posix}" -o "${user}" -g "${group}" \ ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \ "${MROOT}${pathto}" @@ -218,13 +313,13 @@ "${user}" \ "${group}" \ "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ - "${MROOT}${pathto}")" \ + "${MROOT}${pathto}")" \ "${md5sum}" ;; # file is protected, write backup file 2) - if [[ ${VERBOSE} = on ]] + if mqueryfeature "verbose" then echo -en "${COLRED}" echo -n "! prot " @@ -245,13 +340,33 @@ "${user}" \ "${group}" \ "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ - "${dest_protected}")" \ + "${dest_protected}")" \ "${md5sum}" # update global MAGE_PROTECT_COUNTER (( MAGE_PROTECT_COUNTER++ )) export MAGE_PROTECT_COUNTER ;; + + # file is protected but ignored, delete the update/do nothing + 4) + if mqueryfeature "verbose" + then + echo -en "${COLRED}" + echo -n "! ignr " + echo -en "${COLDEFAULT}" + echo " === FILE: ${MROOT}${pathto}" + fi + # 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 @@ -294,23 +409,23 @@ while read pathto posix link mtime do [ -z "${pathto}" ] && continue - [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}" ln -snf "${link}" "${MROOT}${pathto}" - # fix mtime and db - fix_descriptor ${pkgname}/.symlinks \ - "${pathto}" \ - "${posix}" \ - "${link}" \ - "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ - "${MROOT}${pathto}")" +# # fix mtime and db +# fix_descriptor ${pkgname}/.symlinks \ +# "${pathto}" \ +# "${posix}" \ +# "${link}" \ +# "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ +# "${MROOT}${pathto}")" done < ${BUILDDIR}/${pkgname}/.symlinks - # now copy the fixed file over the old one - [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \ - cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,} +# # now copy the fixed file over the old one +# [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \ +# cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,} # very important: unsetting the '§' fieldseperator IFS=$'\n' @@ -326,6 +441,8 @@ local pkgname="$1" local pathto local posix + local user + local group local IFS # sanity checks; abort if not given @@ -339,12 +456,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}" + mqueryfeature "verbose" && 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 @@ -361,6 +483,10 @@ local pkgname="$1" local pathto local posix + local major + local minor + local user + local group local IFS # sanity checks; abort if not given @@ -374,23 +500,68 @@ # 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>>> CHAR: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}" - mknode -m ${posix} -c "${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 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 + mqueryfeature "verbose" && 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() { @@ -398,7 +569,7 @@ # sanity checks; abort if not given [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given." - + # this is only a wrapper # NOTE: @@ -413,6 +584,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}" } @@ -474,7 +646,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 @@ -492,10 +664,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 @@ -556,14 +731,18 @@ # abort if mage file not exists [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist." - # first unregister virtuals - provide="$(get_value_from_magefile PROVIDE ${magefile})" - if [ -n "${provide}" ] + # remove virtuals only if no other exist + if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]] then - for i in ${provide} - do - virtuals_del "${i}" "${pcat}/${pname}" - done + # first unregister virtuals + provide="$(get_value_from_magefile PROVIDE ${magefile})" + if [ -n "${provide}" ] + then + for i in ${provide} + do + virtuals_del "${i}" "${pcat}/${pname}" + done + fi fi # removes database entry @@ -573,6 +752,39 @@ fi } +# get the number of installed packages +count_installed_pkgs() +{ + local pcat + local pname + local pkg + local i + + # very basic getops + for i in $* + do + case $1 in + --pcat|-c) shift; pcat="$1" ;; + --pname|-n) shift; pname="$1" ;; + esac + shift + done + + # sanity checks; abort if not given + [ -z "${pcat}" ] && die "pkg_count() \$pcat not given." + [ -z "${pname}" ] && die "pkg_count() \$pname not given." + + declare -i i=0 + for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname}) + do + (( i++ )) + #echo "$i ${pkg}" + done + + # return the value + echo "${i}" +} + ################################################### # function compare_mtime # @@ -669,7 +881,7 @@ [ -z "${pathto}" ] && continue if [ ! -L "${MROOT}${pathto}" ] then - [[ ${VERBOSE} = on ]] && \ + mqueryfeature "verbose" && \ echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}" continue fi @@ -681,12 +893,12 @@ # 1=keep me # case ${retval} in 0) - [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}" rm "${MROOT}${pathto}" ;; 1) - [[ ${VERBOSE} = on ]] && \ + mqueryfeature "verbose" && \ echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}" ;; esac @@ -733,10 +945,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 @@ -753,7 +965,7 @@ if [ ! -e "${MROOT}${pathto}" ] then - [[ ${VERBOSE} = on ]] && \ + mqueryfeature "verbose" && \ echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}" continue fi @@ -765,12 +977,50 @@ # 1=keep me # case ${retval} in 0) - [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}" - rm "${MROOT}${pathto}" - ;; + # check if the file is config_protected + # ${MROOT} will automatically added if set !! + is_config_protected "${pathto}" + retval="$?" + + # 0 - not protected # + # 1 - error # + # 2 - protected # + # 3 - protected but masked # + # 4 - protected but ignored # + + case ${retval} in + # file is not protected - delete it + 0|3) + mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}" + rm "${MROOT}${pathto}" + ;; + + # file is protected, do not delete + 2) + if mqueryfeature "verbose" + then + echo -en "${COLRED}" + echo -n "! prot " + echo -en "${COLDEFAULT}" + echo " === FILE: ${MROOT}${pathto}" + fi + ;; + # file is protected but ignored, delete the update/do nothing + 4) + if mqueryfeature "verbose" + then + echo -en "${COLRED}" + echo -n "! ignr " + echo -en "${COLDEFAULT}" + echo " === FILE: ${MROOT}${pathto}" + fi + # simply do nothing here + ;; + esac + ;; 1) - [[ ${VERBOSE} = on ]] && \ + mqueryfeature "verbose" && \ echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}" ;; esac @@ -789,6 +1039,8 @@ { local pathto local posix + local user + local group local IFS local pcat local pname @@ -812,10 +1064,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 @@ -826,11 +1078,11 @@ # sets fieldseperator to "§" instead of " " IFS=§ - while read pathto posix + while read pathto posix user group do [ -z "${pathto}" ] && continue - [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}" rm "${MROOT}${pathto}" done < ${MROOT}${INSTALLDB}/${pfull}/.pipes @@ -847,6 +1099,8 @@ { local pathto local posix + local user + local group local IFS local pcat local pname @@ -870,10 +1124,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 @@ -884,11 +1138,11 @@ # sets fieldseperator to "§" instead of " " IFS=§ - while read pathto posix + while read pathto posix user group do [ -z "${pathto}" ] && continue - [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}" rm "${MROOT}${pathto}" done < ${MROOT}${INSTALLDB}/${pfull}/.char @@ -898,6 +1152,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 + + mqueryfeature "verbose" && 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 # ################################################### @@ -928,10 +1244,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 @@ -949,7 +1265,7 @@ if [ ! -d "${MROOT}${pathto}" ] then - [[ ${VERBOSE} = on ]] && \ + mqueryfeature "verbose" && \ echo -e "${COLRED}! exist${COLDEFAULT} === DIR: ${MROOT}${pathto}" continue fi @@ -957,7 +1273,7 @@ # exclude .keep directories if [ -f "${MROOT}${pathto}/.keep" ] then - [[ ${VERBOSE} = on ]] && \ + mqueryfeature "verbose" && \ echo -e "${COLRED}! .keep${COLDEFAULT} === DIR: ${MROOT}${pathto}" continue fi @@ -970,9 +1286,9 @@ if rmdir "${MROOT}${pathto}" &> /dev/null then - [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR: ${MROOT}${pathto}" + mqueryfeature "verbose" && echo -e "\t<<< DIR: ${MROOT}${pathto}" else - [[ ${VERBOSE} = on ]] && \ + mqueryfeature "verbose" && \ echo -e "${COLRED}! empty${COLDEFAULT} === DIR: ${MROOT}${pathto}" fi done @@ -985,7 +1301,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() { @@ -1019,7 +1335,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}" \ @@ -1030,9 +1346,111 @@ done } +# convertmirrors [uri] +convertmirrors() +{ + local uri="$1" + local scheme + local mirror + local mirrors + local addon + local real_uri + local output + + # needs + [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!" + [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!" + [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!" + [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!" + [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!" + + # check known uri schemes + case ${uri} in + http://*|https://*|ftp://*|ftps://*) mirrors="" ;; + mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;; + package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;; + gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;; + sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;; + gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;; + kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;; + *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;; + esac + + if [[ ! -z ${mirrors} ]] + then + for mirror in ${mirrors} + do + # add a whitespace to the output + [[ -z ${output} ]] || output+=" " + output+="${mirror}${addon}/${uri/${scheme}/}" + done + else + output="${uri}" + fi + + echo "${output}" +} + +mdownload() +{ + local i + local uri + local real_uris + local mirror + local outputfile + local outputdir + local retval + local wget_opts + + # very basic getops + for i in $* + do + case $1 in + --uri|-u) shift; uri="$1" ;; + --dir|-d) shift; outputdir="$1" ;; + esac + shift + done + + # sanity checks; abort if not given + [[ -z ${uri} ]] && die "mdownload(): no uri given!" + [[ -z ${outputdir} ]] && die "mdownload(): no dir given!" + + # convert mirrored uris to the real ones + real_uris="$(convertmirrors ${uri})" + + # verbose or not + mqueryfeature "!verbose" && wget_opts+=" --quiet" + + # filter wget options if busybox was found + wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})" + + # create outputdir + [[ ! -d ${outputdir} ]] && install -d "${outputdir}" + + for mirror in ${real_uris} + do + # get the name of the output file + outputfile="${mirror##*/}" + + wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}" + retval="$?" + if [[ ${retval} = 0 ]] + then + break + else + continue + fi + done + + # return wget retval + return "${retval}" +} + # fetch_packages /path/to/mage/file1 /path/to/mage/file2 fetch_packages() { + local i local list="$@" local pkg local mirr @@ -1041,8 +1459,12 @@ local opt local count_current local count_total + local wget_opts + + [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}." - [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc." + # 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 @@ -1082,30 +1504,12 @@ continue fi - for mirr in ${MIRRORS} - do - echo -ne " ${COLBLUE}***${COLDEFAULT}" - #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/${pkg} - if [[ $? = 0 ]] - then - break - else - continue - fi - done - + echo -ne " ${COLBLUE}***${COLDEFAULT}" + echo -e " fetching (${count_current}/${count_total}): ${pkg} ... " + mdownload --uri "package://${pkg}" --dir "${PKGDIR}" || die "Could not download ${pkg}" if [ ! -f ${PKGDIR}/${pkg} ] then - die "Could not download ${pkg}" + die "Package '${pkg}' after download not found in '${PKGDIR}'" fi done @@ -1117,26 +1521,13 @@ { if [ -z "${RSYNC}" ] then - die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc." + die "You have no rsync-mirrors defined. Please edit your ${MAGERC}." fi local i for i in ${RSYNC} do - rsync \ - --recursive \ - --links \ - --perms \ - --times \ - --devices \ - --timeout=600 \ - --verbose \ - --compress \ - --progress \ - --stats \ - --delete \ - --delete-after \ - ${i} ${MAGEDIR} + rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR} if [[ $? = 0 ]] then break @@ -1146,12 +1537,112 @@ done # clean up backup files (foo~) - find ${MAGEDIR} -name *~ -exec rm '{}' ';' + find ${MAGEDIR} -name \*~ -exec rm '{}' ';' - # check if an newer mage version is available + # check if a newer mage version is available is_newer_mage_version_available } +syncmage_tarball() +{ + local latest_tarball + local latest_md5 + 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" + + # 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 + mymirr="${mirr%/*}" + + echo -ne "${COLBLUE} --- ${COLDEFAULT}" + echo "fetching latest md5 from ${mymirr} ..." + mqueryfeature "!verbose" && opt="--quiet" + wget \ + ${wget_opts} \ + --directory-prefix=${temp} \ + ${opt} ${mymirr}/rsync/tarballs/${latest_md5} + + echo -ne "${COLBLUE} --- ${COLDEFAULT}" + echo "fetching latest tarball from ${mymirr} ..." + wget \ + ${wget_opts} \ + --directory-prefix=${temp} \ + ${opt} ${mymirr}/rsync/tarballs/${latest_tarball} + if [[ $? = 0 ]] + then + break + else + continue + fi + done + + if [[ -f ${temp}/${latest_tarball} ]] + then + # check md5 + if [[ ! -f ${temp}/${latest_md5} ]] + then + die "md5 is missing ... aborting" + else + echo -ne "${COLBLUE} --- ${COLDEFAULT}" + echo -n "checking md5sum... " + mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed" + fi + + if [[ -d ${MAGEDIR} ]] + then + echo -ne "${COLBLUE} --- ${COLDEFAULT}" + echo "cleaning old mage-tree ${MAGEDIR}..." + # honor mountpoints and empty dirs + if mountpoint -q ${MAGEDIR} + then + if ! mcheckemptydir ${MAGEDIR} + then + find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xarg --no-run-if-empty rm -r + fi + else + rm -rf ${MAGEDIR} + fi + 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 ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball" + + if [[ -d ${temp} ]] + then + echo -ne "${COLBLUE} --- ${COLDEFAULT}" + echo "cleaning temp-files ..." + rm -rf ${temp} + fi + + # check if a newer mage version is available + is_newer_mage_version_available + else + die "Could not fetch the latest tarball ... aborting" + fi +} + cleanpkg() { if [ -d "${PKGDIR}" ] @@ -1182,20 +1673,23 @@ } -# cuts full pathnames or versioniezed names down to basename -choppkgname() -{ - #we want this only if full name was used - if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ] - then - #cuts ARCH and PBUILD - #ARCH comes from /etc/mage.rc - MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g") +# unused? +# +# # cuts full pathnames or versionized names down to basename +# choppkgname() +# { +# #we want this only if full name was used +# if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ] +# then +# #cuts ARCH and PBUILD +# #ARCH comes from ${MAGERC} +# MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g") +# +# #cuts version number +# MAGENAME=$(basename ${MAGENAME%-*} .mage) +# fi +# } - #cuts version number - MAGENAME=$(basename ${MAGENAME%-*} .mage) - fi -} # get_categorie $PNAME, returns CATEGORIE # $1=pname @@ -1222,11 +1716,14 @@ # returns 0=stable 1=unstable check_stable_package() { + # first check if this magefile is not blacklisted + blacklisted "$1" || return 1 + local STATE STATE="$(get_value_from_magefile STATE "$1")" # state testing - if [[ ${USE_TESTING} = true ]] + if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]] then case ${STATE} in testing|stable) return 0 ;; @@ -1235,7 +1732,7 @@ fi # state unstable - if [[ ${USE_UNSTABLE} = true ]] + if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]] then case ${STATE} in unstable|testing|stable) return 0 ;; @@ -1261,39 +1758,20 @@ local PNAME="$2" local magefile - for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*) + # do not list the content of a directory, only the name (-d) + 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) - [ -d ${magefile} ] && continue + [[ -d ${magefile} ]] && continue if check_stable_package ${magefile} then HIGHEST_MAGEFILE=${magefile} #for debug only - [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" + mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" fi done - # 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 } @@ -1308,6 +1786,7 @@ # 1 - error # # 2 - protected # # 3 - protected but masked # +# 4 - protected but ignored # # # ################################################### is_config_protected() @@ -1316,34 +1795,46 @@ local TEST local PROTECTED local IFS + local i + local x EXPFILE="${MROOT}$1" # file does not exist; it can be written - [ ! -e ${EXPFILE} ] && return 0 + [[ ! -e ${EXPFILE} ]] && return 0 # to be safe; it may be '§' IFS=' ' - # check ob in config protect + # check if config protected for i in ${CONFIG_PROTECT} do - # ersetzen von $i nur wenn am anfang der variable + # only replace $i in the beginning of the variable TEST="${EXPFILE/#${MROOT}${i}/Protected}" - if [ "${TEST}" != "${EXPFILE}" ] + if [[ ${TEST} != ${EXPFILE} ]] then - # setzen das es protected ist + # file is config proteced PROTECTED=TRUE - # check ob nicht doch maskiert + # check if not masked for x in ${CONFIG_PROTECT_MASK} do TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}" - if [ "${TEST}" != "${EXPFILE}" ] + if [[ ${TEST} != ${EXPFILE} ]] then PROTECTED=MASKED fi done + + # check if not ignored + for x in ${CONFIG_PROTECT_IGNORE} + do + TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}" + if [[ ${TEST} != ${EXPFILE} ]] + then + PROTECTED=IGNORED + fi + done fi done @@ -1358,6 +1849,10 @@ #echo "I'm protected, but masked - delete me" return 3 ;; + IGNORED) + #echo "I'm protected, but ignored - keep me, del update" + return 4 + ;; *) #echo "delete me" return 0 @@ -1375,7 +1870,29 @@ ################################################### count_protected_files() { - ${MLIBDIR}/writeprotected "$1" + local file="$1" + local dirname="${file%/*}" + local filename="${file##*/}" + local count + local output + local i + + declare -i count=0 + + # check if there are already protected files + for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" | + sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" | + sort -t'%' -k3 -k2 | cut -f1 -d'%') + do + count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::") + done + (( count ++ )) + + # fill output up with zeros + for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done + output="${output}${count}" + + echo "${output}" } # call with @@ -1392,6 +1909,7 @@ local list local pcatdir local protected + local i # very basic getops for i in $* @@ -1404,15 +1922,16 @@ shift done - # sanity checks; abort if not given - [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given." +# it's not good to complain here about empty pnames; better to continue later anyway +# # sanity checks; abort if not given +# [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given." # check needed global vars [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set." # set pcatdir to '*' if empty - [ -z "${pcatdir}" ] && pcatdir=* + [ -z "${pcatdir}" ] && pcatdir='*' for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/* do @@ -1501,7 +2020,7 @@ if virtuals_read ${virtualname} then - # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already + # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already for i in $(virtuals_read ${virtualname} showpkgs) do if [[ ${i} = ${pkgname} ]] @@ -1545,7 +2064,8 @@ #deletes pakages from virtual database #$1 virtualname; $2 pkgname -virtuals_del() { +virtuals_del() +{ local virtualname="$1" local pkgname="$2" @@ -1652,15 +2172,15 @@ { local i - if [ -n "$@" ] + if [[ -n $* ]] then - for i in $@ + for i in $* do - [[ ${MAGEDEBUG} = on ]] && \ + mqueryfeature "debug" && \ echo "--- Including ${MAGEDIR}/include/${i}.minc" source ${MAGEDIR}/include/${i}.minc done - [[ ${MAGEDEBUG} = on ]] && echo + mqueryfeature "debug" && echo fi } @@ -1668,9 +2188,9 @@ { local i - if [ -n "$@" ] + if [[ -n $* ]] then - for i in $@ + for i in $* do echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" source ${SMAGESCRIPTSDIR}/include/${i}.sminc @@ -1694,7 +2214,7 @@ echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT} echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT} echo "It is recommened to install this newer version" - echo "or your current system installation may brake." + echo "or your current system installation may break." echo echo -en "Please update mage by running " echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT} @@ -1966,6 +2486,9 @@ local magefile="$2" local value + [[ -z ${var} ]] && return 1 + [[ -z ${magefile} ]] && return 1 + # local all possible vars of a mage file # to prevent bad issues local PKGNAME @@ -1976,6 +2499,8 @@ local SDEPEND local PROVIDE local PKGTYPE + local MAGE_TARGETS + local SPLIT_PACKAGE_BASE local preinstall local postinstall local preremove @@ -2022,6 +2547,7 @@ local count_current local magefile local src_install + local i # very basic getops for i in $* @@ -2095,9 +2621,48 @@ echo B:${pbuild} fi - smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2 + if [[ -n ${MAGE_TARGETS} ]] + then + # basic svn compat + if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] + then + for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2 + do + smage2file="${i}" + done + else + smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2 + fi + + elif [[ -n ${SPLIT_PACKAGE_BASE} ]] + then + # basic svn compat + if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] + then + for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2 + do + smage2file="${i}" + done + else + smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2 + fi + + else + # basic svn compat + if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] + then + for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2 + do + smage2file="${i}" + done + else + smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2 + fi + fi + if [ -f "${smage2file}" ] then + echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... " smage2 ${smage2file} || die "compile failed" else echo @@ -2111,14 +2676,7 @@ if [[ ${PKGTYPE} != virtual ]] && \ [[ ${PKGTYPE} != sources ]] then - # show a verbose message on src-install - 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 + echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... " build_doinstall ${PKGNAME} fi @@ -2232,7 +2790,7 @@ then echo -ne "${COLBLUE} *** ${COLDEFAULT}" echo -ne "checking md5sum (${count_current}/${count_total}): " - ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed" + mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed" else echo -ne "${COLBLUE} --- ${COLDEFAULT}" echo -e "!! no md5sum file found for ${pkgfile} :(" @@ -2375,9 +2933,9 @@ echo -ne "${COLBLUE} <<< ${COLDEFAULT}" echo -n "removing: " echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" - echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}" + echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}" - magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" + magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" source ${magefile} ## preremove scripts @@ -2445,7 +3003,8 @@ unset -f postremove } -show_etc_update_mesg() { +show_etc_update_mesg() +{ [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0 echo @@ -2471,14 +3030,22 @@ local state local descriptiom local homepage + local license local i local all_installed local ipver local ipbuild + local latest_available + local depsfull + local sdepsfull + local deps + local sdeps + local dep + local sign # only names no versions - result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name *${string}*)" - #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)" + result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')" + #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)" # nothing found [[ -z ${result} ]] && die "No package found containing '${string}' in the name." @@ -2492,40 +3059,81 @@ # get highest version available magefile=$(get_highest_magefile ${pcat} ${pname}) - # now get all needed infos to print a nice output - pver="$(magename2pver ${magefile})" - pbuild="$(magename2pbuild ${magefile})" - state="$(get_value_from_magefile STATE ${magefile})" - description="$(get_value_from_magefile DESCRIPTION ${magefile})" - homepage="$(get_value_from_magefile HOMEPAGE ${magefile})" + if [[ ! -z ${magefile} ]] + then + # now get all needed infos to print a nice output + pver="$(magename2pver ${magefile})" + pbuild="$(magename2pbuild ${magefile})" + state="$(get_value_from_magefile STATE ${magefile})" + description="$(get_value_from_magefile DESCRIPTION ${magefile})" + homepage="$(get_value_from_magefile HOMEPAGE ${magefile})" + license="$(get_value_from_magefile LICENSE ${magefile})" - # all installed - for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat}) - do - ipver="$(magename2pver ${i})" - ipbuild="$(magename2pbuild ${i})" + # all installed + for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat}) + do + ipver="$(magename2pver ${i})" + ipbuild="$(magename2pbuild ${i})" - if [[ -z ${all_installed} ]] - then - all_installed="${ipver}-${ipbuild}" - else - all_installed="${all_installed} ${ipver}-${ipbuild}" - fi - done - [[ -z ${all_installed} ]] && all_installed="none" + if [[ -z ${all_installed} ]] + then + all_installed="${ipver}-${ipbuild}" + else + all_installed="${all_installed} ${ipver}-${ipbuild}" + fi + done + [[ -z ${all_installed} ]] && all_installed="none" - case ${state} in - stable) state=${COLGREEN}"[s] ";; - testing) state=${COLYELLOW}"[t] ";; - unstable) state=${COLRED}"[u] ";; - old) state=${COLGRAY}"[o] ";; - esac + case ${state} in + stable) state=${COLGREEN}"[s] ";; + testing) state=${COLYELLOW}"[t] ";; + unstable) state=${COLRED}"[u] ";; + old) state=${COLGRAY}"[o] ";; + esac + + latest_available="${pver}-${pbuild}" + else + # package is masked + state="${COLRED}[m] " + latest_available="${COLRED}masked for this distribution.${COLDEFAULT}" + fi + + depsfull="$(get_value_from_magefile DEPEND ${magefile})" + sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})" + + while read sign dep + do + case ${dep} in + "") continue;; + esac + + deps="${deps} $(basename ${dep%-*})" + done << EOF +${depsfull} +EOF + + while read sign dep + do + case ${dep} in + "") continue;; + esac + + sdeps="${sdeps} $(basename ${dep%-*})" + done << EOF +${sdepsfull} +EOF echo -e "${state}${pcat}/${pname}"${COLDEFAULT} - echo " Latest available: ${pver}-${pbuild}" + echo -e " Latest available: ${latest_available}" echo " Installed versions: ${all_installed}" echo " Description: ${description}" echo " Homepage: ${homepage}" + if [[ ! -z ${license} ]] + then + echo " License: ${license}" + fi + echo " Depends: ${deps}" + echo " SDepends: ${sdeps}" echo unset pcat @@ -2539,6 +3147,12 @@ unset all_installed unset ipver unset ipbuild + unset depsfull + unset sdepsfull + unset deps + unset sdeps + unset dep + unset sign done } @@ -2558,8 +3172,264 @@ eval "${functions}() { ${include}_${functions} ; }" # debug - [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}" + mqueryfeature "debug" && typeset -f "${functions}" shift done } + +mlibdir() +{ + local libdir=lib + [[ ${ARCH} = x86_64 ]] && libdir=lib64 + + echo "${libdir}" +} + +## blacklisted ${magefile} +blacklisted() +{ + [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable + + # compat + [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable + [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing + + # support both types for the moment + if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]] + then + local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}" + else + local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}" + fi + + # return 0 if the list not exist; nothin is masked + [[ ! -f ${EXCLUDED} ]] && return 0 + + local MAGEFILE="$1" + + local PCAT="$(magename2pcat ${MAGEFILE})" + local PNAME="$(magename2pname ${MAGEFILE})" + local PVER="$(magename2pver ${MAGEFILE})" + local PBUILD="$(magename2pbuild ${MAGEFILE})" + + local EXPCAT EXPNAME EXPVER EXPBUILD + while read EXPCAT EXPNAME EXPVER EXPBUILD + do + # ignore spaces and comments + case "${EXPCAT}" in + \#*|"") continue ;; + esac + + # exclude full pver + if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] && + [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] && + [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] && + [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]] + then + [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1 + fi + + # exclude pcat/pname only + if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] && + [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] && + [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]] + then + [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1 + fi + done << EOF +$( cat ${EXCLUDED}; echo) +EOF + + 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} +} + +known_mage_feature() +{ + local feature="$1" + local retval + + case "${feature}" in + autosvc|!autosvc) retval=0 ;; + buildlog|!buildlog) retval=0 ;; + ccache|!ccache) retval=0 ;; + check|!check) retval=0 ;; + compressdoc|!compressdoc) retval=0 ;; + debug|!debug) retval=0 ;; + distcc|!distcc) retval=0 ;; + kernelsrcunpack|!kernelsrcunpack) retval=0 ;; + libtool|!libtool) retval=0 ;; + linuxsymlink|!linuxsymlink) retval=0 ;; + pkgbuild|!pkgbuild) retval=0 ;; + pkgdistrotag|!pkgdistrotag) retval=0 ;; + purge|!purge) retval=0 ;; + qalint|!qalint) retval=0 ;; + regentree|!regentree) retval=0 ;; + resume|!resume) retval=0 ;; + srcpkgbuild|!srcpkgbuild) retval=0 ;; + srcpkgtarball|!srcpkgtarball) retval=0 ;; + static|!static) retval=0 ;; + stepbystep|!stepbystep) retval=0 ;; + strip|!strip) retval=0 ;; + verbose|!verbose) retval=0 ;; + *) retval=1 ;; + esac + + return "${retval}" +} + +load_mage_features() +{ + for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]} + do + FVERBOSE=off msetfeature ${i} + done +} + +msetfeature() +{ + local feature + local count + local i + local found + + for feature in $@ + do + found=0 + count="${#MAGE_FEATURES_CURRENT[*]}" + + if ! known_mage_feature "${feature}" + then + [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}" + return 3 + fi + + for ((i=0; i