Build Linux under the program installation package--use scripts to package bin, run and other installation packages

Source: Internet
Author: User
Tags gz file

When making a simple installation package, you can simply use the cat command to connect two files, then the head is a script file, the execution of the following files will be broken out on the line. Generally this latter part of the file is a compressed package, so that you can pack a lot of files, in the script can be extracted. This is the simple creation of the Linux bin, run, and other installation scripts. Let's take a look at two simple examples:

—————————— Gorgeous split-line ——————————

The Run program installation package is essentially an installation script plus the program to be installed, as shown in:

| ————— –|
|                        |
|      Installation Scripts       |
|                        |
| ————— –|
|                        |
|       Programs             |
|                        |
| ————— –|
Figure: The structure of the run installation package

So the entire run package structure is at a glance, in fact, because the actual need for the structure of a little change, but this does not matter, only need to understand the principle of the line.
Create a Run installation package here are some practical examples:
for the sake of simplicity, the program to be installed is the HelloWorld program, and the process of installing it is to copy it to the/bin directory.
$ ls
install.sh HelloWorld
$ cat install.sh
#!/bin/bash
CP helloworld/bin
$
Now there's a setup script, Named Install.sh, there is a program to install HelloWorld. Because the program to be installed is usually done with. tar.bz2. Let's do it here:
$ tar jcvf helloworld.tar.bz2 HelloWorld
Now modify an installation script install.sh
instead:
#!/bin/bash
Lines=7        #这个值是指这个脚本的行数加1, this script has a total of 6 lines
Tail + $lines $ >/tmp/helloworld.tar.gz # $ to represent the script itself, this command is used to take from $ Lines the beginning of the content is written to A/tmp directory in the helloworld.tar.gz file.
Tar jxvf/tmp/hellowrold.tar.gz
CP helloworld/bin
Exit 0

Then use the cat command to connect the installation scripts install.sh and helloworld.tar.bz2.
$ cat install.sh helloworld.tar.bz2 > Myinstall.run
This gives you the Myinstall.run file, which is structured as follows:
| —————— | line 1th
|                           |
|    install.sh       |
|                          | Line 6th
| —————— |
|                           | Line 7th
|helloworld.tar.bz2 |
|                           |
| —————— | End
Figure: Structure of the Myinstall.run installation package

When I run Myinstall.run, the exit 0 script that runs to line 6th exits, so we don't run the binary data (that is, the helloworld.tar.bz2 file) below line 7th, and we use tail to subtly redirect the data below line 7th The freshman became a helloworld.tar.gz file. Perform the installation again.

The run installation package makes it a good choice to make a smaller package, but it also has drawbacks, and it can be cumbersome to make a more complex installation package and write an installation script. So it's better to use a different installation package at this point.

—————————— Gorgeous split-line ——————————

Files in binary. bin under Linux
The way to do this is to use the cat command to put the execution script and the packaged files in a. bin file.
As long as the installation of the use of a package, directly execute the package can be installed, simple and convenient.
Example: Making an installation script package that installs Apache and MySQL
1. Package the source package first
#tar ZCVF packages.tar.gz httpd-2.0.63.tar.bz2 mysql-5.0.33.tar.gz

2. Write the following script:
# Cat Install.sh
#!/bin/bash
Dir_tmp=/root/installapache
mkdir $dir _tmp
Sed-n-E ' 1,/^exit 0$/!p ' $ > ' ${dir_tmp}/packages.tar.gz ' 2>/dev/null
CD $dir _tmp
Tar zxf packages.tar.gz
Tar jxf httpd-2.0.63.tar.bz2
CD httpd-2.0.63
./configure–prefix=/tmp/apache2
Make
Make install
CD $dir _tmp
Tar zxf mysql-5.0.33.tar.gz
CD mysql-5.0.33
./configure–with-charset=gbk–with-extra-charsets=binary,latin1,gb2312–localstatedir=/home/db– With-mysqld-ldflags=-all-static-enable-assembler–with-innodb–prefix=/tmp/mysql5
Make
Make install
Exit 0

#cat install.sh packages.tar.gz >install.bin

This generates the Install.bin installation file, which is composed of shell scripts and binary binaries. The first half is the second part of the script is a binary file, with the strings and other binary view command can be seen
The main thing is that the following sentence separates binary files from the. bin file
Sed-n-E ' 1,/^exit 0$/!p ' $ > ' ${dir_tmp}/packages.tar.gz ' 2>/dev/null

Direct execution when installing
SH install.bin
Install this method to script the installation we normally use, and then package it. It is convenient to use in the future.

—————————— Gorgeous split-line ——————————
The above two examples, in fact, whether it is bin or run, in fact, Linux under all documents, and no matter what documents, are the same view. So there's no point in these suffixes. The above two different places are separated, one is using the tail command, and one is implemented with SED. In short, this is just a way of thinking, no matter what method, as long as it can be combined and then separate on the line.

In addition, someone has written a script to implement such a function, interested can see for themselves:

Build Linux under the program installation package--use scripts to package bin, run and other installation packages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.