Page 1 of 1

multi-distro upgrade script

Posted: Tue Apr 21, 2015 7:58 pm
by pidsley
You know I have a bunch of different things installed on the test machines. I sometimes forget all the upgrade commands, so I scripted them. Nothing special about this script, but you might be able to use parts of it or get some ideas. It's modular, like most of my scripts, so it should be easy to add other distros or commands.

I named it "multi-sysup" and alias it in each distro to "sysup" -- this way when I want to update a test machine, I just type "sysup" and the script knows what to do for each distro. It also records the date and time of the last upgrade step.

I separated the commands with a prompt for each (instead of just "this && that && theother" because sometimes I only want to run part of the sequence ("ports -u" completed successfully, so no need to re-run that, but a compile failed, so I need to re-run "prt-get sysup"; also the "emerge --oneshot portage" step doesn't always need to be run, so I can skip that one)

https://github.com/pidsley/codemangler/ ... ulti-sysup

Code: Select all

#!/bin/bash

red="\e[31m"
grn="\e[32m"
cyn="\e[36m"
rst="\e[0m"    # reset

UPD_FILE=~/.upd.last

error-exit() {
    echo -e $red"must specify one of -C (CRUX) -D (Debian) or -G (Gentoo)"$rst
    exit
}

[[ -z $1 ]] && error-exit

yna() {
    while true; do
        read -n1 -p "$1? (y/n/a) "
        echo
        case $REPLY in
            [aA] )
                echo -e $red'abort'$rst
                exit 1;;
            [yY] )
                return 0;;
            [nN] )
                return 1;;
            * )
                echo -e $red'please answer y/n/a'$rst;;
        esac
    done
}

announce() {
    echo -e $grn"$1 update"$rst
    echo -e "last step run was $cyn$(cat $UPD_FILE)"
}

dostep() {
    step=$1
    cmd=$2
    echo
    echo -e $grn"update step $step: $cyn$cmd$rst"
    if yna "run $cmd"; then
        echo -e $cyn"running $cmd$rst"
        echo
        sudo $cmd && echo "$step $cmd $rst on $(date)" > $UPD_FILE
    fi
}

echo
case $1 in
    -C )
        announce CRUX
        dostep 1 "ports -u"
        dostep 2 "prt-get sysup"
        dostep 3 "prtwash -a"
        ;;
    -D )
        announce Debian
        dostep 1 "apt-get update"
        dostep 2 "apt-get dist-upgrade"
        dostep 3 "apt-get autoremove"
        dostep 4 "apt-get autoclean"
        ;;
    -G )
        announce Gentoo
        dostep 1 "emerge --sync"
        dostep 2 "emerge --oneshot portage"
        dostep 3 "emerge world -uavDN --with-bdeps=y"
        dostep 4 "dispatch-conf"
        dostep 5 "emerge -a --depclean"
        dostep 6 "revdep-rebuild"
        dostep 7 "eclean -i distfiles"
        ;;
    * )
        error-exit;;
esac

Re: multi-distro upgrade script

Posted: Tue Apr 21, 2015 8:07 pm
by rhowaldt
cool. won't use it, but i like it. thanks for posting this Pidsley!

Re: multi-distro upgrade script

Posted: Tue Apr 21, 2015 8:26 pm
by GekkoP
Great stuff. I'll add Fedora and Arch, because I have those around at the moment.

Code: Select all

-F )
    announce Fedora
    dostep 1 "yum update"
    dostep 2 "yum clean all"
    ;;
-A )
    announce Arch
    dostep 1 "pacman -Syu"
    dostep 2 "pacman -Sc"
    ;;

Re: multi-distro upgrade script

Posted: Tue Apr 21, 2015 8:31 pm
by pidsley
^ cool -- thanks GekkoP ; I added those to the script on github.

Re: multi-distro upgrade script

Posted: Tue Apr 21, 2015 8:35 pm
by GekkoP
^ np.
Lovely script, I was used to alias everything to "upg" and "pclean", but this is a cleaner solution. Thank you.

Re: multi-distro upgrade script

Posted: Tue Apr 21, 2015 10:06 pm
by bones
Great idea, nice work.

Re: multi-distro upgrade script

Posted: Tue Apr 21, 2015 10:29 pm
by pidsley
^ thanks bones. What do you typically run to update Slackware?

Re: multi-distro upgrade script

Posted: Wed Apr 22, 2015 8:58 am
by GekkoP
Just saying: works like a charm on 4 different setups. Thanks again, Pidsley.

Re: multi-distro upgrade script

Posted: Wed Apr 22, 2015 12:57 pm
by bones
pidsley wrote:^ thanks bones. What do you typically run to update Slackware?

Code: Select all

slackpkg update
slackpkg upgrade-all

Re: multi-distro upgrade script

Posted: Wed Apr 22, 2015 1:47 pm
by machinebacon
^ same here.

Re: multi-distro upgrade script

Posted: Wed Apr 22, 2015 1:48 pm
by simgin
^^ Bones, what about

Code: Select all

sbopkg -o
for removing old sources ?

Re: multi-distro upgrade script

Posted: Wed Apr 22, 2015 1:57 pm
by machinebacon
^ Would need sbopkg, which is not 'vanilla' slackware. Maybe better "slackpkg remove $PKG"?

Re: multi-distro upgrade script

Posted: Wed Apr 22, 2015 2:16 pm
by simgin
Ahh, ok sorry mate :) I tried hehe.

Re: multi-distro upgrade script

Posted: Wed Apr 22, 2015 3:04 pm
by machinebacon
Doesn't matter, it's good to have that covered, too -- maybe with a

Code: Select all

[[ ! -f /usr/bin/sbopkg ]] && exit 1
(not sure now if sbopkg is originally placed there or into /usr/sbin)

Re: multi-distro upgrade script

Posted: Wed Apr 22, 2015 4:02 pm
by simgin
^ I did some research o.O
It is in /usr/sbin, it used to be in /usr/bin but they changed that in 2009 with the release of Sbopkg 0.30.0alpha1 :)

I found the info here: http://lists.slackbuilds.org/pipermail/ ... 04255.html

So the code will look like this:

Code: Select all

[[ ! -f /usr/sbin/sbopkg ]] && exit 1
cheers
simon

Re: multi-distro upgrade script

Posted: Wed Apr 22, 2015 6:05 pm
by pidsley
Added this to the script:

Code: Select all

-S )
        announce Slackware
        dostep 1 "slackpkg update"
        dostep 2 "slackpkg upgrade-all"
        [[ $(which sbopkg 2>/dev/null) ]] && dostep 3 "sbopkg -o"
        ;;
Testing with "which" ensures the command can be run, and does not care where the binary is located.

Re: multi-distro upgrade script

Posted: Wed Apr 22, 2015 7:03 pm
by simgin
^ Nice work Pidsley :)