multi-distro upgrade script
Posted: 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
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