A lot of people want to encrypt their shell script so that they can publish it online without people being able to peak at the code.
This is a very simple way of turning that script into C code so you can compile it into a binary, although I don’t recommend you entirely rely on this method. Because it is still a shell script at heart, it won’t execute any quicker when converted.
Please note, the text after the // means a comment, and you shouldn’t enter this into the terminal session.
Step 1. Install gcc, make and some other things.
apt-get install gcc make // Debian yum install make gcc // CentOS
Step 2. Download SHC and extract it.
wget http://www.datsi.fi.upm.es/%7Efrosal/sources/shc-3.8.7.tgz tar -xzvf shc* cd shc*
Step 3. Compile and Install It.
make // this will error, but ignore it make test make strings make expiration mkdir -v /usr/local/man/man1/ // it doesn't exist. make install
Now, SHC should be installed, so now we have to make the binary.
Step 4. Make a script in your favourite editor, such as nano or vim. It is VERY important you keep the shebang at the beginning of the script (whatever shell you’re using, probably bash as listed below)
#!/bin/sh echo "Hello"
Save that, and for the tutorial were going to refer to this saved as hello.sh.
Step 5. Compile that script into a binary and C code
shc -v -r -f hello.sh
Step 6. Its now compiled, your end up with two files created similar to what i’ve listed below.
hello.sh.x // This is the binary hello.sh.x.c // This is the code generated
Now, your all done and it should be safe to distribute the binary. If you have any issues just post in the comments or contact me.
SHC Info: http://www.datsi.fi.upm.es/~frosal/sources/shc.html