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
|
#!/bin/sh
#
# Check what's installed on a PCP/PCPQA VM looking for missing apps
# and packages
#
# Need directory where this script is located so we can find packages.rc
#
home=`echo $0 | sed -e 's/\/*check-vm$//'`
if [ ! -f $home/whatami ]
then
echo >&2 "Botch: \$0=$0 -> bad \$home=$home ?"
exit 1
fi
if [ ! -f $home/packages.rc ]
then
echo >&2 "Botch: cannot find $home/packages.rc"
exit
fi
. $home/packages.rc
_usage()
{
echo "Usage: $0 [options]"
echo " -p do (old) packaging tests"
echo " -v verbose (debugging)"
exit 1
}
# Networking goo
#
_check_host()
{
ipaddr=`sed -n </etc/hosts -e '/^#/d' -e '/::/d' -e 's/$/ /' -e "/[ ]$1[ ]/"'{
s/[ ].*//
p
}'`
if [ -z "$ipaddr" ]
then
echo "Error: no /etc/hosts entry for $1"
return
fi
if [ `echo "$ipaddr" | wc -l | sed -e 's/ *//g'` -gt 1 ]
then
echo "Error: multiple /etc/hosts entries for $1"
return
fi
rm -f $tmp.tmp
if `which ifconfig >/dev/null 2>&1`
then
# ifconfig lines of interest look like
# br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
# inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
# ...
# lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
# inet 127.0.0.1 netmask 255.0.0.0
#
ifconfig >$tmp.tmp
elif `which ip >/dev/null 2>&1`
then
ip -f inet address >$tmp.tmp
# ip lines of interest look like
# 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc ...
# inet 127.0.0.1/8 scope host lo
# ...
# 4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc ...
# inet 192.168.1.100/24 brd 192.168.1.255 scope global br0
# ...
else
echo "Error: neither ifconfig(1) nor ip(1)? Not sure how to get primary ip addr"
return
fi
sed <$tmp.tmp \
-e 's/^[0-9][0-9]*: //' \
-e 's/: / /g' \
-e '/ inet /s/\/.*/ /' \
| awk '
/^[^ ]/ { iface = $1; next }
/inet addr:'$ipaddr' / || /inet '$ipaddr'[ \/]/ {
if (iface == "lo")
print "Warning: '$1' associated with loopback network interface"
found = 1
exit
}
END { if (found != 1)
print "Warning: '$1' ('$ipaddr') not associated with a network interface"
}'
}
# Need directory where this script is located so we can find some other
# scripts we need
#
home=`echo $0 | sed -e 's/\/*check-vm$//'`
if [ ! -f $home/whatami ]
then
echo >&2 "Botch: \$0=$0 -> bad \$home=$home ?"
exit 1
fi
if [ -f /etc/pcp.conf ]
then
. /etc/pcp.conf
else
echo >&2 "Error: /etc/pcp.conf not found"
exit 1
fi
verbose=false
very_verbose=false
packages=false
while getopts 'pv?' p
do
case "$p"
in
p) packages=true
;;
v) if $verbose
then
very_verbose=true
else
verbose=true
fi
;;
?) _usage
# NOTREACHED
esac
done
shift `expr $OPTIND - 1`
[ $# -eq 0 ] || _usage
if $very_verbose
then
tmp=tmp
else
tmp=/var/tmp/$$
trap "rm -f $tmp.*; exit 0" 0 1 2 3 15
fi
rm -f $tmp.*
if $packages
then
# any required packages not installed?
#
$home/list-packages -m >$tmp.tmp
if [ -s $tmp.tmp ]
then
echo "Missing packages ..."
fmt -78 <$tmp.tmp
else
$verbose && echo "No missing packages."
fi
fi
# pmhostname sanity check
#
host=`hostname`
_check_host $host >$tmp.out
if [ -s $tmp.out ]
then
cat >&2 $tmp.out
else
$verbose && echo "/etc/hosts for $host looks ok"
fi
if which pmhostname >/dev/null 2>&1
then
pmhost=`pmhostname`
if [ -z "$pmhost" ]
then
echo >&2 "Warning: pmhostname returns nothing!"
else
case $pmhost
in
$host|$host.*)
;;
*)
echo >&2 "Warning: hostname ($host) is not a prefix of pmhostname ($pmhost)"
;;
esac
if [ "$pmhost" != "$host" ]
then
_check_host $pmhost >$tmp.out
if [ -s $tmp.out ]
then
cat >&2 $tmp.out
else
$verbose && echo "/etc/hosts for $pmhost looks ok"
fi
fi
fi
else
echo >&2 'Error: executable pmhostname not found'
fi
if [ -n "$PCP_VAR_DIR" ]
then
# need QA access to pmlogger via pmlc from local subnet
#
network=`_getnetworkaddr 2>$tmp.err`
$verbose && cat $tmp.err
if [ -n "$network" ]
then
if [ -f $PCP_VAR_DIR/config/pmlogger/config.default ]
then
if grep -q "^allow $network" $PCP_VAR_DIR/config/pmlogger/config.default
then
$verbose && echo "primary pmlogger [access] set up ok"
else
echo "Missing: \"allow $network : all;\" [access] in $PCP_VAR_DIR/config/pmlogger/config.default"
echo "Use \"$ sudo -E .../qa/admin/allow-pmlc-access\" to fix this."
fi
else
echo >&2 "Warning: \"$PCP_VAR_DIR/config/pcp/pmlogger/config.default\" is missing"
fi
else
echo >&2 "Please ignore Warnings from _getnetworkaddr unless you wish to run the"
echo >&2 "full PCP QA suite."
fi
else
echo >&2 'Error: $PCP_VAR_DIR not defined in /etc/pcp.conf'
fi
if sudo -u pcp id >/dev/null
then
# pcp user appears to exist ...
#
if sudo -u pcp [ -x $HOME ]
then
$verbose && echo "user pcp looks ok"
else
echo "Error: $HOME is not searchable by user \"pcp\""
fi
else
echo "Error: cannot su to user \"pcp\""
fi
# now some platform-specific tests
#
case "$distro"
in
OpenBSD)
if false
then
# redundant now the openbsd PMDA no longer reads /dev/mem
# directly
#
allowkmem=`sysctl kern.allowkmem | sed -e 's/.*=//'`
if [ "$allowkmem" != 1 ]
then
echo >&2 "Warning: kern.allowkmem is \"$allowkmem\" not 1 and so openbsd PMDA will not be able"
echo " to access /dev/kmem"
echo " Suggest adding kern.allowkmem=1 to etc/sysctl.conf and rebooting."
fi
fi
;;
esac
$very_verbose && echo >&2 "temp files:" $tmp.*
|