/usr/bin/mib2c-update is in libsnmp-dev 5.4.3~dfsg-2.4ubuntu1.3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | #!/bin/bash
#
# $Id: mib2c-update 16702 2007-09-16 09:51:41Z magfr $
#
# script to merge custom code into updated mib2c code
#
#----- example .mib2c-updaterc -----
#UPDATE_OID=ipAddressTable
#UPDATE_CONF=mib2c.mfd.conf
#UPDATE_MIB2C_OPTS=
#UPDATE_NOPROBE=1
#----- example .mib2c-updaterc -----
#----------------------------------------------------------------------
#
# defaults
#
UPDATE_CURR=$PWD
UPDATE_ORIG=$PWD/.orig
UPDATE_NEW=$PWD/.new
UPDATE_MERGED=$PWD/.merged
UPDATE_BACKUP=$PWD/.backup
UPDATE_PATCH=$PWD/.patch
#
# number of diff context lines / patch fuzz factor
#
FUZZ=5
FIRST_RUN=0
#----------------------------------------------------------------------
#
debug()
{
if [ $UPDATE_DEBUG -ge 1 ]; then
echo $1
fi
}
error()
{
echo "ERROR: $@" > /dev/stderr
}
die()
{
error "$@"
exit 99
}
safecd()
{
cd $1
if [ $? -ne 0 ]; then
die "changing to directory $1 from $PWD failed!"
fi
}
safecp()
{
cp $@
if [ $? -ne 0 ]; then
die "'cp $@' failed!"
fi
}
#----------------------------------------------------------------------
#
check_setup()
{
rc=1
for d in $UPDATE_CURR $UPDATE_ORIG $UPDATE_NEW $UPDATE_MERGED $UPDATE_PATCH $UPDATE_BACKUP $UPDATE_BACKUP/curr $UPDATE_BACKUP/orig
do
if [ ! -d $d ]; then
echo "Creating missing directory $d"
mkdir -p $d
if [ $? -ne 0 ]; then
error "Could not create directory $d"
rc=0
fi
fi
done
if [ -z "$UPDATE_OID" ]; then
error "Environment variable missing! Set UPDATE_OID in .mib2c-updaterc"
rc=0
fi
if [ -z "$UPDATE_CONF" ]; then
error "Environment variable missing! Set UPDATE_CONF in .mib2c-updaterc"
rc=0
fi
# if [ -z "$UPDATE_" ]; then
# error "Environment variable missing! Set UPDATE_ in .mib2c-updaterc"
# rc=0
# fi
if [ $rc -eq 0 ] && [ $UPDATE_NOPROBE -ne 1 ]; then
mib2c -c unknown > /dev/null 2>&1
if [ $? -eq 0 ]; then
error "WARNING: mib2c returns 0 on error conditions!"
rc=0
fi
fi
return $rc
}
#----------------------------------------------------------------------
#
do_diff()
{
DD_ORIG=$1
DD_CURR=$2
DD_OUTPUT=$3
# u | c unified | context
# r recursive
# b ignore blank lines
# w ignore white space
# p Show which C function each change is in.
# d smaller changes
# --exclude='*Makefile' --unidirectional-new-file
local rc=0
local rcs=0
safecd $DD_ORIG
echo " checking files in $1 ($PWD)"
files=`ls *$UPDATE_OID* 2>/dev/null`
if [ ! -z "$files" ]; then
for f in $files; do
diff -U $FUZZ -p -b -w --show-c-function \
-I "$""Id:" $f $DD_CURR/$f >> $DD_OUTPUT
rc=$?
rcs=`expr $rcs + $rc`
if [ $rc -eq 1 ]; then
echo " $f is different"
fi
done
fi
if [ $rcs -eq 0 ]; then
rm -f $DD_OUTPUT
fi
safecd -
return $rcs
}
#----------------------------------------------------------------------
#
do_cp()
{
src=$1
dest=$2
if [ ! -d $dest ]; then
die "dest $dest is not a directory"
fi
if [ ! -d $src ]; then
die "src $src is not a directory"
fi
safecd $src
files=`ls *$UPDATE_OID* 2>/dev/null| egrep "(file|onf|m2d|txt|\.c|\.h)$"`
if [ -z "$files" ]; then
echo " no files to copy from $src"
else
safecp $files $dest
if [ $? -ne 0 ]; then
die "error while copying files from $src to $dest in $PWD"
fi
fi
safecd -
}
#----------------------------------------------------------------------
#
save_diff()
{
echo "Creating patch for your custom code"
cnt=`ls $UPDATE_CURR/*$UPDATE_OID* 2>/dev/null | egrep "(file|onf|m2d|txt|\.c|\.h)$" | wc -l`
if [ $cnt -eq 0 ]; then
echo " no custom code!"
FIRST_RUN=1
return
fi
do_diff $UPDATE_ORIG/ $UPDATE_CURR/ $UPDATE_PATCH/custom.$UPDATE_DATE
if [ $? -eq 0 ]; then
echo " no custom code changes found."
fi
}
#----------------------------------------------------------------------
#
gen_code()
{
copy_defaults . $UPDATE_NEW
safecd $UPDATE_NEW
files=`ls *$UPDATE_OID* 2>/dev/null | grep -v "^default"`
if [ ! -z "$files" ]; then
rm -f $files > /dev/null 2>&1
fi
echo "mib2c $@ -c $UPDATE_CONF $UPDATE_MIB2C_OPTS $UPDATE_OID"
mib2c $@ -c $UPDATE_CONF $UPDATE_MIB2C_OPTS $UPDATE_OID
if [ $? -ne 0 ]; then
die "bad rc $rc from mib2 while generation new code."
fi
safecd -
}
#----------------------------------------------------------------------
#
check_new()
{
echo "Checking for updates to generated code"
do_diff $UPDATE_ORIG/ $UPDATE_NEW/ $UPDATE_PATCH/generated.$UPDATE_DATE
if [ $? -eq 0 ]; then
echo "Generated code has not changed."
safecd $UPDATE_PATCH
files=`ls *.$UPDATE_DATE 2>/dev/null `
if [ ! -z "$files" ]; then
rm $files
fi
exit 0
fi
}
#----------------------------------------------------------------------
#
merge_code()
{
files=`ls $UPDATE_MERGED/* 2>/dev/null `
if [ ! -z "$files" ]; then
rm $UPDATE_MERGED/*
fi
do_cp $UPDATE_NEW $UPDATE_MERGED
if [ -f $UPDATE_PATCH/custom.$UPDATE_DATE ]; then
touch .M2C-UPDATE-MERGE-FAILED
echo "Patching new generated code in $UPDATE_MERGED ($PWD)"
# --forward = ignore already applied
patch --forward -F $FUZZ -N -d $UPDATE_MERGED -i $UPDATE_PATCH/custom.$UPDATE_DATE
if [ $? -ne 0 ]; then
error "Could not apply custom code patch to new generated code"
die "You must fix the problem in $UPDATE_MERGED, and then re-run mib2c-update."
fi
rm .M2C-UPDATE-MERGE-FAILED
fi
}
copy_defaults()
{
SRC=$1
DST=$2
if [ -d $SRC/defaults ]; then
safecp -a $SRC/defaults $DST
else
files=`ls $SRC/default-*.m2d 2>/dev/null `
if [ ! -z "$files" ]; then
safecp $files $DST
fi
fi
}
copy_merged()
{
echo "Backing up current code to $UPDATE_BACKUP/curr"
do_cp $UPDATE_CURR $UPDATE_BACKUP/curr/
copy_defaults . $UPDATE_BACKUP/curr/
echo "Copying merged code to $UPDATE_CURR"
do_cp $UPDATE_MERGED $UPDATE_CURR/
echo "Backing up original code to $UPDATE_BACKUP/orig"
do_cp $UPDATE_ORIG $UPDATE_BACKUP/orig/
echo "Saving new original code to $UPDATE_ORIG"
do_cp $UPDATE_NEW $UPDATE_ORIG/
}
copy_new()
{
echo "Copying code to $UPDATE_CURR"
do_cp $UPDATE_NEW $UPDATE_CURR/
# copy defaults back to current dir (which may not be UPDATE_CURR)
copy_defaults $UPDATE_NEW .
echo "Saving original code to $UPDATE_ORIG"
do_cp $UPDATE_NEW $UPDATE_ORIG/
}
copy_code()
{
if [ $FIRST_RUN -ne 1 ]; then
copy_merged
else
copy_new
fi
# always get defaults from UPDATE_NEW, since those are what were used.
copy_defaults $UPDATE_NEW .
}
#----------------------------------------------------------------------
UPDATE_NOPROBE=0
if [ -f $HOME/.mib2c-updaterc ]; then
. $HOME/.mib2c-updaterc
fi
if [ -f .mib2c-updaterc ]; then
. .mib2c-updaterc
fi
check_setup
if [ $? -ne 1 ]; then
exit 1
fi
UPDATE_DATE=`date "+%F_%I.%M"`
echo "Starting regneration of $UPDATE_OID using $UPDATE_CONF at $UPDATE_DATE"
if [ -f .M2C-UPDATE-MERGE-FAILED ]; then
echo "It appears that the last run of mib2c-update was not able to merge"
echo "your changes automatically. Do you want to:"
echo
while : ; do
echo "[c)opy merged files to $UPDATE_CURR]"
echo "[r)e-run from scratch]"
echo "[q)uit]"
echo "(c|r|q) ?"
read ans
if [ "x$ans" = "xr" ]; then
rm .M2C-UPDATE-MERGE-FAILED
break
elif [ "x$ans" = "xc" ]; then
echo "Have you have manually merged all the"
echo "changes into the merged directory?"
echo "(y|n)"
read ans
if [ "x$ans" != "xy" ]; then
echo "Ok. Try again after you've done that."
exit 1
fi
rm .M2C-UPDATE-MERGE-FAILED
copy_code
exit 0
fi
done
fi
save_diff
gen_code $@
if [ $FIRST_RUN -ne 1 ]; then
check_new
merge_code
fi
copy_code
|