| 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 | if [ -z $MY_PID ] ; then |
|---|
| 19 | MY_PID="$$" |
|---|
| 20 | fi |
|---|
| 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 | if [ -z "$REPO_DB" ] || [ -z "$CONF_EXPORT_FILE" ] \ |
|---|
| 50 | || [ -z "$CONF_EXPORT_URI" ] || [ -z "$CONF_GROUP" ] ; then |
|---|
| 51 | echo "$GCONF is out-of-date. Please see the ChangeLog" >&2 |
|---|
| 52 | exit 1 |
|---|
| 53 | fi |
|---|
| 54 | |
|---|
| 55 | # Test if the specified group exists before setting folder groups |
|---|
| 56 | if ! [ -d "$REPO_DB" ] ; then |
|---|
| 57 | if ! [ conf_checkgroup ]; then |
|---|
| 58 | sudo install -d -o root -m 770 "$REPO_DB" |
|---|
| 59 | else |
|---|
| 60 | sudo install -d -o root -g $CONF_GROUP -m 770 "$REPO_DB" |
|---|
| 61 | fi |
|---|
| 62 | sudo chmod g+s "$REPO_DB" |
|---|
| 63 | fi |
|---|
| 64 | |
|---|
| 65 | # Now, we source the library |
|---|
| 66 | if [ -f $REPO_LIBRARY ] ; then |
|---|
| 67 | . $REPO_LIBRARY |
|---|
| 68 | else |
|---|
| 69 | echo "Couldn't source the confman shell library" >&2 |
|---|
| 70 | exit 1 |
|---|
| 71 | fi |
|---|
| 72 | |
|---|
| 73 | # And the documentation library |
|---|
| 74 | if [ -f $REPO_DOCS ] ; then |
|---|
| 75 | . $REPO_DOCS |
|---|
| 76 | else |
|---|
| 77 | echo "Couldn't source the confman shell library" >&2 |
|---|
| 78 | exit 1 |
|---|
| 79 | fi |
|---|
| 80 | |
|---|
| 81 | # And we read in the layers that make this host |
|---|
| 82 | if [ -f $RECIPE_PATH ] ; then |
|---|
| 83 | LAYERS=`cat $RECIPE_PATH | grep "^[^#]"` |
|---|
| 84 | else |
|---|
| 85 | echo "Couldn't read the host's recipe!" >&2 |
|---|
| 86 | exit 1 |
|---|
| 87 | fi |
|---|
| 88 | |
|---|
| 89 | # And we'll set a trap: |
|---|
| 90 | trap "conf_cleanExit" SIGINT SIGTERM SIGHUP |
|---|
| 91 | |
|---|