Renamed variables for clarity, cleaned up / factored code.
Fixed bugs in cfbku and cfinstall that prevented proper operation from
directories other than the canonical source or destination.  Now these
operations work no matter what directory they are issued from.
1 parent 7ab1ae7 commit d04447af4e43977b71a0e7df0d7da3bac958405b
@tundra tundra authored on 12 Feb 2013
Showing 1 changed file
View
44
tconfigfiles
#!/bin/sh
# tconfigfiles - Manage Configuration Files
# Copyright (c) 2007-2013 TundraWare Inc., Des Plaines, IL USA
# All Rights Reserved
# $Id: tconfigfiles,v 1.115 2013/02/13 03:50:15 tundra Exp $
# $Id: tconfigfiles,v 1.116 2013/02/13 04:34:08 tundra Exp $
 
# Where things live
 
CFBASE=${CFBASE:-$HOME/sysgen} # The directory that holds everything below
# Can be overridden with $CFBASE env var
 
ARCHIVES=archives # Where archives go
TREENAME=tree # Where tree of individual files lives
FILES=tree # Where tree of individual files lives
 
TREE="$CFBASE/$TREENAME"
ARCHIVEDIR="$CFBASE/$ARCHIVES"
FILEDIR="$CFBASE/$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 $CFBASE
mkdir -p $ARCHIVES
MACHNAME=`hostname -f`
archdir=$MACHNAME-$TREENAME-$timestamp
cp -pvR $TREENAME $archdir
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
bkudir=$TREE`pwd -P`/
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
targetdir=`pwd -P | sed s?$TREE??`
abspath=`readlink -f $f`
targetdir=`echo $abspath | sed s?$FILEDIR??`
cp -pvR $f $targetdir
done
;;