Changeset 120


Ignore:
Timestamp:
12/04/2006 01:32:20 (5 years ago)
Author:
ccowart
Message:

Modularized some parts of confman for reuse. Used these elements in the
new roll-and-pull features available.

Location:
trunk/confman
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/confman/Makefile

    r119 r120  
    22PREFIX := $(PREFIX)/rescomp 
    33 
     4DIRFLAGS                =       -d -o root -g wheel -m 0555 
     5EXFLAGS                 =       -Sp -o root -g wheel -m 0555 
     6INFLAGS                 =       -Sp -o root -g wheel -m 0444 
     7 
     8BINFILES                =       abspath 
     9SBINFILES               =       confman 
     10LIBEXECFILES    =       export.sh confsync.sh 
     11LIBFILES                =       confmanlib.sh confmandoc.sh 
     12ENVFILES                =       confman_completions 
     13DIRECTORIES             =       /etc /etc/env.d /lib /sbin /bin /libexec 
     14 
    415install :  
    5         mkdir -p $(PREFIX)/etc/env.d 
    6         mkdir -p $(PREFIX)/lib 
    7         mkdir -p $(PREFIX)/sbin 
    8         mkdir -p $(PREFIX)/bin 
     16.for dir in $(DIRECTORIES) 
     17        install $(DIRFLAGS) ${dir} 
     18.endfor 
     19.for file in $(BINFILES) 
     20        install $(EXFLAGS) ${file} $(PREFIX)/bin/ 
     21.endfor 
     22.for file in $(SBINFILES) 
     23        install $(EXFLAGS) ${file} $(PREFIX)/sbin/ 
     24.endfor 
     25for file in $(LIBEXECFILES) 
     26        install $(EXFLAGS) ${file} $(PREFIX)/libexec/ 
     27.endfor 
     28for file in $(LIBFILES) 
     29        install $(INFLAGS) ${file} $(PREFIX)/lib/ 
     30.endfor 
     31.for file in $(ENVFILES) 
     32        install $(INFLAGS) ${file} $(PREFIX)/etc/env.d/ 
     33.endfor 
     34        install -Sp -o root -g wheel -m 0444 confman.conf \ 
     35                $(PREFIX)/etc/confman.conf-default 
    936        install -Sp -o soluzer -g wheel -m 0444 confmanrc \ 
    1037                /var/home/soluzer/.confmanrc 
    11         install -Sp -o root -g wheel -m 0555 confman $(PREFIX)/sbin/confman 
    12         install -Sp -o root -g wheel -m 0555 abspath $(PREFIX)/bin/abspath 
    13         install -Sp -o root -g wheel -m 0444 confman.conf \ 
    14                 $(PREFIX)/etc/confman.conf-default 
    15         install -Sp -o root -g wheel -m 0444 confmanlib.sh \ 
    16                 $(PREFIX)/lib/confmanlib.sh 
    17         install -Sp -o root -g wheel -m 0444 confmandoc.sh \ 
    18                 $(PREFIX)/lib/confmandoc.sh 
    19         install -Sp -o root -g wheel -m 0444 bash_completions \ 
    20                 $(PREFIX)/etc/env.d/confman_completions 
    2138 
    2239fetch: 
  • trunk/confman/confman

    r117 r120  
    1212# $Id$ 
    1313 
    14  
    15  
    16 # Some global definitions. Defaults that can be overriden by options. 
    17 GCONF="/usr/local/rescomp/etc/confman.conf" 
    18 UCONF="${HOME}/.confmanrc" 
    19 MYNAME=`basename $0` 
    20  
    21 # First things first. Check to see if the logging fd is open. If it's not, 
    22 # we re-spawn confman inside a pipe. 
    23 if (true >&5) 2>/dev/null ; then 
    24         exec 4>&2 2>&5 >&3- 
    25 else 
    26         exec 3>&1 
    27         exec $0 $* 5>&1 1>&3 | logger -t "$MYNAME ($USER)" -s 
    28         exit ${PIPESTATUS[0]} 
    29 fi 
    30  
    31 # Get the global config 
    32 if [ -f $GCONF ] ; then  
    33         . $GCONF 
    34 else 
    35         echo "Global config file couldn't be located" >&2 
    36         exit 1 
    37 fi 
    38  
    39 # Get the user config 
    40 if [ -f $UCONF ] ; then 
    41         . $UCONF 
    42 fi 
    43  
    44 # Set debugging: 
    45 if [ -z $DEBUG ] ; then 
    46         DEBUG="false" 
    47 fi 
    48  
    49 # Now, we source the library 
    50 if [ -f $REPO_LIBRARY ] ; then 
    51         . $REPO_LIBRARY 
    52 else 
    53         echo "Couldn't source the confman shell library" >&2 
    54         exit 1 
    55 fi 
    56  
    57 # And the documentation library 
    58 if [ -f $REPO_DOCS ] ; then 
    59         . $REPO_DOCS 
    60 else 
    61         echo "Couldn't source the confman shell library" >&2 
    62         exit 1 
    63 fi 
    64  
    65 # And we read in the layers that make this host 
    66 if [ -f $RECIPE_PATH ] ; then 
    67         LAYERS=`cat $RECIPE_PATH | grep "^[^#]"` 
    68 else 
    69         echo "Couldn't read the host's recipe!" >&2 
    70         exit 1 
    71 fi 
     14#. /usr/local/rescomp/lib/confmancommon.sh 
     15. $HOME/src/sysadmin/confman/confmancommon.sh 
    7216 
    7317# Set a default editor 
     
    8327# Have to make this less restrictive due to NFS home dirs. 
    8428umask 022 
    85  
    86 # And we'll set a trap: 
    87 trap "conf_cleanexit" SIGINT SIGTERM SIGHUP 
    88  
    8929 
    9030# This function implements the setup subcommand. It is intended to be called 
     
    14888 
    14989                echo "Commit operation started" >&2 
    150                 for layer in $LAYERS ; do 
    151                         conf_commit $layer $msg || return $? 
    152                 done 
     90        conf_commit "$LAYERS" $msg || return $? 
    15391                for layer in $LAYERS ; do 
    15492                        echo "Rolling on $layer..." 
  • trunk/confman/confman.conf

    r100 r120  
    1414 
    1515# The hostname providing our config repository: 
    16 REPO_HOSTNAME="kermit.rescomp.berkeley.edu" 
     16REPO_HOSTNAME="svn.rescomp.berkeley.edu" 
    1717 
    1818# The path on the remote host to find the repository: 
     
    4242DEFAULT_COMMENT="#" 
    4343 
     44# This is the URI for clients to locate the exported working copy. This 
     45# is used by system processes (crons). There are URI handlers for 
     46# file://, http://, https://, ftp://, sftp://, and scp://. Port numbers 
     47# are not handled correctly in sftp and scp URIs. 
     48CONF_EXPORT_FILE="/var/db/confman/export.tgz" 
     49CONF_EXPORT_URI="scp://${REPO_HOSTNAME}${CONF_EXPORT_FILE}" 
     50 
     51# What group should be able to read confman files? 
     52CONF_GROUP="staff" 
     53 
    4454# Enable or disable debugging 
    4555DEBUG="false" 
  • trunk/confman/confmanlib.sh

    r117 r120  
    5555# Commits module $1 with message $2 
    5656function conf_commit { 
    57         local module=$1 
     57        local modules=$(echo $modules | tr ' ' ',') 
    5858        local msg="$2" 
    59         svn commit -F "$msg" ${WORK_PATH}/$module 
     59 
     60    # $modules is in the form foo,bar,baz. This eval trick forces 
     61    # curly brace expansion. 
     62        svn commit -F "$msg" $(eval echo foo/{$modules}) 
     63} 
     64 
     65function conf_fetch { 
     66    local tmpfile=`mktemp -t confman` 
     67    local proto="${CONF_EXPORT_URI%:/*}" 
     68    local remote 
     69 
     70    case $proto in 
     71        sftp|scp)    
     72            remote="${CONF_EXPORT_URI#*://}" 
     73            remote="${remote/\//:/}" 
     74            scp $remote $tmpfile  
     75            ;; 
     76        http|https|ftp) 
     77            fetch -o $tmpfile $remote 
     78            ;; 
     79        file) 
     80            remote="${CONF_EXPORT_URI#*://}" 
     81            cp $remote $tmpfile 
     82            ;; 
     83        *) 
     84            echo "Unsupported Protocol in conf_fetch" >&2 
     85            return 1 
     86            ;; 
     87    esac 
     88    echo $tmpfile 
     89    return 0 
    6090} 
    6191 
     
    6393function conf_status { 
    6494        svn status $* 
     95} 
     96 
     97# This exports a working copy of the repository to a tarball 
     98function conf_export { 
     99    local tmpdir=`mktemp -d -t confman` 
     100    local tarball="$1" 
     101    svn checkout "${REPO_URI}" "${tmpdir}/conf" 
     102    tar -czf "$tarball" -C "$tmpdir" conf 
     103    rm -rf "$tmpdir" 
    65104} 
    66105 
     
    400439} 
    401440 
     441# Accepts log messages on stdin until EOF 
     442function conf_logger { 
     443   cat | logger -t "$MYNAME[$$]: $USER" -s 
     444} 
     445 
    402446# WARNING: If you refer to fd 2 in this code, this function will silently 
    403447# fail when called by trap. DO NOT ATTEMPT TO LOG TO fd 2 IN THIS FUNCTION! 
     
    405449# process, which is receiving its input from our fd 2. 
    406450function conf_cleanexit { 
     451    echo "Confman received a signal. Exiting cleanly." | conf_logger 
    407452        echo "Abort, Abort! Patience is a virtue." >&4 
    408453        echo "Please wait until I finish cleaning up after you." >&4 
    409  
    410         echo "Removing leftover temp files..." >&4 
    411         find /tmp -maxdepth 1 -user `whoami` -name 'confman*' -exec rm -f {} \; 
    412454 
    413455        # And in case we got an interrupt during a rollout, we still want the 
     
    415457        chmod 700 ${WORK_PATH} 
    416458 
     459        echo "Removing leftover temp files..." >&4 
     460        find /tmp -maxdepth 1 -user `whoami` -name 'confman*' -exec rm -rf {} \; 
     461 
    417462        # And this clears any locks we may have created on our working copy: 
    418463        echo "Undoing damage to your working copy..." >&4 
    419         svn cleanup ${WORK_PATH} 
     464        [ -d "${WORK_PATH}" ] && svn cleanup ${WORK_PATH} 
    420465        echo "All clean. Terminating." >&4 
    421466 
Note: See TracChangeset for help on using the changeset viewer.