Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ How to create a binary distribution with Bash     - Permissions and attributes of files and directories under Linux (Linux)

- Linux beginners should know 12 commands (Linux)

- GRUB and Linux system repair (Linux)

- Using PHP MySQL library (Programming)

- Linux System Getting Started Learning: install software packages on Ubuntu and Fedora (Linux)

- Oracle to create an external table (Database)

- Oracle RMAN backups of the control file backup (Database)

- CMake Quick Start Tutorial (Linux)

- How to use Java to read OpenOffice document (Programming)

- Kernel compile under Debian (Linux)

- Open remote MySQL database connection managed under CentOS (Database)

- Get the Linux device PCI ID method (Linux)

- Linux file system management partition, format, mount - label mount (Linux)

- CentOS 6.5 using Virtualenv under development environment to build Python3 (Linux)

- mysqldump implement database logical backup (Database)

- Effective Java - lazy initialization (Programming)

- Use a soft Raid play multiple SSD hard drive performance and enhance data security (Linux)

- Copy Recovery using RMAN repository development environment (Database)

- Nginx logging client ip (Server)

- Stunning exclamation point at the Linux command line (Linux)

 
         
  How to create a binary distribution with Bash
     
  Add Date : 2018-11-21      
         
         
         
  When the Linux install the JDK, Sun has linux version JDK6 provides a shell for the installation package, using them especially easy to use, and basically install the software under Windows is no different, file execution after shell, almost all lines were set up, do our own hands and then set the PATH and JAVA_HOME, but a shell file contains a binary code is how to get in?

Another example Taobao to linux development Taobao plug-in, it is actually a shell file, but after the implementation of the shell file will install a lot of binary stuff, the same problem, Shell only text file binary is how to contain come of it?

Convert text files from the executable file, the compiler through the programming source code into an executable program is certainly possible, but in both cases mentioned above which are not doing so. There are two reasons, first for large projects, the time required to compile longer, more complex environment; second, more important, in fact, doing so from the source code and compile the program is no different, so that users who do not want to see to their source business software, which is obviously undesirable.

We see how the usual procedure is to publish their binary packages.

General procedure, is that the binary and the necessary documents compressed into a compressed file, what kind of assumptions and reliance by running the interpreter README document, and then you can put the program on their own move to where you want to move the place went.

Many times, we put into the program which can run anywhere, but the program can be run, not to say that we have completed the installation procedure, for example, if after we unpacked JDK binary package directly to the program move to a place, and then add the corresponding bin directory to the PATH can perform a range of tools provided by the JDK.

But if we install additional time dependence and JDK programs, such TOMCAT, then there will be problems. Because we just added in the PATH JDK bin directory but not set JAVA_HOME environment variable, so TOMCAT will probably not run.

Another example we use the man command to view a program handbook, under normal circumstances the binary package will contain man documents, but if we just add the path to extract the binary package to the PATH, it can not find the corresponding in man in document.

It is also because of this reason, many of the binary packages is to use the publication to publish a deb or rpm package. The installation of a lot less trouble. To making deb or rpm packages need to learn is of course the cost of deb and rpm and can only be used in the corresponding linux releases, if you want all of the Linux distributions provide an installation file, use the shell file No doubt it is the best way.

Shell low learning costs, but also for linux platforms with universal, then it is how to do it?

We think in the case of manual installation, simply unpack the compressed binary to move to work under a specific directory, add in the PATH variable binary package executable file path, and so on. First, we put binary packages are compressed files and shell files separately. As a result, shell as long as the completion of decompression, and after decompression move a directory to the directory specified to set a variety of environment variables and then to complete the work.

But we shell file after the compressed file and how to extract the shell to execute the command shell put together a file?

To do this, first the shell file, you can extract have binary content, and secondly, this shell is work to be done, the binary content, decompression, then the original manual work done in the shell with the command completes . Then write a shell script to complete some work done manually, this task is easier, so the difficulty of making shell package is how to contain the binary content therein.

How to record binary content in a text file?

This problem has long been solved. The answer is to use Base64 encoding. In linux there base64 this command procedure is to do the job. base64 can file base64 encoding standard output to the output file or to the Base64 encoded content decoding. Command base64 addition to the contents of the file do Base64 encoding and decoding of, but also the standard input data can be edited Base64 code.

With this knowledge prepared, then we can look at how to do a specific shell binary distribution package.

First, assume that we want to publish the files are placed in the current document named test.

The file is packaged to be published

tar zcf test.tar./test
To lay the Base64 encoded binary packages do

base64 ./test.tar> test_base64.txt
Ready to install the files shell file

test_base64 = ""; # test_base64 all content
echo $ test_base64 | base64 -d> test.tar
tar zxf test.tar
rmtest.tar
Other installation code #
I write to you, we have the truth will understand. But can you write a shell program, specifically to generate such release package software? of course can. Here is what I wrote this program's source code package.

function mkpackage () {
target_dir = $ 1
felow_install_shell_command_file = $ 2
echo "tar -zcf ._test_dir.tar.gz $ target_dir"
tar-zcf ._test_dir.tar.gz $ target_dir
base64 ._test_dir.tar.gz> ._ base64
rm._test_dir.tar.gz
printf "test_base64 = \" "> install.sh
while IFS = '' read -r line || [[- n "$ line"]]; do
printf "$ line \\" >> install.sh
printf "n" >> install.sh
done <./._ base64
rm._base64
echo "\" ">> install.sh
echo'printf $ test_base64 | base64 -d> ._ temp.tar.gz; '>> install.sh
echo'tar zxf ._temp.tar.gz '>> install.sh
echo'rm ._temp.tar.gz '>> install.sh
if [[- e $ fellow_install_shell_command_file]]; then
cat $ fellow_install_shell_command_file >> install.sh
fi
chmod + x install.sh
}
function usage () {
echo "usage:"
echo "$ 1 test_dir [the_command.sh]"
}
if [[$ #! = 0]]
then
mkpackage $ 1 $ 2
else
usage $ 0
fi
The program accepts two input parameters, the fight represents the first package directory, the second is unpacked, the installation operation of the shell script file. Finally, this program creates a file called install.sh's. After executing install.sh, you will first get pressurized package contents, and then execute the contents of the second parameter specifies the shell script. So we did with Shell released a binary package program. Of course, before the final release, also need to compress the shell. In order to eliminate as Base64 encoded file length brought becomes a big impact.
     
         
         
         
  More:      
 
- LaTeX Getting Started Tutorial (Linux)
- Linux Firewall Basics (Linux)
- PHP generates a random password several ways (Programming)
- Java inner classes (Programming)
- Object-oriented language Java some of the basic features (Programming)
- To install PXE + Kickstart under CentOS 6.x operating system (Linux)
- Linux create and delete user step (Linux)
- Linux alpine use the command line to access Gmail (Linux)
- Oracle user lock how to know what causes (Database)
- How to download GOG games in Linux command line (Linux)
- MySQL loose index scan (Database)
- Docker deployment practices in Ubuntu (Server)
- Enterprise Hadoop cluster architecture - DNS installation (Server)
- Configure the Linux kernel and use iptables to do port mapping (Linux)
- Oracle table compression Technology Introduction (Database)
- Linux LVM space expansion Demo (Linux)
- VPS xen openvz kvm (Server)
- Secondary exponential smoothing prediction method implemented in Python (Programming)
- Linux foundation tutorial: how to modify the host name on CentOS or RHEL 7 (Linux)
- Linux kernel VLAN study notes (Programming)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.