Newer
Older
tconfigfiles / tconfigfiles
#!/bin/sh
# tconfigfiles - Manage Configuration Files
# Copyright (c) 2007-2013 TundraWare Inc., Des Plaines, IL USA
# All Rights Reserved
# $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
FILES=tree                       # Where tree of individual files lives

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
    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