source: tags/confman-1.5.6a5/confmancommon.sh @ 212

Revision 212, 2.8 KB checked in by mattea, 4 years ago (diff)

Tagging fixed symlinking

  • Property svn:keywords set to Id
Line 
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.
15GCONF="/usr/local/rescomp/etc/confman.conf"
16UCONF="${HOME}/.confmanrc"
17MYNAME=`basename $0`
18if [ -z $MY_PID ] ; then
19    MY_PID="$$"
20fi
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.
23if (true >&5) 2>/dev/null ; then
24        exec 4>&2 2>&5 >&3-
25else
26        exec 3>&1
27        exec $0 "$@" 5>&1 1>&3 | logger -t "$MYNAME[$$]: $USER" -s
28        exit ${PIPESTATUS[0]}
29fi
30
31# Get the global config
32if [ -f $GCONF ] ; then 
33        . $GCONF
34else
35        echo "Global config file couldn't be located" >&2
36        exit 1
37fi
38
39if [ -z "$UNAME" ] ; then
40    UNAME=`uname`
41fi
42case $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    ;;
70esac
71
72# Get the user config
73if [ -f $UCONF ] ; then
74        . $UCONF
75fi
76
77# Set debugging:
78if [ -z $DEBUG ] ; then
79        DEBUG="false"
80fi
81
82if [ -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
86fi
87
88# Now, we source the library
89if [ -f $REPO_LIBRARY ] ; then
90        . $REPO_LIBRARY
91else
92        echo "Couldn't source the confman shell library" >&2
93        exit 1
94fi
95
96# Test if the specified group exists before setting folder groups
97if ! [ -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"
104fi
105
106# And the documentation library
107if [ -f $REPO_DOCS ] ; then
108        . $REPO_DOCS
109else
110        echo "Couldn't source the confman shell library" >&2
111        exit 1
112fi
113
114# And we read in the layers that make this host
115if [ -f $RECIPE_PATH ] ; then
116        LAYERS=`cat $RECIPE_PATH | grep "^[^#]"`
117else
118        echo "Couldn't read the host's recipe!" >&2
119        exit 1
120fi
121
122# And we'll set a trap:
123trap "conf_cleanExit" SIGINT SIGTERM SIGHUP
124
Note: See TracBrowser for help on using the repository browser.