Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

Updating unmodified config files automatically

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
14 posts • Page 1 of 1
Author
Message
Naan Yaar
Bodhisattva
Bodhisattva
Posts: 1549
Joined: Thu Jun 27, 2002 7:06 pm

Updating unmodified config files automatically

  • Quote

Post by Naan Yaar » Thu Aug 29, 2002 4:26 am

When I emerged the new baselayout and was presented with 24 config files to update, I became a little bit tired of updating files that I have not modified since the emerge. I wrote a little script that will find these files by checking md5sums from ebuilds and then updates them automatically or one-by-one.

You can run this before running etc-update to save yourself some work.

NB.
1. This needs gentoolkit to work
2. You need to do this before the old package that installed the config file is cleaned (either through an emerge clean or autoclean)
3. Please make sure that copy/cut-and-paste to the script text file does not remove spaces or modify line-ends.

Code: Select all

#!/bin/bash

# This script checks config files in directories with config files and
# checks whether their checksum matches known checksums in /var/db.
# If a checksum matches, the file has not been modified since the emerge
# and can be overwritten safely.  These files are presented and queried
# for update individually or in one shot
#
# You can run this prior to running etc-update to save some work in updating
# files that you have not touched

strip_config()
{
    echo ${1//._cfg????_/}
}

# check for root
if [ $UID != 0 ]; then
    echo "Got root?"
    exit 1
fi

# check for gentoolkit
needed=gentoolkit
if [ ! -f /usr/bin/qpkg ]; then
    echo "You need to emerge $needed to run this"
    exit 2
fi

# get dir list from config
sourcefiles="/etc/make.globals /etc/profile"
for sourcefile in $sourcefiles; do
    source $sourcefile
    for dir in $CONFIG_PROTECT; do
        [ -d $dir ] && dirs="$dirs $dir"
    done
done

# check for config files with matching checksums
for nf in `find $dirs -iname '._cfg*'`; do
    of=`strip_config $nf`
    for eb in `qpkg -v -nc -f $of`; do
        if grep $of /var/db/pkg/$eb/CONTENTS |
           grep -v ^sym |
           sed 's/obj \([^ ]*\) \([^ ]*\) .*$/\2  \1/g' |
           md5sum -c --status; then
            can_update="$can_update $nf"
        fi
    done
done

# exit if nothing to do
[ -z "$can_update" ] && echo "No files found" && exit 0

# make sure files are listed only once in the update
can_update=`echo $can_update | sed 's/ /\n/g' | sort -u`

# blurb
can_update="`echo $can_update | sort -u`"
echo "The following files have not been modified by you:"
echo
echo `strip_config "$can_update"` | tr ' ' '\n'
echo
echo "You can update the files one by one by typing \"y/n\" or update"
echo "all the remaining by typing \"a\""

# update one by one or all
for nf in $can_update; do
    of=`strip_config $nf`
    [ -z "$all" ] && echo -n "Update ${of}? [Y|n|q|a] " && read ans
    case $ans in
    n|N)
        ;;
    q|Q)break
        ;;
    a|A)echo Moving $nf to $of
        mv -f $nf $of
        all=y
        ans=y
        ;;
    y|Y|*)echo Moving $nf to $of
        mv -f $nf $of
        ;;
    esac
done
exit 0
EDIT (rac): incorporated puddpunk's suggestion of checking UID against 0 instead of USER against root.
EDIT(Naan Yaar):03/12/04: Updated to include Yak's suggestion and previous fix for missing pkglist.
Last edited by Naan Yaar on Sat Mar 13, 2004 4:53 am, edited 5 times in total.
Top
kirill
Apprentice
Apprentice
User avatar
Posts: 183
Joined: Thu Aug 01, 2002 11:18 pm
Location: Finland

Re: Updating unmodified config files automatically

  • Quote

Post by kirill » Thu Aug 29, 2002 8:32 pm

Naan Yaar wrote:When I emerged the new baselayout and was presented with 24 config files to update, I became a little bit tired of updating files that I have not modified since the emerge. I wrote a little script that will find these files by checking md5sums from ebuilds and then updates them automatically or one-by-one.

You can run this before running etc-update to save yourself some work.

NB.
1. This needs gentoolkit to work
2. Lightly tested. YMMV.
The script is not quite working here:

Code: Select all

 * GNU info directory index is up-to-date.
 * IMPORTANT: 22 config files in /etc need updating.
 * Type emerge --help config to learn how to update config files.

Code: Select all

# ./etc-force-update
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
md5sum: standard input: no properly formatted MD5 checksum lines found
No files found
exactly as many times as many new config files I have

I also ran this:

Code: Select all

# qpkg -c -v baselayout
sys-apps/baselayout-1.8.2 *
/etc/devfsd.conf !md5! !mtime!
/etc/fstab !md5! !mtime!
/etc/group !md5! !mtime!
/etc/hosts !md5! !mtime!
/etc/inputrc !md5! !mtime!
/etc/profile !md5! !mtime!
/etc/rc.conf !md5! !mtime!
/etc/services !md5! !mtime!
/etc/conf.d/local.start !md5! !mtime!
/etc/conf.d/net !md5! !mtime!
/etc/init.d/bootmisc !md5! !mtime!
/etc/init.d/checkfs !md5! !mtime!
/etc/init.d/checkroot !md5! !mtime!
/etc/init.d/consolefont !md5! !mtime!
/etc/init.d/halt.sh !md5! !mtime!
/etc/init.d/keymaps !md5! !mtime!
/etc/init.d/modules !md5! !mtime!
/etc/init.d/net.eth0 !md5! !mtime!
/etc/init.d/net.ppp0 !md5! !mtime!
/etc/init.d/netmount !md5! !mtime!
/etc/skel/.bash_profile !md5! !mtime!
/etc/skel/.bashrc !md5! !mtime!
22/236
is that my configuration or the script which b0rks?:(
--kirill
Top
Naan Yaar
Bodhisattva
Bodhisattva
Posts: 1549
Joined: Thu Jun 27, 2002 7:06 pm

  • Quote

Post by Naan Yaar » Thu Aug 29, 2002 8:42 pm

kirill,

I'll follow up with PM's and post the resolution to the forum since I don't want to clutter up the documentation thread.

[EDIT]PM exchanges determined that the cut-and-paste to a file changed the two spaces between \2 and \1 above into a single space, causing md5sum to fail. Adding warning to original post above regarding this.
Thanks, kirill[/EDIT]
Top
puddpunk
l33t
l33t
User avatar
Posts: 680
Joined: Sat Jul 20, 2002 11:07 pm
Location: New Zealand

  • Quote

Post by puddpunk » Wed Nov 20, 2002 6:28 am

The script doesn't work if I'm SU'd :\

I just changed the line:

Code: Select all

if [ $USER != root ]; then
to

Code: Select all

if [ $UID != 0 ]; then
and it worked fine.

Great script, thanks man :)
Top
ales
n00b
n00b
User avatar
Posts: 19
Joined: Wed Nov 20, 2002 1:48 pm

  • Quote

Post by ales » Thu Nov 21, 2002 8:20 am

how exactly is this script suppose to be run?

" (either through an emerge clean or autoclean) " ?

maybe an example please...

(BTW.. i just finished the Stage2 and am about to do the stage 3)

plus if I copy and paste it... i get a bunch of these at the end of each line (viewing it in nano)..

Code: Select all

^M
which didn't make the script work... had to delete each one of those.. for it to properly tell me that "gentoolkit is required"

but after emerging gentoolkit, (before going to stage 3) I now get the following:

Code: Select all

 
: command not found
: command not found
: command not found
: command not found
: command not found
No files found
I'm assuming it probably has something to do with the fact that I'm still at stage 2 ?

this is probably baby sh*t to those who know what they're doing... however, i'm *just* starting out... so any help would be cherished :P


-ales
Top
puddpunk
l33t
l33t
User avatar
Posts: 680
Joined: Sat Jul 20, 2002 11:07 pm
Location: New Zealand

  • Quote

Post by puddpunk » Thu Nov 21, 2002 10:59 pm

yup, finish your install first! :)
Top
sebest
Apprentice
Apprentice
User avatar
Posts: 162
Joined: Wed Jul 03, 2002 10:30 am
Location: Paris - France
Contact:
Contact sebest
Website

  • Quote

Post by sebest » Sun Dec 29, 2002 12:09 am

Hi.

I tryed your script, but i think that the new default behavior of emerge, to clean after emerging brook it.

Because it can removes the old CONTENT file containing the md5 checksum of a current file in /etc. So when i run you script he thinks that i modified the file because there is no CONTENT file containing his checksum.
Top
Naan Yaar
Bodhisattva
Bodhisattva
Posts: 1549
Joined: Thu Jun 27, 2002 7:06 pm

  • Quote

Post by Naan Yaar » Sun Dec 29, 2002 5:11 am

Autoclean is on by default now. You can change this behavior by putting in this line in your /etc/make.conf file:

Code: Select all

AUTOCLEAN="no"
NB. Portage seems to strongly recommend not doing this.
sebest wrote:Hi.

I tryed your script, but i think that the new default behavior of emerge, to clean after emerging brook it.

Because it can removes the old CONTENT file containing the md5 checksum of a current file in /etc. So when i run you script he thinks that i modified the file because there is no CONTENT file containing his checksum.
Top
Yama
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 135
Joined: Sun Jul 21, 2002 4:38 am
Location: Sydney, Australia
Contact:
Contact Yama
Website

  • Quote

Post by Yama » Tue Feb 10, 2004 2:26 am

This script served me flawlessly for quite some time (> 1 year), but now when I run it I receive the following error:

Code: Select all

/usr/local/sbin/etc-autoupdate: line 29: /usr/lib/portage/bin/pkglist: No such file or directory
You need to emerge gentoolkit to run this
This started happening after upgrading my gentoolkit to the latest stable version (0.2.0_pre6). It seems that this version does not have the /usr/lib/portage/bin/pkglist file.
Top
nempo
Guru
Guru
User avatar
Posts: 360
Joined: Tue Apr 16, 2002 8:43 pm
Location: Linkoping, Sweden
Contact:
Contact nempo
Website

  • Quote

Post by nempo » Tue Feb 10, 2004 8:45 am

This is a feature that should be in portage IMO. Maybe you should try to commit it ;)
homeobocks wrote:
superjaded wrote: would Big Brother become a reality?
Yeah . . . it would be just like the tv show. Except somebody would be watching.
Top
Naan Yaar
Bodhisattva
Bodhisattva
Posts: 1549
Joined: Thu Jun 27, 2002 7:06 pm

  • Quote

Post by Naan Yaar » Tue Feb 17, 2004 6:29 pm

Sorry. I haven't been around the forums a lot recently and have updated to the recent portage version only recently. I have attached the modified script below (it is a simple change that checks for qpkg explicitly rather than through pkglist).

Regards.

NB. Code has been updated in the first post to this thread itself and has been removed from this post.
Yama wrote:This script served me flawlessly for quite some time (> 1 year), but now when I run it I receive the following error:

Code: Select all

/usr/local/sbin/etc-autoupdate: line 29: /usr/lib/portage/bin/pkglist: No such file or directory
You need to emerge gentoolkit to run this
This started happening after upgrading my gentoolkit to the latest stable version (0.2.0_pre6). It seems that this version does not have the /usr/lib/portage/bin/pkglist file.
EDIT(Naan Yaar): Removed code and put in consolidated version in the first post.
Last edited by Naan Yaar on Sat Mar 13, 2004 4:56 am, edited 2 times in total.
Top
Yama
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 135
Joined: Sun Jul 21, 2002 4:38 am
Location: Sydney, Australia
Contact:
Contact Yama
Website

  • Quote

Post by Yama » Wed Feb 18, 2004 2:09 pm

Thanks Naan. Your new script appears to work well.
Top
Yak
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 107
Joined: Sun Sep 01, 2002 12:34 am

  • Quote

Post by Yak » Fri Mar 12, 2004 1:34 am

This script has served me well, it's a real time saver. However, awhile back I somehow got about 50 files in /usr/X11R6/lib/X11/xkb that needed updating, and I finally got around to looking at it. It seems that CONFIG_PROTECT is also present in /etc/profile.env which gets read when you source /etc/profile. So I played around a bit and changed the script so it sources /etc/profile too. This worked for what I needed so I thought I would share it. Use it at your own peril.

Code: Select all

# get dir list from config
sourcefiles="/etc/make.globals /etc/profile"
for file in $sourcefiles; do
    echo "List from $file"
    source $file
    for dir in $CONFIG_PROTECT; do
        echo -n "    $dir"
        if [ -d $dir ]; then
            echo "  (directory exists)"
            dirs="$dirs $dir"
        else
            echo "  (not existing dir)"
        fi
    done
done
echo
echo "Dirs list to search: $dirs"
It prints a bunch of extra stuff, I sort of like it so I left it in. I suppose to be complete it should source /etc/make.conf too, but it doesn't seem to work right unless you add an empty CONFIG_PROTECT="" into /etc/make.conf.
Top
Naan Yaar
Bodhisattva
Bodhisattva
Posts: 1549
Joined: Thu Jun 27, 2002 7:06 pm

  • Quote

Post by Naan Yaar » Sat Mar 13, 2004 4:58 am

Yak,

I had noticed that it did not pick up files in .../xkb correctly, but did not investigate further. Thanks for your insight.

I have updated the script in the first post to this thread to reflect this fix.
Yak wrote:This script has served me well, it's a real time saver. However, awhile back I somehow got about 50 files in /usr/X11R6/lib/X11/xkb that needed updating, and I finally got around to looking at it. It seems that CONFIG_PROTECT is also present in /etc/profile.env which gets read when you source /etc/profile. So I played around a bit and changed the script so it sources /etc/profile too. This worked for what I needed so I thought I would share it. Use it at your own peril.
...
It prints a bunch of extra stuff, I sort of like it so I left it in. I suppose to be complete it should source /etc/make.conf too, but it doesn't seem to work right unless you add an empty CONFIG_PROTECT="" into /etc/make.conf.
Top
Post Reply

14 posts • Page 1 of 1

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy