Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Update Script
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
magillb
n00b
n00b


Joined: 01 Aug 2006
Posts: 4

PostPosted: Tue Aug 01, 2006 1:15 am    Post subject: Update Script Reply with quote

Hello,

I am a gentoo user of 2 months and I am very happy with it.

I update every week or so, and always need to look up the commands. So, I thought I would try my hand at Bash scripting the update process. This very simple script is my first.

The emerge commands are not functional, they only echo to the terminal. The echo need only be removed to make it functional.

Any comments are welcome, on the concept, the scripting, or the emerge flags I am using.

Thanks,

Brett

Code:
#!/bin/bash
#---------------------------------
echo "This script will update your system."
echo "The following commands will be issued:"
echo "     emerge sync"
echo "     emerge -pvDuN world"
echo "     emerge -vDuN world"
echo
echo "You will be prompted before each procedure"
echo
#---------------------------------
super_user="root"
if [ $USER = $super_user ] ; then
   echo "Logged in as root, proceding"
else echo "You must log in as root to quick-update"
   exit
   fi
#---------------------------------
check_with_user ()
{
X=0
while [ $X = 0 ]
do
   echo "Continue with update (yes/no)?"
   read go_on
   if [ $go_on = "yes" ] ; then
      echo "Continuing with update..."
                echo
      X=1
   elif [ $go_on = "no" ] ; then
      echo "Exiting, update not completed."
      exit
   fi
done
}
#--------------------
echo
echo "Ready to begin emerge sync."
check_with_user
echo
echo "emerge sync"
#--------------------
echo
echo "Ready to pretend emerge -vDuN."
check_with_user
echo
echo "emerge -pvDuN world"
#--------------------
echo
echo "Ready to emerge -vDuN."
check_with_user
echo
echo "emerge -vDuN world"
#--------------------
exit
Back to top
View user's profile Send private message
Ma3oxuct
Guru
Guru


Joined: 18 Apr 2003
Posts: 523

PostPosted: Tue Aug 01, 2006 3:01 am    Post subject: Reply with quote

You can simplify your script by using portage's --ask option...

Code:
emerge -DuavN world


It will give you a prompt of yes or no.
Back to top
View user's profile Send private message
magillb
n00b
n00b


Joined: 01 Aug 2006
Posts: 4

PostPosted: Tue Aug 01, 2006 4:35 am    Post subject: Reply with quote

Here is a working update with a few features.

Code:
#!/bin/bash
#Gentoo quick update script
#quick-update.sh
#07/31/06 11:54 CST Version 0.3
#Author: Brett Magill
#---------------------------------
usage ()
{
echo "Usage: quick-update [OPTION]..."
echo "This script will update your system."
echo "The following commands will be issued:"
echo "     emerge sync"
echo "     emerge -pvDuN world"
echo "     emerge -vDuN world"
echo
echo "You will be prompted before each procedure"
echo
echo "Optional arguments"
echo "  -s, --no-sync           skip emerge sync"
echo "  -p, --no-pretend        skip emerge pretend"
echo "  -e, --no-emerge         skip emerge"
echo "  -h, --help              this usage statement"
echo "   --no-ask      do not prompt"
echo
}
check_with_user ()
{
X=0
while [ $X = 0 ]
do
   echo "Continue with update (yes/no)?"
   read go_on
   if [ $go_on = "yes" ] ; then
      echo "Continuing with update..."
                echo
      X=1
   elif [ $go_on = "no" ] ; then
      echo "Exiting, update not completed."
      exit
   fi
done
}
#---------------------------------
no_sync=0
no_pretend=0
no_emerge=0
super_user="root"
no_ask=0
#---------------------------------
while [ "$1" != "" ]; do
    case $1 in
        -s | --no-sync )       no_sync=1
                                ;;
        -p | --no-pretend )    no_pretend=1
                                ;;
        -e | --no-emerge )    no_emerge=1
                                ;;
        --no-ask )            no_ask=1
                                ;;
        -h | --help )           usage
                                exit
                                ;;
        * )                     usage
                                exit 1
    esac
    shift
done
#-----------------------------------
if [ $USER = "root" ] ; then
   echo "Logged in as root, proceding"
else echo "You must log in as root to quick-update"
   exit
   fi
#-----------------------------------
let sum="$no_sync + $no_pretend + $no_emerge"
if [ $sum = 3 ] ; then
   echo
   echo "Nothing to do!  Don't skip all three operations."
   exit
   fi
#--------------------
if [ $no_sync = 0 ] ; then
   echo
   echo "Ready to begin emerge sync."
   if [ $no_ask = 0 ] ; then
      check_with_user
      echo
      fi
   echo "emerge sync"
   emerge sync
else    echo
   echo "Skipping sync..."
   fi
#--------------------
if [ $no_pretend = 0 ] ; then
   echo
   echo "Ready to pretend emerge -vDuN."
   if [ $no_ask = 0 ] ; then
      check_with_user
      echo
      fi
   echo
   echo "emerge -pvDuN world"
   emerge -pvDuN world
else    echo
   echo "Skipping pretend..."
   fi
#--------------------
if [ $no_emerge = 0 ] ; then
   echo
   echo "Ready to emerge -vDuN."
   if [ $no_ask = 0 ] ; then
      check_with_user
      echo
      fi
   echo
   echo "emerge -vDuN world"
   emerge -vDuN world
else    echo
   echo "Skipping emerge..."
   fi
#--------------------
echo "Done!  Be sure to review the output of emerge."
exit
Back to top
View user's profile Send private message
Suicidal
l33t
l33t


Joined: 30 Jul 2003
Posts: 959
Location: /dev/null

PostPosted: Tue Aug 01, 2006 5:30 am    Post subject: Reply with quote

You should add a revdep-rebuild option; my lazy script is something like this:

Code:

#!/bin/bash

     emerge --deep --sync
         
     emerge system
         revdep-rebuild

     emerge -uDN system
          revdep-rebuild

     emerge world
           revdep-rebuild

     emerge -uDN world
            revdep-rebuild


I run it at the end of the day; and check it in the morning.
Back to top
View user's profile Send private message
magillb
n00b
n00b


Joined: 01 Aug 2006
Posts: 4

PostPosted: Wed Aug 02, 2006 1:03 am    Post subject: Reply with quote

OK, how about this. Add revdep option.

Code:
#!/bin/bash
#Gentoo quick update script
#quick-update.sh
#08/01/06 8:00 PM CST Version 0.4
#Author: Brett Magill
#---------------------------------
usage ()
{
echo "Usage: quick-update [OPTION]..."
echo "This script will update your system."
echo "The following commands will be issued:"
echo "     emerge sync"
echo "     emerge -pvDuN world"
echo "     emerge -vDuN world"
echo
echo "You will be prompted before each procedure"
echo
echo "Optional arguments"
echo "  -s, --no-sync           skip emerge sync"
echo "  -p, --no-pretend        skip emerge pretend"
echo "  -e, --no-emerge         skip emerge"
echo "  -h, --help              this usage statement"
echo "  --no-ask                do not prompt"
echo "  --with-revdep           add reverse dependency updating"
echo
}
check_with_user ()
{
X=0
while [ $X = 0 ]
do
   echo "Continue with update (yes/no)?"
   read go_on
   if [ $go_on = "yes" ] ; then
      echo "Continuing with update..."
                echo
      X=1
   elif [ $go_on = "no" ] ; then
      echo "Exiting, update not completed."
      exit
   fi
done
}
#---------------------------------
no_sync=0
no_pretend=0
no_emerge=0
no_ask=0
with_revdep=0
#---------------------------------
while [ "$1" != "" ]; do
    case $1 in
        -s | --no-sync )      no_sync=1
                                ;;
        -p | --no-pretend )   no_pretend=1
                                ;;
        -e | --no-emerge )    no_emerge=1
                                ;;
        --no-ask )            no_ask=1
                                ;;
        --with-revdep )       with_revdep=1
                                ;;
        -h | --help )           usage
                                exit
                                ;;
        * )                     usage
                                exit 1
    esac
    shift
done
#-----------------------------------
if [ $USER = "root" ] ; then
   echo "Logged in as root, proceding"
else   usage
   echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
   echo "!!!!!You must log in as root to quick-update!!!!!"
   echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
   exit
   fi
#-----------------------------------
let sum="$no_sync + $no_pretend + $no_emerge"
if [ $sum = 3 ] ; then
   echo
   echo "Nothing to do!  Don't skip all three operations."
   exit
   fi
#--------------------
if [ $no_sync = 0 ] ; then
   echo
   echo "Ready to begin emerge sync."
   if [ $no_ask = 0 ] ; then
      check_with_user
      echo
      fi
   echo "emerge sync"
   emerge sync
else    echo
   echo "Skipping sync..."
   fi
#--------------------
if [ $no_pretend = 0 ] ; then
   echo
   echo "Ready to pretend emerge -vDuN."
   if [ $no_ask = 0 ] ; then
      check_with_user
      echo
      fi
   echo
   echo "emerge -pvDuN world"
   emerge -pvDuN world
   if [ $with_revdep = 1 ] ; then
      echo "revdep-rebuild -p"
      revdep-rebuild -p
      echo
      fi
   
else    echo
   echo "Skipping pretend..."
   fi
#--------------------
if [ $no_emerge = 0 ] ; then
   echo
   echo "Ready to emerge -vDuN."
   if [ $no_ask = 0 ] ; then
      check_with_user
      echo
      fi
   echo
   echo "emerge -vDuN world"
   emerge -vDuN world
   if [ $with_revdep = 1 ] ; then
      echo "revdep-rebuild"
      revdep-rebuild
      echo
      fi
else    echo
   echo "Skipping emerge..."
   fi
#--------------------
echo "Done!  Be sure to review the output of emerge."
exit
Back to top
View user's profile Send private message
mark_alec
Bodhisattva
Bodhisattva


Joined: 11 Sep 2004
Posts: 6066
Location: Melbourne, Australia

PostPosted: Wed Aug 02, 2006 4:44 am    Post subject: Reply with quote

Moved from Portage & Programming to Unsupported Software. Scripts go here.
Back to top
View user's profile Send private message
magillb
n00b
n00b


Joined: 01 Aug 2006
Posts: 4

PostPosted: Wed Aug 02, 2006 2:20 pm    Post subject: Reply with quote

Hmm...

A request for feedback on a Bash script whose function is related to portage.

Portage and Programming or Unsupported Software?

I choose Portage and Programming. The intent was to get feedback on the bash scritpting as this was my first attempt at it, more than it was to release a script for general use. That said, I used this to update my system last night and it worked quite nicely. I think I will keep it around.

Brett
Back to top
View user's profile Send private message
loftwyr
l33t
l33t


Joined: 29 Dec 2004
Posts: 970
Location: 43°38'23.62"N 79°27'8.60"W

PostPosted: Wed Aug 02, 2006 4:41 pm    Post subject: Reply with quote

Your script looks good but I'm not sure it's really neccessary.

I have emerge --sync as a nightly cron job and that only leaves the emerge -auDvN world as the sole command I need for when I'm ready to update.

This makes sure your portage directory is up to date and only requires one command when you're ready.
_________________
My emerge --info
Have you run revdep-rebuild lately? It's in gentoolkit and it's worth a shot if things don't work well.
Celebrating 5 years of Gentoo-ing.
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