[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#809441: apt: provide a global resource for upgradeable packages



Package: apt
Version: 1.0.9.8.2
Severity: wishlist

Dear Maintainer,

in Debian there are several tools which calculate the number of
available pkgs updates and the specific data
<pkg> <version_old> <version_new>
on their own.

This results in several tools here that all do the same thing over and over again.
(Update notifier e.g. apper, byobu GNU screen wrapper, to include it in status
line, and so on...)

Local i have a script which does this once everytime 'update' is run.
I attach it.

I would like to ask APT maintainers if you would be interested to include/create
such a global resource which could be easyly reused by other clients then.


PS.
I follow your work on apt 1.1 with great interest! Thank you for that!



kind regards,

     Thilo



-- System Information:
Debian Release: 8.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'proposed-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.16.0-4-amd64 (SMP w/2 CPU cores)
Locale: LANG=C.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages apt depends on:
ii  debian-archive-keyring  2014.3
ii  gnupg                   1.4.18-7
ii  libapt-pkg4.12          1.0.9.8.2
ii  libc6                   2.19-18+deb8u1
ii  libgcc1                 1:4.9.2-10
ii  libstdc++6              4.9.2-10

apt recommends no packages.

Versions of packages apt suggests:
pn  apt-doc     <none>
ii  aptitude    0.6.11-1+b1
ii  dpkg-dev    1.17.26
ii  python-apt  0.9.3.12
ii  synaptic    0.81.3
ii  wajig       2.17

-- Configuration Files:
/etc/cron.daily/apt changed [not included]

-- no debconf information
#!/bin/bash
#
# vim: ts=8:sw=4:sts=4:et:

export PATH="/sbin:/bin:/usr/sbin:/usr/bin"

if [[ -z ${DBUGVERBOSE} ]] ; then
    DBUGVERBOSE=false
fi

# taken from '/etc/cron.daily/apt'. Thanks!
debug_echo() {
    # display debug messages if $DBUGVERBOSE is set
    case ${DBUGVERBOSE} in
        ([Tt][Rr][Uu][Ee]|1|[Yy][Ee][Ss]|[Oo][Nn])
            echo "${*}" 1>&2
            ;;
    esac
}

apt-toupgrade() {
    local -i updatenum
    local    DIR DEB_UPDT_CNT_FILE DEB_AVAIL_UPDTS_FILE DEB_AVAIL_FULL_FILE DEB_INSTALLED_FILE

    DIR=/var/lib/apt/meta-data
    DEB_UPDT_CNT_FILE="${DIR}/deb-updt-count"
    DEB_AVAIL_UPDTS_FILE="${DIR}/deb-avail-updates"
    DEB_AVAIL_FULL_FILE="${DIR}/deb-avail-all"
    DEB_INSTALLED_FILE="${DIR}/deb-installed"

    updatenum=0

    if [[ ! -d ${DIR} ]] ; then
        debug_echo 'creating cache dir! '
        command mkdir -p "${DIR}"
    fi

    if [[ ! -f ${DEB_UPDT_CNT_FILE} ]] || [[ -L ${DEB_UPDT_CNT_FILE} ]] ; then
        debug_echo "normalizing count file '${DEB_UPDT_CNT_FILE}'"
        command rm -f "${DEB_UPDT_CNT_FILE}"
    fi

    if [[ ! -f ${DEB_AVAIL_UPDTS_FILE} ]] || [[ -L ${DEB_AVAIL_UPDTS_FILE} ]] ; then
        debug_echo "normalizing avail updates file '${DEB_AVAIL_UPDTS_FILE}'"
        command rm -f "${DEB_AVAIL_UPDTS_FILE}"
    fi

    debug_echo 'updating count now'
    # generate list of upradable pkgs
    command apt-get --just-print -o Debug::NoLocking=true dist-upgrade 2>/dev/null  \
                    | command grep '^Inst'                  \
                    | command grep -oE '^.*\(\S*'           \
                    | command awk '{ print $2" "$3" "$4 }'  \
                    | command sed 's#[][()]##g'             \
                    | column -t     1>"${DEB_AVAIL_UPDTS_FILE}"  2>/dev/null

    # generate count of upradable pkgs
    command awk 'END { print NR }' "${DEB_AVAIL_UPDTS_FILE}"   1>"${DEB_UPDT_CNT_FILE}"    2>/dev/null

    updatenum=$(head -n 1 "${DEB_UPDT_CNT_FILE}")
    debug_echo "updatenum is: '${updatenum}'"

    # generate list of all available pkgs
    command apt-cache -o Debug::NoLocking=true --no-generate --all-names pkgnames \
                    | sort    1>"${DEB_AVAIL_FULL_FILE}"  2>/dev/null

    # generate list of all installed pkgs
    command dpkg-query -W -f '${Status}\t${Package}\n' \
                    | command egrep '(ok installed|ok config-files)' \
                    | command cut -f2,3     1>"${DEB_INSTALLED_FILE}"  2>/dev/null

    command sync
}

apt-toupgrade              || exit 1
debug_echo "END apt-toupgrade() run"

exit 0


Reply to: