| 1 | #! /bin/bash |
|---|
| 2 | |
|---|
| 3 | ## |
|---|
| 4 | # This file is a global include for all confman-based utilities. It |
|---|
| 5 | # provides the common interfaces for loading the shell library, setting |
|---|
| 6 | # up the use of syslog, and reading configurations. |
|---|
| 7 | # |
|---|
| 8 | # Author: Chris Cowart <ccowart@rescomp.berkeley.edu> |
|---|
| 9 | # 4 December 2006 |
|---|
| 10 | # |
|---|
| 11 | # $Id$ |
|---|
| 12 | ## |
|---|
| 13 | |
|---|
| 14 | # Some global definitions. Defaults that can be overriden by options. |
|---|
| 15 | GCONF="/usr/local/rescomp/etc/confman.conf" |
|---|
| 16 | UCONF="${HOME}/.confmanrc" |
|---|
| 17 | MYNAME=`basename $0` |
|---|
| 18 | |
|---|
| 19 | # First things first. Check to see if the logging fd is open. If it's not, |
|---|
| 20 | # we re-spawn confman inside a pipe. |
|---|
| 21 | if (true >&5) 2>/dev/null ; then |
|---|
| 22 | exec 4>&2 2>&5 >&3- |
|---|
| 23 | else |
|---|
| 24 | exec 3>&1 |
|---|
| 25 | exec $0 "$@" 5>&1 1>&3 | logger -t "$MYNAME[$$]: $USER" -s |
|---|
| 26 | exit ${PIPESTATUS[0]} |
|---|
| 27 | fi |
|---|
| 28 | |
|---|
| 29 | # Get the global config |
|---|
| 30 | if [ -f $GCONF ] ; then |
|---|
| 31 | . $GCONF |
|---|
| 32 | else |
|---|
| 33 | echo "Global config file couldn't be located" >&2 |
|---|
| 34 | exit 1 |
|---|
| 35 | fi |
|---|
| 36 | |
|---|
| 37 | # Get the user config |
|---|
| 38 | if [ -f $UCONF ] ; then |
|---|
| 39 | . $UCONF |
|---|
| 40 | fi |
|---|
| 41 | |
|---|
| 42 | # Set debugging: |
|---|
| 43 | if [ -z $DEBUG ] ; then |
|---|
| 44 | DEBUG="false" |
|---|
| 45 | fi |
|---|
| 46 | |
|---|
| 47 | if [ -z "$REPO_DB" ] || [ -z "$CONF_EXPORT_FILE" ] \ |
|---|
| 48 | || [ -z "$CONF_EXPORT_URI" ] || [ -z "$CONF_GROUP" ] ; then |
|---|
| 49 | echo "$GCONF is out-of-date. Please see the ChangeLog" >&2 |
|---|
| 50 | exit 1 |
|---|
| 51 | fi |
|---|
| 52 | |
|---|
| 53 | if ! [ -d "$REPO_DB" ] ; then |
|---|
| 54 | sudo install -d -o root -g $REPO_GROUP -m 770 "$REPO_DB" |
|---|
| 55 | chmod g+s "$REPO_DB" |
|---|
| 56 | fi |
|---|
| 57 | |
|---|
| 58 | # Now, we source the library |
|---|
| 59 | if [ -f $REPO_LIBRARY ] ; then |
|---|
| 60 | . $REPO_LIBRARY |
|---|
| 61 | else |
|---|
| 62 | echo "Couldn't source the confman shell library" >&2 |
|---|
| 63 | exit 1 |
|---|
| 64 | fi |
|---|
| 65 | |
|---|
| 66 | # And the documentation library |
|---|
| 67 | if [ -f $REPO_DOCS ] ; then |
|---|
| 68 | . $REPO_DOCS |
|---|
| 69 | else |
|---|
| 70 | echo "Couldn't source the confman shell library" >&2 |
|---|
| 71 | exit 1 |
|---|
| 72 | fi |
|---|
| 73 | |
|---|
| 74 | # And we read in the layers that make this host |
|---|
| 75 | if [ -f $RECIPE_PATH ] ; then |
|---|
| 76 | LAYERS=`cat $RECIPE_PATH | grep "^[^#]"` |
|---|
| 77 | else |
|---|
| 78 | echo "Couldn't read the host's recipe!" >&2 |
|---|
| 79 | exit 1 |
|---|
| 80 | fi |
|---|
| 81 | |
|---|
| 82 | # And we'll set a trap: |
|---|
| 83 | trap "conf_cleanexit" SIGINT SIGTERM SIGHUP |
|---|
| 84 | |
|---|