| 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: confmancommon.sh 1302 2008-01-17 02:55:18Z mattea $ |
|---|
| 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 | if [ -z "$UNAME" ] ; then |
|---|
| 40 | UNAME=`uname` |
|---|
| 41 | fi |
|---|
| 42 | case $UNAME in |
|---|
| 43 | FreeBSD) |
|---|
| 44 | install_cmd="install -Sp" |
|---|
| 45 | mktemp_file="mktemp -t confman" |
|---|
| 46 | mktemp_dir="mktemp -d -t confman" |
|---|
| 47 | sed_cmd="sed -E" |
|---|
| 48 | stat_cmd="stat -f" |
|---|
| 49 | stat_args="mode=%Mp%Lp owner=%Su group=%Sg" |
|---|
| 50 | readlink_cmd="greadlink" |
|---|
| 51 | ;; |
|---|
| 52 | Linux) |
|---|
| 53 | install_cmd="install -p" |
|---|
| 54 | mktemp_file="mktemp -t confman.XXXXXX" |
|---|
| 55 | mktemp_dir="mktemp -t -d confman.XXXXXX" |
|---|
| 56 | sed_cmd="sed -r" |
|---|
| 57 | stat_cmd="stat -c" |
|---|
| 58 | stat_args="mode=%a owner=%U group=%G" |
|---|
| 59 | readlink_cmd="readlink" |
|---|
| 60 | ;; |
|---|
| 61 | *) |
|---|
| 62 | install_cmd="install -Sp" |
|---|
| 63 | mktemp_file="mktemp -t confman" |
|---|
| 64 | mktemp_dir="mktemp -d -t confman" |
|---|
| 65 | sed_cmd="sed -E" |
|---|
| 66 | stat_cmd="stat -f" |
|---|
| 67 | stat_args="mode=%Mp%Lp owner=%Su group=%Sg" |
|---|
| 68 | readlink_cmd="greadlink" |
|---|
| 69 | ;; |
|---|
| 70 | esac |
|---|
| 71 | |
|---|
| 72 | # Get the user config |
|---|
| 73 | if [ -f $UCONF ] ; then |
|---|
| 74 | . $UCONF |
|---|
| 75 | fi |
|---|
| 76 | |
|---|
| 77 | # Set debugging: |
|---|
| 78 | if [ -z $DEBUG ] ; then |
|---|
| 79 | DEBUG="false" |
|---|
| 80 | fi |
|---|
| 81 | |
|---|
| 82 | if [ -z "$REPO_DB" ] || [ -z "$CONF_EXPORT_FILE" ] \ |
|---|
| 83 | || [ -z "$CONF_EXPORT_URI" ] || [ -z "$CONF_GROUP" ] ; then |
|---|
| 84 | echo "$GCONF is out-of-date. Please see the ChangeLog" >&2 |
|---|
| 85 | exit 1 |
|---|
| 86 | fi |
|---|
| 87 | |
|---|
| 88 | # Now, we source the library |
|---|
| 89 | if [ -f $REPO_LIBRARY ] ; then |
|---|
| 90 | . $REPO_LIBRARY |
|---|
| 91 | else |
|---|
| 92 | echo "Couldn't source the confman shell library" >&2 |
|---|
| 93 | exit 1 |
|---|
| 94 | fi |
|---|
| 95 | |
|---|
| 96 | # Test if the specified group exists before setting folder groups |
|---|
| 97 | if ! [ -d "$REPO_DB" ] ; then |
|---|
| 98 | if ! [ conf_checkgroup ]; then |
|---|
| 99 | sudo $install_cmd -d -o root -m 770 "$REPO_DB" |
|---|
| 100 | else |
|---|
| 101 | sudo $install_cmd -d -o root -g $CONF_GROUP -m 770 "$REPO_DB" |
|---|
| 102 | fi |
|---|
| 103 | sudo chmod g+s "$REPO_DB" |
|---|
| 104 | fi |
|---|
| 105 | |
|---|
| 106 | # And the documentation library |
|---|
| 107 | if [ -f $REPO_DOCS ] ; then |
|---|
| 108 | . $REPO_DOCS |
|---|
| 109 | else |
|---|
| 110 | echo "Couldn't source the confman shell library" >&2 |
|---|
| 111 | exit 1 |
|---|
| 112 | fi |
|---|
| 113 | |
|---|
| 114 | # And we read in the layers that make this host |
|---|
| 115 | if [ -f $RECIPE_PATH ] ; then |
|---|
| 116 | LAYERS=`cat $RECIPE_PATH | grep "^[^#]"` |
|---|
| 117 | else |
|---|
| 118 | echo "Couldn't read the host's recipe!" >&2 |
|---|
| 119 | exit 1 |
|---|
| 120 | fi |
|---|
| 121 | |
|---|
| 122 | # And we'll set a trap: |
|---|
| 123 | trap "conf_cleanExit" SIGINT SIGTERM SIGHUP |
|---|
| 124 | |
|---|