Changeset 4


Ignore:
Timestamp:
03/15/2006 22:31:33 (6 years ago)
Author:
ccowart
Message:

Implemented some of the more complicated library functions. --cowart

Location:
mgmt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • mgmt/mgmt.conf

    r2 r4  
    1717REPO_LOCAL="`hostname -s`" 
    1818 
    19 # The directory from the roto of the repository to tags: 
    20 REPO_TAGS="tags" 
     19# The directory from the root of the repository to our checkpoints: 
     20REPO_CHECKPTS="checkpoints" 
    2121 
    2222# Where to keep our "working copy" of the system: 
  • mgmt/mgmtlib.sh

    r3 r4  
    1616       svn checkout ${REPO_URI} ${WORK_PATH}/.. 
    1717  else 
    18        svn update ${WORK_PATH}/${REPO_CORE} 
    19        svn update ${WORK_PATH}/${REPO_LOCAL} 
     18       svn update ${WORK_PATH} 
    2019  fi 
    2120 
     
    3332  fi 
    3433 
    35   echo "Still no luck. I'm going to call create_host." >&2 
    36   conf_create_host 
     34  echo "Still no luck. I'm going to call conf_create_module." >&2 
     35  conf_create_module ${REPO_LOCAL} 
    3736} 
    3837 
    3938# Assumes that we already have core setup in our work path. 
    40 function conf_create_host { 
    41   mkdir -p ${WORK_PATH}/${REPO_LOCAL}/{usr/local/,}etc 
    42   svn add ${WORK_PATH}/${REPO_LOCAL} 
    43   svn commit ${WORK_PATH}/${REPO_LOCAL} -m \ 
     39function conf_create_module { 
     40  if [ -z $1 ] ; then return 1 ; fi 
     41  svn mkdir ${WORK_PATH}/$1 
     42  svn mkdir ${WORK_PATH}/${REPO_CHECKPTS}/$1 
     43  svn commit ${WORK_PATH}/${REPO_LOCAL} ${WORK_PATH}/${REPO_CHECKPTS} -m \ 
    4444      "Created directory structure for ${REPO_LOCAL} --`whoami`" 
    4545} 
     
    4848function conf_commit { 
    4949  CPWD=$PWD 
     50  if [ -z $1 ] ; then 
     51          echo "You forgot to specify a module." >&2 
     52          return 1 
     53  fi 
    5054  cd ${WORK_PATH} 
    5155  echo "Type your commit message (escape \\\"double-quotes\\\"):" 
     
    5357  read MESSAGE 
    5458  svn commit -m "${MESSAGE} --`whoami`" $* 
    55   rollout 
     59  for mod in $* ; do  
     60        rollout $mod 
     61  done 
    5662  cd $CPWD 
    5763} 
    5864 
    5965# Roll out the specified module, optionally at the specified checkpoint 
    60 # eg:  rollout MODULE [checkpoint] 
    61 function rollout { 
    62   : 
     66# eg:  conf_rollout MODULE [checkpoint] 
     67function conf_rollout { 
     68  if [ -z $1 ] ; then 
     69          return 1 
     70  fi 
     71  module="$1" 
     72  if [ -z $2 ] ; then 
     73          moduledir="${WORK_PATH}/$module" 
     74  else  
     75          moduledir="${WORK_PATH}/checkpoints/${module}/${2}" 
     76  fi 
     77  for directory in `find $moduledir -type d | grep -v "\.svn"` ; do 
     78          livedir=`echo $directory | sed "s:$moduledir::"` 
     79          livedir="/home/ccowart/img${livedir}" 
     80          if [ ! -d $livedir ] ; then 
     81                  mkdir -p $livedir 
     82          fi 
     83  done 
     84  for file in `find $moduledir -type f | grep -v "\.svn"` ; do 
     85          livefile=`echo "$file" | sed "s:$moduledir::"` 
     86          livefile="/home/ccowart/img${livefile}" 
     87          livedir=`dirname $livefile`  
     88          cmd="install -Sp -o root -g wheel -m 0444 $file $livefile" 
     89          echo $cmd 
     90          $cmd 
     91  done 
    6392} 
    6493 
    65 # These functions take care of tagging your current working copy. 
    66 function tag_host { 
    67   tag_generic ${REPO_LOCAL} $1 
     94# This function generates a checkpoint called NAME for the given MODULE. 
     95# eg: conf_new_checkpoint MODULE NAME 
     96function conf_new_checkpoint { 
     97  module=$1 
     98  checkpoint=$2 
     99  chkpath="${WORK_PATH}/${REPO_CHECKPTS}/${module}/${checkpoint}" 
     100  if [ -z $module -o -z $checkpoint ] ; then 
     101          return 1 
     102  fi 
     103  svn copy ${WORK_PATH}/${module} ${chkpath} 
     104  msg="Created a checkpoint, ${checkpoint} for ${REPO_LOCAL} --`whoami`" 
     105  svn commit ${WORK_PATH}/${REPO_CHECKPTS} -m "$msg" 
    68106} 
    69107 
    70 function tag_core { 
    71   tag_generic ${REPO_CORE} $1 
     108# This function will remove the checkpoint NAME from MODULE. 
     109# eg: conf_rm_checkpoint MODULE NAME 
     110function conf_rm_checkpoint { 
     111  module=$1 
     112  checkpoint=$2 
     113  chkpath="${WORK_PATH}/${REPO_CHECKPTS}/${module}/${checkpoint}" 
     114  if [ -z $module -o -z $checkpoint ] ; then  
     115          return 1  
     116  fi  
     117  svn rm ${chkpath} 
     118  msg="Removed the checkpoint ${checkpoint} from ${REPO_LOCAL} --`whoami`" 
     119  svn commit ${WORK_PATH}/${REPO_CHECKPTS} -m "$msg" 
    72120} 
    73121 
    74 function tag_generic { 
    75   if [ -z $2 ] ; then 
    76           echo "You forgot to specify a name for your tag!" >&2 
    77           return 1 
     122# This function will restore the state of your module's working copy to the 
     123# named checkpoint. eg: conf_rollback MODULE NAME 
     124function conf_rollback { 
     125  module=$1 
     126  checkpoint=$2 
     127  modpath="${WORK_PATH}/${module}" 
     128  chkpath="${WORK_PATH}/${REPO_CHECKPTS}/${module}/${checkpoint}" 
     129  if [ -z $module -o -z $checkpoint ] ; then  
     130          return 1  
    78131  fi 
    79   if [ -d ${WORK_PATH}/${REPO_TAGS}/${1}-${2} ] ; then 
    80           svn rm ${WORK_PATH}/${REPO_TAGS}/${1}-${2} 
    81   fi 
    82   svn copy ${WORK_PATH}/${1} ${WORK_PATH}/${REPO_TAGS}/${1}-${2} 
    83   echo "Don't forget to commit!" 
     132  svn rm ${WORK_PATH}/${module} 
     133  svn update ${WORK_PATH}/${module} 
     134  svn commit -m "Removing ${module} for rollback ==`whoami`" $modpath 
     135  svn copy $chkpath $modpath 
     136  msg="Rolled ${module} back to checkpoint ${checkpoint}" 
     137  echo $msg | conf_commit $module 
    84138} 
    85139 
    86140 
    87  
    88  
Note: See TracChangeset for help on using the changeset viewer.