update_machine (update the config files on a machine)

Note: this is super old, use puppet instead these days...

 

Script: update_machine update_file
We use this simple script (no error checking as usual) to update our machine configuration.
We keep the configuration files in cvs and download them to a new machine.

Usage: update_machine directory root

directory
subdirectory to apply
root
where to apply the files (filesystem root, useful when doing this at kickstart, you can specify root as /mnt/sysimage)

Files are named according to how they are applied to the host system.

.append
contents of file are appended to host system file
.insert
file is created on host filesystem.
.link
a symlink is created on the host filesystem, the link will point to the contents of this file (we put the location we wish to link to in the file
.patch
the file contains patch information that will be applied to the host system file. (we use -p1)
.remove
the host system file is "removed"*
.replace
the host system file is replaced with this one

* We never remove a file, we move file.name to .file.name.original, this way the file will not be read but will still exist if we screwed up.

Example:
[root@surrey scripts]# ./update_machine auth /
/mnt/2WS/scripts/local-2-math/auth /mnt/2WS/scripts/local-2-math
REPLACE /etc/ldap.conf
INSERT /etc/openldap/cacerts/IAS.crt
REPLACE /etc/openldap/ldap.conf
REPLACE /etc/nsswitch.conf
REPLACE /etc/pam.d/system-auth
/mnt/2WS/scripts/local-2-math

 



#!/bin/sh
#variation of rdist, but for use with CVS and for the root filesystem...
# Josko Plazonic
# Kristina Plazonic
# -- start
# Thomas Uphill
# -- add patch and insert types, do directory checking

ROOTFILES=$1
#Must be absolute
FILESYSTEM=$2

pushd $ROOTFILES
for i in `find . -type f -not -path '*CVS*'`; do
# d will be the filename+path without the action suffix
d=`echo $i | cut -b2- | awk -F'.' '{OFS="."; NF=NF-1; print $0}'`
# bd is the base directory of the file
bd=`dirname $d`
# bf is the base filename
bf=`echo $d | awk -F'/' '{print $NF;}'`

case `basename $i` in
*.append)
ACTION=APPEND
;;
*.insert)
ACTION=INSERT
;;
*.link)
ACTION=LINK
;;
*.patch)
ACTION=PATCH
;;
*.remove)
ACTION=REMOVE
;;
*.replace)
ACTION=REPLACE
;;
*)
ACTION=
echo "WARNING! File $d is invalid!"
;;
esac
#Copies of the originals should be called .filename.original
#there are some directories where you don't want to see the originals
if [ "$ACTION" ]; then
#move the original back into location if it exists
if [ -e $FILESYSTEM/$bd/.$bf.original ]; then
rm -f $FILESYSTEM/$d
mv $FILESYSTEM/$bd/.$bf.original $FILESYSTEM/$d
fi
#make the container directory if it doesn't exist
if [ ! -e $FILESYSTEM/$bd ]; then
echo creating $FILESYSTEM/$bd
mkdir -p $FILESYSTEM/$bd
fi
echo "$ACTION $d"
case $ACTION in
APPEND)
cp -a $FILESYSTEM/$d $FILESYSTEM/$bd/.$bf.original
cat $i >> $FILESYSTEM/$d
;;
INSERT)
if [ -e $FILESYSTEM/$d ]; then
echo $INSERT over existing $d, use force
fi
cp -a $i $FILESYSTEM/$d
;;
PATCH)
cp -a $FILESYSTEM/$d $FILESYSTEM/$bd/.$bf.original
patch $FILESYSTEM/$d $i
;;
REMOVE)
mv $FILESYSTEM/$d $FILESYSTEM/$bd/.$bf.original >/dev/null 2>&1
;;
REPLACE)
mv $FILESYSTEM/$d $FILESYSTEM/$bd/.$bf.original >/dev/null 2>&1
cp -a $i $FILESYSTEM/$d
;;
LINK)
if [ -e $FILESYSTEM/$d ]; then
echo link over existing $d backup first
mv $FILESYSTEM/$d $FILESYSTEM/$bd/.$bf.original
fi
ln -sf `cat $i` $FILESYSTEM/$d
;;
esac
fi
done
if [ -f "postinstall" ]; then
echo Executing postinstall
bash -x postinstall
fi
popd

About the Author...

Slides from LISA 2019 Linux systems troubleshooting #LISA2019 https://t.co/D4dMKflK6R Tue Oct 29 05:59:30 +0000 2019

https://t.co/AGeihMALAv configuring grub2 with EFI Fri Sep 13 05:20:01 +0000 2019

I published a Thing on @thingiverse! https://t.co/IYpRyEb7Hz #thingalert Tue Jul 23 19:27:57 +0000 2019

Nokogiri install on MacOSX https://t.co/v3An0miW9L Fri Jul 12 15:06:49 +0000 2019

HTML email with plain mailer plugin on Jenkins https://t.co/Z6FSDMDjy8 Thu Jul 11 21:07:25 +0000 2019