summaryrefslogtreecommitdiff
path: root/src/pmdas/logger/Install
blob: 10deb91514d97658efdccfebb5c39baa6f244fd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#! /bin/sh
#
# Copyright (c) 2011-2012 Red Hat.
# Copyright (c) 1997 Silicon Graphics, Inc.  All Rights Reserved.
# 
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
# 
# Install the logger PMDA and/or PMNS
#

. $PCP_DIR/etc/pcp.env
. $PCP_SHARE_DIR/lib/pmdaproc.sh

iam=logger
pmda_interface=5
forced_restart=false

pmdaSetup

# be careful that mortals cannot write any configuration files, as
# these would present a security problem
#
umask 022

# PMDA variables
#
configfile=""

_parsedefaults()
{
    echo "Extracting options from current installation ..."
    while getopts D:d:l c
    do
    	case $c in
	    \?)		echo "Warning: Unrecognized option in $PCP_PMCDCONF_PATH"
			echo "	       Remove line for the $iam PMDA in $PCP_PMCDCONF_PATH and re-run ./Install"
	    		exit 2;;
	    * )		;;
	esac
    done
    eval configfile='$'$OPTIND
}

# Get logfile(s) to monitor
if $do_pmda
then
    # set options from $PCP_PMCDCONF_PATH, if possible
    #
    ans=`$PCP_AWK_PROG <$PCP_PMCDCONF_PATH '
$1 == "'$iam'"	{ printf "%s",$6
		  for (i=7;i<=NF;i++) printf " %s",$i
		  print ""
	        }'`
    if [ ! -z "$ans" ]
    then
	_parsedefaults $ans
    fi

    # go figure out which configuration file to use ...
    #
    #default_configfile=./sample.conf
    default_configfile=''
    pmdaChooseConfigFile
    if [ ! -f "$configfile" ]
    then
	$PCP_ECHO_PROG $PCP_ECHO_N "Do you wish to enter logfile names and paths manually? [y] ""$PCP_ECHO_C"
	read ans
	if [ "X$ans" = "Xy" -o "X$ans" = "XY" -o -z "$ans" ]
	then
	    configfile="$configdir/$iam.conf"
	    if [ -f "$configfile" ]
	    then
		    echo "Removing old configuration file \"$configfile\""
		    rm -f "$configfile"
		    if [ -f "$configfile" ]
		    then
			    echo "Cannot remove \"$configfile\""
			    exit 1
		    fi
	    fi

	    echo
	    echo \
'Enter the PMNS name and logfile path.  If the  path ends in "|", the
filename is interpreted as a command which will output data.

An empty line terminates the logfile selection process and there must
be at least one logfile specified.  '

	    args=""
	    touch "$configfile"
	    if [ ! -f "$configfile" ]
	    then
		echo "Installation aborted."
		exit 1
	    fi

	    while [ ! -s "$configfile" ]
	    do
		while true
		do
		    $PCP_ECHO_PROG $PCP_ECHO_N "Logfile PMNS name: ""$PCP_ECHO_C"
		    read name
		    [ -z "$name" ] && break

		    # Check name for invalid chars.
		    if ! echo $name | grep "^[A-Za-z][_A-Za-z0-9]*$" > /dev/null
		    then
			echo \
"Invalid characters in PMNS name: \"$name\".
Names must start with an alphabetic character ([a-zA-Z]).  The rest of
the characters in the name must be alphanumeric ([a-zA-Z0-9]) or an
underscore ('_')."
			continue
		    fi

		    # Make sure name isn't already in the logfile.
		    if grep "^${name}[ \t]" "$configfile" >/dev/null
		    then
			echo "Sorry, logfile PMNS name \"$name\" already specified.  Please try again."
			continue
		    fi

		    $PCP_ECHO_PROG $PCP_ECHO_N "Logfile pathname: ""$PCP_ECHO_C"
		    read pathname
		    [ -z "$pathname" ] && break
		    if grep "[ \t]${pathname}$" "$configfile" >/dev/null
		    then
			echo "Sorry, pathname \"$pathname\" already specified.  Please try again."
			continue
		    fi

		    $PCP_ECHO_PROG $PCP_ECHO_N "Restricted access [n]: ""$PCP_ECHO_C"
		    read restrict
		    if [ "$restrict" = "y" -o "$restrict" = "yes" ]; then
			restrict="y"
		    else
			restrict="n"
		    fi

		    echo "$name $restrict $pathname" >>"$configfile"
		done
	    done
	else
	    echo ""
	    echo "Error: Abandoning installation as no configuration file was specified."
	    exit 1
	fi
    fi

    args="$configfile"
fi

pmdaInstall

exit 0