#!/bin/sh
# tconfigfiles - Manage Configuration Files
# Copyright (c) 2007-2013 TundraWare Inc., Des Plaines, IL USA
# All Rights Reserved
# $Id: tconfigfiles,v 1.118 2013/02/13 15:33:42 tundra Exp $
# Where things live
CFREPO=${CFREPO:-$HOME/configfiles} # The directory that holds everything below
# Can be overridden with $CFREPO env var
ARCHIVES=archives # Where archives go
FILES=tree # Where tree of individual files lives
ARCHIVEDIR="$CFREPO/$ARCHIVES"
FILEDIR="$CFREPO/$FILES"
# Make sure the container directories exist
mkdir -p $ARCHIVEDIR
mkdir -p $FILEDIR
# The name used to invoke the program tells us what to do
CMD=`basename $0`
case $CMD
in
"cfarchive") # Make archival copy of current tree
timestamp=`date "+%Y-%m-%d-%H%M%S"`
cd $CFREPO
MACHNAME=`hostname -f`
archdir=$MACHNAME-$FILES-$timestamp
cp -pvR $FILES $archdir
tar -czvf $ARCHIVES/$archdir.tar.gz $archdir
rm -rf $archdir
;;
"cfbku") # Backup configuration files to tree
for f in $*
do
abspath=`readlink -f $f`
bkudir=$FILEDIR`dirname $abspath`/
mkdir -p $bkudir
cp -pvR $f $bkudir
done
;;
"cfinstall") # Install configuration files from tree
for f in $*
do
abspath=`readlink -f $f`
targetdir=`echo $abspath | sed s?$FILEDIR??`
cp -pvR $f $targetdir
done
;;
"tconfigfiles")
INSTALLDIR=`dirname $0`
ln -s $0 $INSTALLDIR/cfarchive
ln -s $0 $INSTALLDIR/cfbku
ln -s $0 $INSTALLDIR/cfinstall
;;
*)
echo "Unknown Command ===> $CMD"
exit 1
;;
esac