View previous topic :: View next topic |
Author |
Message |
Balthasar n00b
Joined: 25 May 2003 Posts: 62 Location: Florida
|
Posted: Sun May 25, 2003 7:26 pm Post subject: A small script to update your system |
|
|
Steps to setup updatesystem script,
1) nano -w /usr/bin/updatesystem (as root)
2) Paste the below code into file
3) Save, chmod +x /usr/bin/updatesystem
4) Run updatesystem command as root.
Code: |
#! /bin/bash
# Check to see if root
if [ $UID -ne 0 ]; then
echo "You need to be root to continue."
echo "Please login as root and run this script again."
echo
exit
else
echo "You are root, good."
fi
echo
echo Rsyncing
echo
emerge rsync
emerge -up world
echo
echo Take a look and press enter to continue with the update, or press Control-C to cancel
echo
read $foo
emerge -u world
echo
echo Your system is now up to date
echo Please check your configs
echo
etc-update
echo
echo Thank you.
echo
|
Just figured I'd post this since it gets me updating more, figured it might help some others stay more up to date, feel free to post any suggestions.
I suppose you could even add this to a cron job if you really wanted. |
|
Back to top |
|
|
TheQuickBrownFox n00b
Joined: 08 Oct 2002 Posts: 37
|
Posted: Sun May 25, 2003 8:43 pm Post subject: |
|
|
Cool. Simple, but cool.
Personally, I would make a couple of changes like Code: |
emerge sync >/dev/null
|
Does anyone check the output?
I'd like to know what changed. The changelogs are mostly not very informative though.
Code: |
emerge -u world 2>&1|tee -a /var/log/emerge_world.log
|
Again, too much output. Who sits around watching the output of kde/OpenOffice building anyway? I would like to be able to redirect all stdout to file and all errors and info messages to screen, but AFAIK the info messages are also printed to stdout, so that won't work. _________________ -- jumps over the lazy dog |
|
Back to top |
|
|
Gibberx Apprentice
Joined: 20 Oct 2002 Posts: 217 Location: UMBC
|
Posted: Sun May 25, 2003 9:13 pm Post subject: |
|
|
Sounds nice, but I have "ACCEPT_KEYWORDS=~x86" in my /etc/make.conf file... I think I'd be asking for trouble to just "emerge -u world" whenever I pleased. I'd also be doing a lot of updating, too! |
|
Back to top |
|
|
Woland Apprentice
Joined: 02 Aug 2002 Posts: 248 Location: Russian Jack, Alaska
|
Posted: Mon May 26, 2003 2:01 am Post subject: |
|
|
I wrote this shell script and then sent it into my cron.daily directory. While there, it will sync my portage tree every other day (as is recomended) and will email me a list of packages that need updating. Then it is up to me what or when to update:
Code: |
#This script will run emerge sync every other day.
#First, determine whether this is an odd or even day
#this script will run only on even days (will skip
#Dec. 31-Jan.1
#First line returns the day of the year from the 'date' command
#and sets that as a variable
DAY=`date +%j`
#This defines a variable whose value is zero if the day is even,
#and one if the day is odd.
ON_DAY=`expr $DAY % 2`
if [ $ON_DAY = 0 ];
then
emerge sync > /dev/null;
emerge -pU --deep world | mail -s \
"`awk -F. '{ print $1 }' /etc/hostname` packages that \
needed updating as of `date +%A`" root;
fi
|
Oh yes, you need to have emegred mailx for this to work. Mailx should be part of the default system packages, but it is not.
Last edited by Woland on Mon May 26, 2003 6:25 am; edited 1 time in total |
|
Back to top |
|
|
Balthasar n00b
Joined: 25 May 2003 Posts: 62 Location: Florida
|
Posted: Mon May 26, 2003 5:14 am Post subject: |
|
|
As for the ~x86, I have it as well, and I normally have no problems.. So use at your own risk |
|
Back to top |
|
|
Bl4cKH4T n00b
Joined: 19 Dec 2002 Posts: 11
|
Posted: Fri May 30, 2003 11:12 am Post subject: |
|
|
This is my update script:
Code: |
#!/bin/bash
emerge sync
emerge world -pu --deep
echo ""
echo update world? [y/n]:
read update
if [ $update = "n" ]; then
echo Nothing to do, exiting.
echo ""
exit
else
if [ $update = "y" ]; then
echo build precompiled packages? [y/n]:
read pkg
if [ $pkg = "y" ]; then
emerge world -ub --deep
else
emerge world -u --deep
fi
fi
fi
|
_________________ gentoo pr0n:
#emerge world -fu --deep |
|
Back to top |
|
|
amne Bodhisattva
Joined: 17 Nov 2002 Posts: 6378 Location: Graz / EU
|
Posted: Fri May 30, 2003 12:19 pm Post subject: Re: A small script to update your system |
|
|
Balthasar wrote: |
1) nano -w /usr/bin/updatesystem (as root)
3) Save, chmod +x /usr/bin/updatesystem
|
wouldn't /usr/local/bin be a more appropriate place for this? |
|
Back to top |
|
|
Woland Apprentice
Joined: 02 Aug 2002 Posts: 248 Location: Russian Jack, Alaska
|
Posted: Fri May 30, 2003 10:30 pm Post subject: |
|
|
Or better yet, put it in /root/bin; and get rid of the whole first part which checks if you are root: emerge sync will return an error anyway if a non-root user is doing it.
Of course, I am prejudiced to putting into to a root crontab, and never again having to worry about running it manualy. A good sysadmin is a lazy sysadmin---just make sure its the right kind of lazy. |
|
Back to top |
|
|
incubus n00b
Joined: 12 Dec 2002 Posts: 20 Location: Sheffield, UK
|
Posted: Sat May 31, 2003 6:20 am Post subject: |
|
|
I just use this in cron; it emails me every day for each of the gentoo boxes that I administer. I prefer it this way, so I know how behind I'm getting
Code: |
#!/bin/bash
## Outdated Package Report
# for {hostname}
echo "From: {domain} Package Monitor <admin@{domain}>"
echo "To: {domain} Systems Administrators <admin@{domain}>"
echo "Subject: {hostname} outdated package report"
echo "Date: `/bin/date -R`"
echo
echo "{hostname} outdated package report"
echo "=============================================="
echo
/usr/bin/emerge -pu world | /bin/grep "\[ebuild" | /usr/bin/wc -l | /bin/sed 's/^[ \t]*//' | /bin/awk {'print "Attention: "$1" Packages are outdated and need upgrading."'}
echo
echo "If you need to update any packages, log in as root and perform the following:"
echo
echo "# emerge -u world"
echo
echo "Regards,"
echo "The {domain} Package Monitor."
|
Hope that is of some use to some of you ... _________________ Drink like it's payday |
|
Back to top |
|
|
Bl4cKH4T n00b
Joined: 19 Dec 2002 Posts: 11
|
Posted: Sat May 31, 2003 11:49 am Post subject: |
|
|
You could use hostname='cat /etc/hostname' instead of {hostname}
This way you won't have to edit this file on every system you install it.
note: use backsticks instead of '. Mozilla doesn't seem to support them here _________________ gentoo pr0n:
#emerge world -fu --deep |
|
Back to top |
|
|
Woland Apprentice
Joined: 02 Aug 2002 Posts: 248 Location: Russian Jack, Alaska
|
Posted: Sat May 31, 2003 5:07 pm Post subject: |
|
|
Bl4cKH4T wrote: | You could use hostname='cat /etc/hostname' instead of {hostname}
This way you won't have to edit this file on every system you install it.
|
From my script:
Code: | awk -F. '{ print $1 }' /etc/hostname |
You can always store that in say $BOX_NAME if you did not want to type it twice. |
|
Back to top |
|
|
incubus n00b
Joined: 12 Dec 2002 Posts: 20 Location: Sheffield, UK
|
Posted: Sun Jun 01, 2003 1:55 pm Post subject: |
|
|
Bl4cKH4T wrote: | You could use hostname='cat /etc/hostname' instead of {hostname}
This way you won't have to edit this file on every system you install it.
note: use backsticks instead of '. Mozilla doesn't seem to support them here |
Cheers, I'll integrate that, I think.
incubus _________________ Drink like it's payday |
|
Back to top |
|
|
kolla n00b
Joined: 30 May 2003 Posts: 1
|
Posted: Tue Jun 03, 2003 12:13 pm Post subject: |
|
|
incubus wrote: | I just use this in cron; it emails me every day for each of the gentoo boxes that I administer. I prefer it this way, so I know how behind I'm getting
Code: |
#!/bin/bash
## Outdated Package Report
# for {hostname}
echo "From: {domain} Package Monitor <admin@{domain}>"
echo "To: {domain} Systems Administrators <admin@{domain}>"
echo "Subject: {hostname} outdated package report"
echo "Date: `/bin/date -R`"
echo
echo "{hostname} outdated package report"
echo "=============================================="
echo
/usr/bin/emerge -pu world | /bin/grep "\[ebuild" | /usr/bin/wc -l | /bin/sed 's/^[ \t]*//' | /bin/awk {'print "Attention: "$1" Packages are outdated and need upgrading."'}
echo
echo "If you need to update any packages, log in as root and perform the following:"
echo
echo "# emerge -u world"
echo
echo "Regards,"
echo "The {domain} Package Monitor."
|
Hope that is of some use to some of you ... |
Shouldn't there be some emerge sync up in there too?
Unfortunatly, every time I try to run emerge from cron (vixie) I get this:
Code: |
Traceback (most recent call last):
File "/usr/bin/emerge", line 279, in ?
emergelog("Started emerge on: "+time.strftime("%b %d, %Y %H:%M:%S", time.localtime()))
File "/usr/bin/emerge", line 186, in emergelog
xtermTitle(mystr)
File "/usr/lib/python2.2/site-packages/output.py", line 34, in xtermTitle
myt=os.environ["TERM"]
File "/usr/lib/python2.2/UserDict.py", line 14, in __getitem__
def __getitem__(self, key): return self.data[key]
KeyError: TERM
Error in sys.exitfunc:
Traceback (most recent call last):
File "/usr/lib/python2.2/atexit.py", line 20, in _run_exitfuncs
apply(func, targs, kargs)
File "/usr/bin/emerge", line 201, in emergeexit
emergelog(" *** terminating.")
File "/usr/bin/emerge", line 186, in emergelog
xtermTitle(mystr)
File "/usr/lib/python2.2/site-packages/output.py", line 34, in xtermTitle
myt=os.environ["TERM"]
File "/usr/lib/python2.2/UserDict.py", line 14, in __getitem__
def __getitem__(self, key): return self.data[key]
KeyError: TERM
|
I assume this has something to do with emerge using python functions that relies on a non-dumb TERM. Find it kinf of akward that it uses something that tries to alter xtermTitle, but... |
|
Back to top |
|
|
SadMac n00b
Joined: 24 Mar 2003 Posts: 40 Location: Cheltenham, UK
|
Posted: Tue Jun 03, 2003 12:58 pm Post subject: |
|
|
Here's the orig with modifications plus a bit of eye candy
Code: |
#!/bin/bash
source /sbin/functions.sh
YELLOW=$'\e[33;01m'
NORMAL=$'\e[0m'
GREEN=$'\e[32;02m'
echo_info() {
echo -e " ${YELLOW}*${NORMAL} ${*}"
}
echo_question() {
echo -e "${GREEN}${*}${NORMAL}"
}
# Check to see if root
if [ $UID -ne 0 ]; then
echo "You need to be root to continue."
echo "Please login as root and run this script again."
exit
fi
ebegin Syncing with rsync server
emerge rsync >/dev/null
ebegin Running fixpackages
/usr/lib/portage/bin/fixpackages >/dev/null 2>/dev/null
# Don't want this bit unless you have my dodgy package unmasker thingy
# ebegin Unmasking listed packages
# unmasklist.sh >/dev/null
emerge -upl world
echo
echo_question To merge these packages press enter, to stop press Control-C
read $foo
ebegin Running world update
emerge -U world >>/var/log/emerge_world.log 2>>/var/log/emerge_world-errors.log
echo_info System is now up to date
ebegin Running etc-update
echo
etc-update
echo
echo_info Done
|
|
|
Back to top |
|
|
Woland Apprentice
Joined: 02 Aug 2002 Posts: 248 Location: Russian Jack, Alaska
|
Posted: Tue Jun 03, 2003 4:24 pm Post subject: |
|
|
kolla wrote: |
Unfortunatly, every time I try to run emerge from cron (vixie) I get this:
..................
I assume this has something to do with emerge using python functions that relies on a non-dumb TERM. Find it kinf of akward that it uses something that tries to alter xtermTitle, but... |
The man 1 emerge page lists the following option:
Quote: | --nospinner
Disables the spinner for the session. The spinner is active when
the terminal device is determined to be a TTY. This flag dis-
ables it regardless.
|
So in theory, emerge should be able to distinguish between terms. But as I get the same error, appearently it is not doing so. Perhaps a report to Bugzilla may be appropriate? I get teh very same error myself. Its really no big deal---I just delete the second e-mail, but it doesn't feel "clean." |
|
Back to top |
|
|
incubus n00b
Joined: 12 Dec 2002 Posts: 20 Location: Sheffield, UK
|
Posted: Tue Jun 03, 2003 5:34 pm Post subject: |
|
|
kolla wrote: | Shouldn't there be some emerge sync up in there too?
|
Ooops, sorry. I forgot to mention that I have that seperately in cron
kolla wrote: |
Unfortunatly, every time I try to run emerge from cron (vixie) I get this:
Code: |
Traceback (most recent call last):
File "/usr/bin/emerge", line 279, in ?
emergelog("Started emerge on: "+time.strftime("%b %d, %Y %H:%M:%S", time.localtime()))
File "/usr/bin/emerge", line 186, in emergelog
xtermTitle(mystr)
File "/usr/lib/python2.2/site-packages/output.py", line 34, in xtermTitle
myt=os.environ["TERM"]
File "/usr/lib/python2.2/UserDict.py", line 14, in __getitem__
def __getitem__(self, key): return self.data[key]
KeyError: TERM
Error in sys.exitfunc:
Traceback (most recent call last):
File "/usr/lib/python2.2/atexit.py", line 20, in _run_exitfuncs
apply(func, targs, kargs)
File "/usr/bin/emerge", line 201, in emergeexit
emergelog(" *** terminating.")
File "/usr/bin/emerge", line 186, in emergelog
xtermTitle(mystr)
File "/usr/lib/python2.2/site-packages/output.py", line 34, in xtermTitle
myt=os.environ["TERM"]
File "/usr/lib/python2.2/UserDict.py", line 14, in __getitem__
def __getitem__(self, key): return self.data[key]
KeyError: TERM
|
I assume this has something to do with emerge using python functions that relies on a non-dumb TERM. Find it kinf of akward that it uses something that tries to alter xtermTitle, but... |
I'm not sure. It's been working fine forever but my machine at work has started giving similar errors as of this week. A change to portage permissions perhaps? Does vcron drop root privs at any point (and then would need to be in the portage group)? _________________ Drink like it's payday |
|
Back to top |
|
|
deepthought Guru
Joined: 04 Apr 2003 Posts: 321 Location: icbm://5131''N:0710''E
|
Posted: Thu Jun 05, 2003 7:41 am Post subject: |
|
|
incubus wrote: |
I'm not sure. It's been working fine forever but my machine at work has started giving similar errors as of this week. A change to portage permissions perhaps? Does vcron drop root privs at any point (and then would need to be in the portage group)?
|
This issue is related to bug 21703. I attached a small fix to the bug report, which will make it work perfectly again.
Regards,
Alexander _________________ Out of loyalty to its disregarded comrades, this message feels free to ignore the reader.
Registered Linux User #317705 |
|
Back to top |
|
|
deepthought Guru
Joined: 04 Apr 2003 Posts: 321 Location: icbm://5131''N:0710''E
|
Posted: Sun Jun 08, 2003 11:46 am Post subject: |
|
|
The stated problem has been fixed in portage-2.0.48-r1. To upgrade, run
Code: | emerge -u sys-apps/portage |
I will close the bug report or (if I can't do this by myself) notify the assignee to do so.
Regards,
Alexander _________________ Out of loyalty to its disregarded comrades, this message feels free to ignore the reader.
Registered Linux User #317705 |
|
Back to top |
|
|
incubus n00b
Joined: 12 Dec 2002 Posts: 20 Location: Sheffield, UK
|
Posted: Mon Jun 09, 2003 2:29 pm Post subject: |
|
|
Awesome _________________ Drink like it's payday |
|
Back to top |
|
|
crowe n00b
Joined: 11 Jun 2003 Posts: 17 Location: University of Essex, UK
|
Posted: Wed Jun 11, 2003 3:28 pm Post subject: Re: A small script to update your system |
|
|
New to gentoo but impressed so far.
Newbie question: I am going to be using one of the scripts discussed in this thread (I like the one that someone suggested for an every other day emerge sync with email to root) in a cron job. However, is it dangerous to run an emerge <package> while doing an email sync? The kind of thing that I am thinking is that I will run the emerge sync, emerge -pUl --deep world job every other day in cron to remind me (nag me!) to do essential updates, however, I would like the emerge -U <packages...> to run overnight from a manual start (I like to choose the packages to upgrade). Problem with this is that the emerge <packages...> might (will!) run past the start of the emerge sync. I guess this might cause real problems if there are complex package dependencies (e.g. one dependency before the emerge sync which changes on some emerge <package> after the sync.)
What are peoples experience with automated emerge scripts and parrallel emerge sessions, any tips for new users? |
|
Back to top |
|
|
deepthought Guru
Joined: 04 Apr 2003 Posts: 321 Location: icbm://5131''N:0710''E
|
Posted: Thu Jun 12, 2003 7:38 pm Post subject: |
|
|
In general, it is a *bad idea* to run several emerge processes at once.
Think of changed package dependencies after running emerge rsync while an emerge --intriguingoptions -u world is still active.
Regards,
Alexander _________________ Out of loyalty to its disregarded comrades, this message feels free to ignore the reader.
Registered Linux User #317705 |
|
Back to top |
|
|
ozt Apprentice
Joined: 13 Dec 2002 Posts: 212 Location: Stockholm
|
Posted: Fri Jun 13, 2003 7:44 am Post subject: |
|
|
Does anyone of you guys know where I can learn more about bash scripting/programming?
Thanks _________________ = |
|
Back to top |
|
|
deepthought Guru
Joined: 04 Apr 2003 Posts: 321 Location: icbm://5131''N:0710''E
|
|
Back to top |
|
|
NiklasH Apprentice
Joined: 30 Aug 2002 Posts: 211 Location: On top of something
|
Posted: Wed Jun 18, 2003 8:58 am Post subject: |
|
|
Here is a little script I wrote that checks for updates and outputs new packages if there are any.
Put it in /etc/cron.daily, and you will get a daily update in your mail if there are any outdated packages.
Don't forget to set the MAILTO variable in root's crontab (crontab -e, add MAILTO=<your mail address>"
That way you only get a mail if anything has been updated.
I think someone wrote a script like this somewhere, but I couldn't find it. Anyway, this works fine for me, and I hope it might be of use to others.
Code: |
#Syncs the portage tree and outputs any updatable packages.
#Put in /etc/cron.daily/ for daily updates, or smack it into your crontab.
#Don't forget to set MAILTO in your crontab
#and emerge the mailx package.
#
#!/bin/sh
emerge sync > /dev/null 2>&1
PACKAGES=`/usr/bin/emerge -pu world | /bin/grep "\[ebuild"`
COUNT="`/bin/echo $PACKAGES | /bin/wc -w | /bin/sed -e s/\ //g`"
if [ "$COUNT" -ne "0" ] ; then
echo "Subject: Out-of-date packages at $HOSTNAME"
echo
echo "These packages need updating at $HOSTNAME:"
echo
echo "$PACKAGES"
|
I had to use the COUNT variable, as my bash skillz aren't perfected yet... |
|
Back to top |
|
|
|