- TODO updated
[public/netxms.git] / tools / stub.sh
CommitLineData
b78936e5
AK
1#!/bin/sh
2
3hash1=__HASH1__
4hash2=__HASH2__
5skip=__SKIP__
6command=__COMMAND__
861fb447
VK
7log="/tmp/agent_upgrade_log"
8elog="/tmp/agent_upgrade_log.stderr"
b78936e5
AK
9
10trap '
861fb447 11 echo "Upgrade script finished" >> $log
2dad1e4c 12 [ "x"$temp != "x" ] && rm -rf $temp
b78936e5
AK
13 exit
14' INT EXIT
15
861fb447
VK
16rm -f $log $elog
17
2dad1e4c 18md5=`which md5 2>/dev/null`
b78936e5 19if [ $? != 0 ]; then
2dad1e4c 20 md5=`which md5sum 2>/dev/null`
b78936e5 21 if [ $? != 0 ]; then
2dad1e4c 22 md5=`which openssl 2>/dev/null`
b78936e5 23 if [ $? != 0 ]; then
861fb447 24 echo "Can't calculate MD5, exiting" >> $log
b78936e5
AK
25 exit
26 else
27 md5="$md5 md5"
28 fi
b78936e5
AK
29 fi
30fi
31
2dad1e4c 32if [ "X"`head -n$skip $0 | tail -n +5 | $md5 | cut -b1-32 | tr A-Z a-z` != "X"$hash1 ]; then
861fb447 33 echo "Script MD5 mismach" >> $log
b78936e5
AK
34 exit
35fi
1216cc73
AK
36
37let "skip=skip+1" 2>/dev/null
38if [ $? != 0 ]; then
39 # real sh?
40 skip=`let "$skip+1"`
41fi
42
2dad1e4c 43if [ "X"`tail -n +$skip $0 | $md5 | cut -b1-32 | tr A-Z a-z` != "X"$hash2 ]; then
861fb447 44 echo "Payload MD5 mismach" >> $log
b78936e5
AK
45 exit
46fi
47
48temp=`mktemp -d /tmp/nxinst.XXXXXX 2>/dev/null`
49if [ $? != 0 ]; then
861fb447 50 echo "Can't create temp dir" >> $log
b78936e5
AK
51 exit 0
52fi
53tail -n +$skip $0 | gzip -dc 2>/dev/null | tar xf - -C $temp
54if [ $? != 0 ]; then
861fb447 55 echo "Can't unpack" >> $log
b78936e5
AK
56 exit;
57else
58 cd $temp
2dad1e4c
AK
59 chmod +x ./$command
60 if [ $? != 0 ]; then
861fb447 61 echo "Can't chmod $command" >> $log
2dad1e4c
AK
62 exit
63 fi
861fb447 64 ./$command >> $log 2> $elog
b78936e5
AK
65fi
66
67exit
68###################################