File: install

package info (click to toggle)
changetrack 3.7-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 168 kB
  • ctags: 22
  • sloc: perl: 279; sh: 239; makefile: 56
file content (293 lines) | stat: -rwxr-xr-x 7,887 bytes parent folder | download
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/bin/sh
#
# Copyright (C) Cameron J. Morland 2000
#
# 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.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# File Name:          install
#
# Project Name:       changetrack
#
# Module Description: changetrack installation utility
#
# $Revision: 1.3 $
#
# Author:             Cameron J. Morland

# defaults
APPPATH_DEFAULT="/usr/bin"
MANPATH_DEFAULT="/usr/man/man1"
ETCPATH_DEFAULT="/etc"
HISTORYPATH_DEFAULT="/var/state/changetrack"
MAILFROM_DEFAULT="changetrack@localhost"

# override the defaults if we've installed from here before
d=`dirname $0`
if [ -f $d/.config ]; then
    cat <<EOF
Using previous values from $d/.config
Delete that file if you want the factory defaults.
EOF
    . $d/.config
fi

# show the information about the license (whole thing awfully long)
clear
cat gnu_short.txt

echo ""

#
# Asks a question, giving a default value.  The user can either accept the
# default, or enter something else.
#
# Usage:  ask "question" variable_name default_value
#
ask () {
    question="$1"
    variable="$2"
    default="$3"
    echo -n "$question ($default) " 
    result=''
    read response
    if [ -z "$response" ]; then
	result="$default"
    else
	result="$response"
    fi
    eval $variable=$result
}

#
# Like 'ask', but forces the answer to begin with either 'y' or 'n', case-
# insensitive.  The returned value is always either 'yes' or 'no'.
#
# Usage:  yesno "question" variable_name default_value
#
yesno () {
    question="$1"
    variable="$2"
    default="$3"
    echo -n "$question ($default) " 
    result=''
    read response
    if [ -z "$response" ]; then
	result="$default"
    fi
    while [ -z "$result" ]; do
	short=`expr substr "$response" 1 1`
	if [ "$short" = 'y' -o "$short" = 'Y' ]; then
	    result=yes
	elif [ "$short" = 'n' -o "$short" = 'N' ]; then
	    result=no
	else
	    echo -n "please answer 'yes' or 'no': "
	    read response
	fi
    done
    eval $variable=$result
}

#
# Installs a file to it's proper location.  Unlike the install(1) program,
# the full pathname has to be given for the second argument.  At the same
# time as the install, the following strings are substituted:
#
#     %%APPPATH%%
#     %%MANPATH%%
#     %%ETCPATH%%
#     %%HISTORYPATH%%
#
# Usage:  my_install original destination mode
#
my_install () {
    src="$1"
    dst="$2"
    mode="$3"

    # create the destination directory
    dstdir=`dirname $dst`
    if [ ! -d $dstdir ]; then
	yesno "Should I create the directory '$dstdir'?" answer yes
	if [ "$answer" = no ]; then
	    echo "Aborting."
	    exit 1
	fi
	mkdir -p $dstdir
	if [ $? -ne 0 ]; then
	    echo "Failed to create directory '$dstdir'.  Aborting."
	    exit 1
	fi
    fi

    # a bit of paranoia
    if [ -r $dst ]; then
	rm -f $dst
	if [ $? -ne 0 ]; then
	    echo "$dst already existed and I could not delete it."
	    echo "Aborted."
	    exit 1
	fi
    fi

    # copy over the file, doing substitutions as required
    echo "creating $dst"
    escaped_mailfrom=`echo $MAILFROM | perl -pe 's,\@,\\\\@,;'`
    perl -p \
	-e "s,%%APPPATH%%,$APPPATH,g;" \
	-e "s,%%MANPATH%%,$MANPATH,g;" \
	-e "s,%%ETCPATH%%,$ETCPATH,g;" \
	-e "s,%%HISTORYPATH%%,$HISTORYPATH,g;" \
	-e "s,%%MAILFROM%%,$escaped_mailfrom,g;" \
	< $src > $dst
    if [ $? -ne 0 ]; then
	echo "Failed to copy $src to $dst."
	echo "Aborted."
	exit 1
    fi
    chmod $mode $dst
    if [ $? -ne 0 ]; then
	echo "Failed to chmod $dst to mode '$mode'."
	echo "Aborted."
	exit 1
    fi
}

########## Determine what's up with Perl
if [ `perl -e 'print 1;'` ] ;  then
	# some version of Perl exists
	echo "Perl detected"
	if [ `perl -e 'if($] >= 5) {print 1;} else {}'` ] ; then
		# Perl 5 or greater detected
		echo "Perl version OK."
		PERL=1
	else
		# Perl 5 not detected
		perl -e 'print "Perl version $] detected.\n"'	
		echo "Changetrack has been tested only with Perl 5."
		yesno "Install anyway?" YN no
		if [ "$YN" = no ]; then
			echo "Installation cancelled."
			echo "Perl is available at www.perl.com"
			exit 1
		else
			echo "Installing with old Perl."
			echo "Upgrading Perl is recommended."
			echo "Perl is available at www.perl.com"
			PERL=0
		fi
	fi
else
	# no version of Perl exists.
	cat <<EOF

Perl not detected.  Make sure Perl is in your path.
Changetrack requires at least Perl version 5, available from www.perl.com.

Installation cancelled.

EOF
	exit 1
fi

PERLPATH=`which perl`
export perlpath=`which perl`   # pass variable to perl. Ugh.

if [ ! $PERLPATH = "/usr/bin/perl" -a $PERL == 1 ] ; then
	# if it's already in the normal place, fine; 
	# if perl isn't version 5, the modification won't work anyway.
	echo "Perl found at $perlpath, should be /usr/bin/perl"
	yesno "Should I modify changetrack to run perl from $perlpath?" YN yes
	if [ "$YN" = yes ]; then
		echo "Telling changetrack to run from $PERLPATH."
		perl -i -pe "s,/usr/bin/perl,$perlpath,g;" changetrack
	else
		echo "Installing changetrack unmodified."
		echo "You should probably link perl to /usr/bin/perl"
	fi
fi

########## Are my defaults OK for this machine?
ask "Application directory:" APPPATH $APPPATH_DEFAULT
ask "Manual page directory:" MANPATH $MANPATH_DEFAULT
ask "Configuration file directory:" ETCPATH $ETCPATH_DEFAULT
ask "History files directory:" HISTORYPATH $HISTORYPATH_DEFAULT

cat <<EOF

If you want changetrack to send email notifications, you need to configure
the email address where the mail comes *from*.  This is because some MTAs
(mail transfer agents, such as sendmail) are configured to block email
addresses that do not resolve to a valid domain name.  As a rule in this
case, you must not use 'localhost' for the domain.

If you *don't* want to use email notifications, then you can safely use
'changetrack@localhost' or whatever else you want; the address will not
be used.

EOF
ask "Originating email address: " MAILFROM $MAILFROM_DEFAULT

#
# Save our configuration
#
date=`date`
cat > $d/.config <<EOF
#
# Configuration file created by $0
# $date
#
APPPATH_DEFAULT="$APPPATH"
MANPATH_DEFAULT="$MANPATH"
ETCPATH_DEFAULT="$ETCPATH"
HISTORYPATH_DEFAULT="$HISTORYPATH"
MAILFROM_DEFAULT="$MAILFROM"
EOF

my_install changetrack     $APPPATH/changetrack   0755
my_install changetrack.man $MANPATH/changetrack.1 0644

if [ -f "$ETCPATH/changetrack.conf" ]; then
	echo "$ETCPATH/changetrack.conf exists; not installing default file."
else
	yesno "Should I put a default changetrack.conf file in $ETCPATH?" YN yes
	if [ "$YN" = yes ]; then
		my_install changetrack.conf $ETCPATH/changetrack.conf 0644
	else
		echo "Omitting default configuration file."
	fi
fi

more <<EOF

If you want to enable email capabilities, you must ensure that the perl
module Mail::SendMail is installed on your machine, and then modify the
changetrack script so that the lines
        #use Mail::Sendmail
        exit();
are changed to 
        use Mail::Sendmail
        # exit();
Also, you should change the value of the 'mailfrom' variable to be that
of a real email address within your domain, or some antispam filters may
block changetrack's mail.

These modifications can be found in the changetrack script at about line 350.

The Mail::Sendmail module can be installed by running the following
command as root:
        perl -MCPAN "install Mail::Sendmail"

EOF