Self-extracting shell script from a TAR archive for Linux PushAgent

Print Friendly, PDF & Email

Create under a convenient directory (such as /tmp) a C6.X-bundle direcrory then copy there all the needed RPMs and the atlantix-nrpe-installer shell script

mkdir /tmp/bundle
cp -pr /root/SKELETON/atlantix-clients-installer.sh /root/SKELETON/C6.7 /tmp/bundle/

 

Create a tar.gz archive with all the content:
cd /tmp/
tar -zcvf C6.7-bundle.tar.gz bundle

Under /tmp create the following create-self-bin script:

#!/bin/bash
BASEDIR=`dirname "${0}"`
cd "$BASEDIR"

payload=$1
script=$2
tmp=__extract__$RANDOM

[ "$payload" != "" ] || read -e -p "Enter the path of the tar archive: " payload
[ "$script" != "" ] || read -e -p "Enter the name/path of the script: " script

printf "#!/bin/bash
PAYLOAD_LINE=\`awk '/^__PAYLOAD_BELOW__/ {print NR + 1; exit 0; }' \$0\`
tail -n+\$PAYLOAD_LINE \$0 | tar -xvz
#you can add custom installation command here

exit 0
__PAYLOAD_BELOW__\n" > "$tmp"

cat "$tmp" "$payload" > "$script" && rm "$tmp"
chmod +x "$script"

and make it executable

chmod +x create-self-bin

Now run the create-self-bin script with the following parameters to generate a self-extract.bin script in the same directory

./create-self-bin /tmp/C6.7-bundle.tar.gz /tmp/self-extract.bin

The self-extract.bin now contains all we need to push our nrpe and ocsinventory agents on a target Centos server.

In order to push the agent to the target server you have to follow these steps:

  1. Copy the generated self-extract.bin file somewhere (/tmp for example) in the target server
  2. Run it: ./self-extract.bin
  3. Finally enter the folder created upon self extraction ends (cd bundle) and run the nrpe installer with appropriate paremeters:
    ./atlantix-clients-installer.sh <atlantix-site-controller-IP> [local]

Done!

Reference: http://community.linuxmint.com/tutorial/view/1998

 

atlantixadmin has written 113 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>