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
|
#!/bin/sh
#
# Copyright (C) 2000-2002 Cameron J. Morland
#
# 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: functions
#
# Project Name: changetrack
#
# Module Description: changetrack installation utility functions
#
# Author: Cameron J. Morland and Devin Reade
# 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:
#
# %%PERLPATH%%
# %%APPPATH%%
# %%MANPATH%%
# %%ROOTCONFFILE%%
# %%ROOTHISTORYPATH%%
# %%USERCONFFILE%%
# %%USERHISTORYPATH%%
# %%MAILFROM%%
#
# 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 | sed 's,\@,\\\\@,'`
sed \
-e "s,%%PERLPATH%%,$PERLPATH,g" \
-e "s,%%APPPATH%%,$APPPATH,g" \
-e "s,%%MANPATH%%,$MANPATH,g" \
-e "s,%%ROOTCONFFILE%%,$ROOTCONFFILE,g" \
-e "s,%%ROOTHISTORYPATH%%,$ROOTHISTORYPATH,g" \
-e "s,%%USERCONFFILE%%,$USERCONFFILE,g" \
-e "s,%%USERHISTORYPATH%%,$USERHISTORYPATH,g" \
-e "s,%%MAILFROM%%,$escaped_mailfrom,g" \
-e "s,%%ESMAIL%%,$ESMAIL,g" \
-e "s,%%DSMAIL%%,$DSMAIL,g" \
-e "s,%%ENCOPY%%,$ENCOPY,g" \
-e "s,%%DNCOPY%%,$DNCOPY,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
}
|