Dan Ritter wrote:

> It seems unlikely to me that you want to do an autoremove
> before you have done an upgrade.

a1 is to maintain and a2 is to upgrade, so the idea is to
always upgrade from a maintained state, that's why a2 first
calls a1. One could do a1 after a2 as well as
before, actually.

> apt autoremove calls apt-get autoremove. Doing that twice
> seems unwise or useless.

OK, thanks, fixed!

> apt-get check is an extremely basic fast check to see if the
> cache is in place. Running it after update is useless -- any
> failure would appear in update first.

OK!

> In general people don't want to dist-upgrade automatically.
> Maybe you do.

Well, none of this is automated necessarily, these commands
can be run by the user explicitely from the shell, it is how
I use them. I don't install a lot of things from the repos but
when I do the system get the implied sanity check by those
piles of commands.

Now they look like this:

a1 () {
    sudo apt-get  -qq   check
    sudo apt-get  -qq   update
    sudo apt-get  -qq   autoremove
    sudo aptitude -q=99 autoclean
    apt -a list --upgradable
}

a2 () {
    a1
    sudo apt-get -qq upgrade
    sudo apt-get dist-upgrade
}

Here is the whole file yanked if you are into this part of the
Debianverse ...

#! /bin/zsh
#
# this file:
#   https://dataswamp.org/~incal/conf/.zsh/apt

alias am='aptitude show'
alias as='aptitude search'

alias ar='sudo apt-get -qq remove'
alias ap='sudo apt-get -qq purge'

package-versions () {
    apt list -a $1
}
alias vers=package-versions

apt-install () {
    apt-get-update
    sudo apt-get -qq install $@
}
alias ai=apt-install

apt-reinstall () {
    apt-get-update
    sudo apt-get -qq reinstall $@
}
alias aii=apt-reinstall

a1 () {
    sudo apt-get  -qq   check
    sudo apt-get  -qq   update
    sudo apt-get  -qq   autoremove
    sudo aptitude -q=99 autoclean
    apt -a list --upgradable
}

a2 () {
    a1
    sudo apt-get -qq upgrade
    sudo apt-get dist-upgrade
}

require-bin () {
    local bins=($@)
    local all_good=true

    local fun=$funcstack[2]
    echo "checking requirements for"
    echo "\n  ${fun}\n"

    for b in $bins; do
        echo -n "    $b: "
        type $b &> /dev/null

        if (( ! $? )); then
            set-color green
            echo OK
        else
            set-color red
            echo fail
            all_good=false
        fi
        reset-color
    done

    if ( ! $all_good ); then
        echo "\nnot all"
        return 1
    else
        echo "\nall systems ready"
        return 0
    fi
}

apt-installed () {
    apt list --installed
}

apt-get-update () {
    sudo apt-get -qq update
}

apt-get-upgrade () {
    apt-get-update
    if [ $# > 0 ]; then
        sudo apt-get -qq install --only-upgrade $@
    else
        sudo apt-get -qq upgrade
    fi
}
alias au=apt-get-upgrade

apt-get-upgrade-dist () {
    apt-get-update
    sudo apt-get -qq dist-upgrade
}

command-to-pack () {
    if [[ $# = 1 ]]; then
        local cmd=$1
        local whereis_path=$(whereis $cmd | awk '{print $2}')
        local bin=$(readlink -e $whereis_path)
        if [[ -z $bin ]]; then
            local fun=$funcstack[1]
            echo                                                \
                "$fun error: no such command (\"$cmd\")"        \
                "\nNB: $fun deals with installed software,"     \
                "\n    to track the package of any binary, use" \
                "\n    $ bin-to-pack BINARY-NAME"               >&2
            return
        fi
        bin-to-pack $bin
    else
        echo "syntax: $0 COMMAND" >&2
    fi
}
alias cmd2pack=command-to-pack

bin-to-pack () {
    local fs=($@)
    deb-file-to-pack $fs
    file-to-pack $fs
}
alias bin2pack=bin-to-pack

pack-to-file () {
    local pack=$1
    local only_bins=$2

    local fs=("${(@f)$(dpkg --listfiles $pack)}")

    if [[ $only_bins == 1 ]]; then
        for f in $fs; do
            [[ -x $f && ! -d $f ]] && echo $f
        done
    else
        for f in $fs; do
            [[ -f $f ]]            && echo $f
        done
    fi | sort
}
alias files-from=pack-to-file

pack-to-bin () {
    local pack=$1
    pack-to-file $pack 1 # only_bins
}
alias bins-from=pack-to-bin

deb-file-to-pack () {
    local fs=($@)
    dpkg --search $fs 2> /dev/null | cut -d ':' -f 1
}

file-to-pack () {
    sudo apt-file update > /dev/null
    apt-file search $@
}
alias file-there=file-to-pack

get-source () {
    apt-get -qq source $@
}
alias get-src=get-source

get-command-source () {
    if [[ $# = 1 ]]; then
        local cmd=$1
        get-source $(cmd2pack $cmd)
    else
        echo "syntax: $0 COMMAND" >&2
    fi
}

# aptitude search -F %V "?exact-name(units)"
file-url () {
    local pack=$1
    local ver=$(dpkg-query -f '${Version}\n' -W $pack)
    local file=$2
    local url=https://sources.debian.org/data/main/u/$pack/$ver/$file
    echo $url
}

-- 
underground experts united
https://dataswamp.org/~incal

Reply via email to