multi-distro upgrade script

Submitted scripts and programs
Forum rules
Your own work only.
pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

multi-distro upgrade script

Unread post by pidsley » Tue Apr 21, 2015 7:58 pm

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

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: multi-distro upgrade script

Unread post by rhowaldt » Tue Apr 21, 2015 8:07 pm

cool. won't use it, but i like it. thanks for posting this Pidsley!
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5877
Joined: Tue Sep 03, 2013 7:05 am

Re: multi-distro upgrade script

Unread post by GekkoP » Tue Apr 21, 2015 8:26 pm

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"
    ;;

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: multi-distro upgrade script

Unread post by pidsley » Tue Apr 21, 2015 8:31 pm

^ cool -- thanks GekkoP ; I added those to the script on github.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5877
Joined: Tue Sep 03, 2013 7:05 am

Re: multi-distro upgrade script

Unread post by GekkoP » Tue Apr 21, 2015 8:35 pm

^ np.
Lovely script, I was used to alias everything to "upg" and "pclean", but this is a cleaner solution. Thank you.

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: multi-distro upgrade script

Unread post by bones » Tue Apr 21, 2015 10:06 pm

Great idea, nice work.

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: multi-distro upgrade script

Unread post by pidsley » Tue Apr 21, 2015 10:29 pm

^ thanks bones. What do you typically run to update Slackware?

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5877
Joined: Tue Sep 03, 2013 7:05 am

Re: multi-distro upgrade script

Unread post by GekkoP » Wed Apr 22, 2015 8:58 am

Just saying: works like a charm on 4 different setups. Thanks again, Pidsley.

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: multi-distro upgrade script

Unread post by bones » Wed Apr 22, 2015 12:57 pm

pidsley wrote:^ thanks bones. What do you typically run to update Slackware?

Code: Select all

slackpkg update
slackpkg upgrade-all

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: multi-distro upgrade script

Unread post by machinebacon » Wed Apr 22, 2015 1:47 pm

^ same here.
..gnutella..

User avatar
simgin
Meme Fodder
Posts: 1167
Joined: Sun Jan 06, 2013 12:07 am
Location: Bradford-on-Avon, UK

Re: multi-distro upgrade script

Unread post by simgin » Wed Apr 22, 2015 1:48 pm

^^ Bones, what about

Code: Select all

sbopkg -o
for removing old sources ?
Someone told me that I am delusional, I almost fell off my unicorn.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: multi-distro upgrade script

Unread post by machinebacon » Wed Apr 22, 2015 1:57 pm

^ Would need sbopkg, which is not 'vanilla' slackware. Maybe better "slackpkg remove $PKG"?
..gnutella..

User avatar
simgin
Meme Fodder
Posts: 1167
Joined: Sun Jan 06, 2013 12:07 am
Location: Bradford-on-Avon, UK

Re: multi-distro upgrade script

Unread post by simgin » Wed Apr 22, 2015 2:16 pm

Ahh, ok sorry mate :) I tried hehe.
Someone told me that I am delusional, I almost fell off my unicorn.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: multi-distro upgrade script

Unread post by machinebacon » Wed Apr 22, 2015 3:04 pm

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)
..gnutella..

User avatar
simgin
Meme Fodder
Posts: 1167
Joined: Sun Jan 06, 2013 12:07 am
Location: Bradford-on-Avon, UK

Re: multi-distro upgrade script

Unread post by simgin » Wed Apr 22, 2015 4:02 pm

^ 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
Someone told me that I am delusional, I almost fell off my unicorn.

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: multi-distro upgrade script

Unread post by pidsley » Wed Apr 22, 2015 6:05 pm

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.

User avatar
simgin
Meme Fodder
Posts: 1167
Joined: Sun Jan 06, 2013 12:07 am
Location: Bradford-on-Avon, UK

Re: multi-distro upgrade script

Unread post by simgin » Wed Apr 22, 2015 7:03 pm

^ Nice work Pidsley :)
Someone told me that I am delusional, I almost fell off my unicorn.

Post Reply