Create an executable file bin installed under Linux

[Scenarios]

Simplify operation, some for the mounting operation, and installation script files need to include the script needs two parts, after packaging into an executable file is only one bin of the installation package.

Code protection, in many cases, we do not want the user direct access to the code portion, in this case, we need more packaged into a bin file to install.

【Fundamental】

In fact, that is simple, bin executable files, in fact, the installation script files and scripts needed to put on the same file at the same time inside, and then to read the section in the rearmost bin file in the script.

After reading out the normal execution of the script.

Then remove.

as follows:

#!/bin/sh
dir_installation=/root/create_bin
mkdir $dir_installation
sed -n -e '1,/^exit 0$/!p' $0 > "${dir_installation}/abc.rpm" 2>/dev/null
cd $dir_installation
rpm -ivh abc.rpm
rm -y abc.rpm
rm -y $dir_installation
exit 0

The red part of the most important, its main purpose is to exit the back of the 0 content is extracted, save as rpm package, and then perform the installation, after installation deleted rpm.

The green part is the actual execution of our script.

[Creation]

Creation process even simpler:

cat install.sh ./abc.rpm > install.bin

Install.bin then open the file with vim, found the beginning is part of our script, the second half of our file.

[Code Protection]

About code protection, we can use the shc tool.

./shc -f install.bin

Script files can be compiled into a binary file by shc, hides the contents of the script.

Of course, this is not a perfect solution, linux also provides a method for binaries decompile, but at least the average user is no way to view the contents of the code.

Guess you like

Origin www.linuxidc.com/Linux/2019-08/159988.htm