Various fixes
[public/netxms.git] / tools / stub.sh
1 #!/bin/sh
2
3 hash1=__HASH1__
4 hash2=__HASH2__
5 skip=__SKIP__
6 skip1=__SKIP1__
7 command=__COMMAND__
8 log=/tmp/nxagentupdate.log
9
10 wd=`pwd -P`
11
12 trap '
13 echo "Upgrade script finished" >> $log
14 cd $wd
15 [ "x"$temp != "x" ] && rm -rf $temp
16 exit
17 ' INT EXIT
18
19 rm -f $log
20 echo "WD = $wd" >> $log
21
22 mktemp() {
23 d=/tmp/nxupdate.$$.UniQ
24 mkdir $d && echo $d || false
25 }
26
27 temp=`mktemp -d /tmp/nxinst.XXXXXX 2>/dev/null`
28 if [ $? != 0 ]; then
29 echo "Can't create temp dir" >> $log
30 exit 0
31 fi
32 cd $temp
33 tail +$skip1 $wd/$0 | gzip -dc 2>/dev/null | tar xf -
34 if [ $? != 0 ]; then
35 echo "Can't unpack" >> $log
36 exit;
37 else
38 chmod +x ./$command
39 if [ $? != 0 ]; then
40 echo "Can't chmod $command" >> $log
41 exit
42 fi
43 echo Starting $command $*... >> $log
44 ./$command $* 2>&1 >> $log
45 fi
46
47 exit
48 ###################################