[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 most important part of the red , 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 |
Then open install with vim . Bin file, find 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.
当然这并不是一个完美无缺的方案,linux也提供了方法对二进制文件进行反编译,但是至少普通用户是没有办法去查看相关代码内容了。