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
|
#!/bin/sh
#
# Generic script to remove PCP after installation from a tarball
#
# exit status
# 0 all OK
# 1 warnings
# 2 errors
#
if [ ! -f /etc/pcp.env ]
then
# PCP not installed before, do nothing
#
exit 0
fi
. /etc/pcp.env
# debugging
#
RM="echo + rm"
RMDIR="echo + rmdir"
WARN="echo Warning:"
# do the work
#
RM=rm
RMDIR=rmdir
for svc in pmproxy pmie pmcd pmlogger pcp
do
[ -f $PCP_RC_DIR/$svc ] && $PCP_RC_DIR/$svc stop
if which rc-update >/dev/null 2>&1
then
rc-update delete $svc
elif which rcctl >/dev/null 2>&1
then
rcctl disable $svc
fi
done
if [ ! -f pcp-*[0-9].tar.gz ]
then
echo "Error: cannot find tarball matching pcp-*[0-9].tar.gz"
exit 1
fi
sts=0
tar tf pcp-*[0-9].tar.gz \
| sed -e 's/^\.//' -e 's/^[^/]/\/&/' \
| while read file
do
if [ -f $file -o -L $file ]
then
if $RM $file
then
:
else
sts=2
fi
else
$WARN "file $file is missing"
[ $sts = 0 ] && sts=1
fi
done
for conf in \
$PCP_PMCDCONF_PATH $PCP_PMCDOPTIONS_PATH $PCP_PMCDRCLOCAL_PATH \
$PCP_PMIECONTROL_PATH $PCP_PMLOGGERCONTROL_PATH \
$PCP_PMPROXYOPTIONS_PATH $PCP_PMWEBDOPTIONS_PATH
do
rm -f "$conf.pre" "$conf.dist"
done
_rmdir_if_empty()
{
if [ "`echo $1/*`" = "$1/*" ]
then
if $RMDIR "$1"
then
:
else
sts=2
fi
else
# directory is not empty
$WARN "directory $1 is not empty, not removed"
[ $sts = 0 ] && sts=1
fi
}
# some special case cleanup in $PCP_VAR_DIR for files that
# are known/expected to be created after the installation and
# so not part of the tarball
#
$RM -rf $PCP_VAR_DIR/config/pmda
$RM -rf $PCP_VAR_DIR/pmns
$RM -rf $PCP_VAR_DIR/pmdas/simple
$RM -rf $PCP_VAR_DIR/pmdas/sample
$RM -f $PCP_VAR_DIR/pmdas/*/*.pag $PCP_VAR_DIR/pmdas/*/*.dir $PCP_VAR_DIR/pmdas/*/*.log
# we leave $PCP_LOG_DIR but clean up everything else that is not
# empty ... order is a bit tricky, make sure possible leaf directories
# come before any parent directories
#
for dir in $PCP_BINADM_DIR $PCP_INC_DIR $PCP_MPI_DIRS \
$PCP_RUN_DIR $PCP_PMDAS_DIR $PCP_VAR_DIR \
$PCP_DOC_DIR $PCP_DEMOS_DIR $PCP_SHARE_DIR
do
if [ -d "$dir" ]
then
find "$dir" -depth -type d \
| while read subdir
do
_rmdir_if_empty "$subdir"
done
fi
done
# TODO
# if $PCP_SYSCONFIG_DIR is not empty (RH sysconfig only?) what to do?
exit $sts
|