Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
My System Update Script (Work in Progress!)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
IQgryn
l33t
l33t


Joined: 05 Sep 2005
Posts: 764
Location: WI, USA

PostPosted: Thu Mar 12, 2009 3:31 pm    Post subject: My System Update Script (Work in Progress!) Reply with quote

Awhile back, I used to update my system with this one-liner:
Code:
emerge --sync && layman -S && emerge --ask --verbose --update --deep --newuse --with-bdeps=y world && emerge --ask --depclean && revdep-rebuild --ignore --verbose && dispatch-conf && eclean-dist


Needless to say, that became a little too inflexible, so I've written an update script following the same basic process, though with some improvements. It consists of three files (eventually I hope to make it two) stored anywhere you like, as long as they're in the same directory. Being a system update script, it will have to be run as root.

update.sh:
Code:
#!/bin/bash

# Options:
# -s --sync            runs an emerge --sync to start off
#   Optional parameter: minimum time between syncs (default 24h)
# TODO: implement this!
# --fix-permissions      fixes overlay and /etc/portage permissions to be readable by portage group

function cleanup {
   echo "Received interrupt. Exiting..."
   exit 130
}

trap cleanup SIGINT

function abort {
   echo "$1"
   exit 1
}

# Parses the command line options with getopt
OPTS=`getopt -o s:: --long sync:: -n $(basename $0) -- "$@"`

eval set -- "$OPTS"

while true
do
   case "$1" in
      -s|--sync)
         case "$2" in
            "") SYNC_INTERVAL=24; shift 2;;
            *[!0-9]*) abort "Sync interval must be a non-negative integer" ;;
            *) SYNC_INTERVAL="$2"; shift 2;;
         esac;;
      --) shift; break;;
      *) abort "Error: argument \"$1\" not recognized" ;;
   esac
done

sync_overlays () {
   if ! which layman > /dev/null 2>&1
   then
      echo "Layman not found; skipping overlay sync."
      return
   fi
   
   if ! layman -S
   then
      abort "Overlay sync failed."
   fi
   
   # TODO: Add options check here
   if ! ( chown -R root:portage /usr/portage/local/layman/ && chmod -R g+r /usr/portage/local/layman/ &&
   find /usr/portage/local/layman/ -type d -exec chmod g+x '{}' '+' )
   then
      abort "Updating overlay permissions failed."
   fi
}

sync () {
   if ([ "$(( $(( `date +%s` - `date -r /usr/portage +%s` )) / 3600 ))" -ge $SYNC_INTERVAL ]) then
      if ! emerge --sync
      then
         abort "Sync failed."
      fi
      
      sync_overlays
   fi
}

if ! [ -z $SYNC_INTERVAL ]
then
   sync $SYNC_INTERVAL
fi

function call_subshell {
   bash --init-file `dirname $0`/update-bashrc
}

function check_elog_notices {
   if [ -d /var/log/portage/elog ]
   then
      logfiles="/var/log/portage/elog/*"
      numfiles=`echo $logfiles | wc -w`
      currentfile=0
      for i in $logfiles
      do
         currentfile=$(( currentfile + 1 ))
         if [ -f "$i" ]
         then
            while true
            do
               echo
               echo
               echo "Displaying '$i' ($currentfile of $numfiles):"
               cat "$i"

               echo -n "Would you like to delete '$i'? "
               read response
               case "$response" in
                  [Yy] | [Yy][Ee][Ss] ) rm "$i"; break ;;
                  [Nn] | [Nn][Oo] )
                     while true
                     do
                        echo -n "Would you like a shell? "
                        read response
                        case "$response" in
                           [Yy] | [Yy][Ee][Ss] ) call_subshell; break ;;
                           [Nn] | [Nn][Oo] ) break 2 ;;
                           * ) echo "'$response' not understood" ;;
                        esac
                     done ;;
                  * ) echo "'$response' not understood" ;;
               esac
            done
         else
            if [ "$i" == "/var/log/portage/elog/*" ]
            then
               echo "No elog files found."
            else
               echo "'$i' is not a regular file, skipping."
            fi
            echo
         fi
      done
   else
      echo "/var/log/portage/elog does not exist or is not a directory."
      return 1
   fi
}

while ! which revdep-rebuild > /dev/null 2>&1
do
   echo -n "Revdep-rebuild not found.  Would you like to install gentoolkit now [Y/n]? "
   read install
   case "${install:-Y}" in
      [nN] | [nN][oO] ) break ;;
      [yY] | [yY][eE][sS] ) emerge gentoolkit || abort "Failed to install gentoolkit." ;;
      * ) echo "Response '$install' not understood" ;;
   esac
done

emerge --ask --verbose --update --deep --newuse --with-bdeps=y world || abort "Update failed."

if ! [ -f /usr/src/linux/.config ]
then
   newversion=`readlink /usr/src/linux | sed -e 's/linux-//'`
   currentversion=`uname -r`
   installedversion="`grep 'Linux kernel version:' /boot/config | sed -e 's/.*: //'``grep 'CONFIG_LOCALVERSION=' /boot/config | sed -e 's/.*"\([^"]*\)"/\1/'`"
   while true
   do
      echo -n "Unconfigured kernel ($newversion) found. (Running version is $currentversion, latest installed version is $installedversion). Configure now [Y/n]? "
      read updatekernel
      case "${updatekernel:-Y}" in
         [nN] | [nN][oO] )   break ;;
         [yY] | [yY][eE][sS] )   `dirname $0`/update-kernel; break ;;
         * )   echo "Response '$updatekernel' not understood" ;;
      esac
   done
fi

check_elog_notices

emerge --ask --depclean || abort "Depclean failed."

if which revdep-rebuild > /dev/null 2>&1
then
   revdep-rebuild --ignore --verbose || abort "Revdep-rebuild failed."
else
   echo "Revdep-rebuild not found; skipping.  It is recommended to install gentoolkit to ensure reverse dependencies have not been broken."
fi

echo
check_elog_notices

dispatch-conf || abort "Dispatch-conf failed."

eclean-dist || abort "Eclean failed."


update-kernel.sh:
Code:
#!/bin/bash
# TODO: add (better) error handling and comments

env-update && source /etc/profile && source .bash_profile

umask 022

echo -n "New kernel source directory [${1:-/usr/src/linux}]: "
read sourcedir
while ! cd "${sourcedir:-${1:-/usr/src/linux}}"
do
   echo -n "New kernel source directory [${1:-/usr/src/linux}]: "
   read sourcedir
done

echo -n "Old kernel config file (symlinks will be dereferenced) [${2:-/boot/config}]: "
read oldconfig
while ! cp -L "${oldconfig:-${2:-/boot/config}}" .config
do
   echo -n "Old kernel config file (symlinks will be dereferenced) [${2:-/boot/config}]: "
   read oldconfig
done

make oldconfig

while true
do
   echo -n "Run menuconfig [N/y]? "
   read menuconfig
   case "${menuconfig:-N}" in
      [nN] | [nN][oO] )   break ;;
      [yY] | [yY][eE][sS] )   make menuconfig ;;
      * )   echo "Response '$menuconfig' not understood" ;;
   esac
done

make

source /etc/profile

while true
do
    echo -n "Install new kernel? [Y/n]? "
    read install
    case "${install:-Y}" in
   [nN] | [nN][oO] )   break ;;
   [yY] | [yY][eE][sS] )   make modules_install && module-rebuild -X rebuild && make install && break ;;
   * ) echo "Response '$install' not understood" ;;
    esac
done


update.bashrc:
Code:
[ -f ~/.bashrc ] && . ~/.bashrc

export PS1="(update) $PS1"


The first two need to be executable.

Having said all that, there are still a lot of changes to be made. This script works well with my system, but I need to make it more general. It should be safe to run on any Gentoo system, it'll just abort a lot if you don't have certain programs installed.

I welcome comments, suggestions, and ideas
Back to top
View user's profile Send private message
IQgryn
l33t
l33t


Joined: 05 Sep 2005
Posts: 764
Location: WI, USA

PostPosted: Fri Mar 13, 2009 10:20 pm    Post subject: Reply with quote

So I've seen over a hundred views with no responses. Perhaps I should explain the goals of this script.

It's intended to be run as often as you like, and will update (I believe) the entire system. If it detects a new kernel source installed, it attempts to compile and install a new version (with user guidance and oversight). If elog is set up, it displays each log file, with the option to delete the file or start a shell. Then, it strips out any unused software and runs revdep-rebuild to make sure there are no library issues (and re-checks for log files in case something gets re-installed). Finally, it runs eclean-dist to clean out old and unused distfiles.

The kernel bit probably only works properly if you have Grub set up the way I do, but I'd be willing to try and generalize that if I had some feedback as to what it needs to do differently. I'd like to add a way for genkernel to be used with it also.

Eventually, I'd like it to have parameters to exclude whatever parts of the script you don't want to run. I'm still deciding whether it should run everything by default or not. I'd also like to combine the update-kernel script with the main update script, but without losing the ability to just update a kernel if I want.

I'd really welcome any feedback, even if it's just "here's something that already does that, stop wasting your time" :?
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Sat Mar 14, 2009 1:53 am    Post subject: Reply with quote

IQgryn wrote:
So I've seen over a hundred views with no responses. Perhaps I should explain the goals of this script.
...
I'd really welcome any feedback, even if it's just "here's something that already does that, stop wasting your time" :?
Well, actually there is something which does all of this (and quite a bit more) except the update kernel part. Perhaps you can join the dev here to incorporate any new ideas you have:
https://forums.gentoo.org/viewtopic-t-546828-highlight-.html
_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum