How to generate a bash script with an embeeded tar.gz (self-extract)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
> cat extract.sh
#!/bin/bash
echo "Extracting file into `pwd`"
# searches for the line number where finish the script and start the tar.gz
SKIP=`awk '/^__TARFILE_FOLLOWS__/ { print NR + 1; exit 0; }' $0`
#remember our file name
THIS=`pwd`/$0
# take the tarfile and pipe it into tar
tail -n +$SKIP $THIS | tar -xz
# Any script here will happen after the tar file extract.
echo "Finished"
exit 0
# NOTE: Don't place any newline characters after the last line below.
__TARFILE_FOLLOWS__
3) Concatenate The script and the tar file together.
1
2
> cat extract.sh example.tar.gz > example.sh
> chmod +x example.sh
4) Now test in another directory.
1
2
3
> cp example.sh /tmp
> cd /tmp
> ./example.sh

Comments

Popular posts from this blog

HAproxy logging

tomcat catalina coyote jasper cluster

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all