Package multiple files into a single shell

Source: Internet
Author: User
Tags pack

1.Scripting purposes

Automate the deployment of your environment and combine packages and deployment scripts into one file to avoid scripting and file separation.

2. Experimental Environment

(1) Linux Environment

CentOS 7.4

(2) package

[email protected] 0517]# TAR-TF apache_2.4.29.tar.gz # for automated Installation Apache as an example

Apr-1.6.3.tar.gz

Apr-util-1.6.1.tar.gz

Httpd-2.4.29.tar.gz

(3) installation Script

[email protected] 0517]# ll install.sh # the script implements the apache_2.4.29.tar.gz Decompression and httpd Environment Deployment

-rw-r--r--1 root root 2958 may 12:03 install.sh

(4) packaging Scripts

[email protected] 0517]# Cat package.sh # will be apache_2.4.29.tar.gz and the install.sh Merge into one file

#!/bin/bash

script_size=$ (stat-c%s $)

pack_size=$ (stat-c%s $)

Echo ' #!/bin/bash ' >/tmp/compress.sh

echo "DD if=$1 of=$3 bs=1 count= $PACK _size skip=$[script_size+100]" >>/tmp/compress.sh

com_size=$ (stat-c%s/tmp/compress.sh)

If [$COM _size-ne];then

Sed-i "2d"/tmp/compress.sh

echo "DD if=$1 of=$3 bs=1 count= $PACK _size skip=$[script_size+com_size]" >>/tmp/compress.sh

com_size_new=$ (stat-c%s/tmp/compress.sh)

If [$COM _size-lt $COM _size_new];then

Sed-i "2d"/tmp/compress.sh

echo "DD if=$1 of=$3 bs=1 count= $PACK _size skip=$[script_size+com_size-1]" >>/tmp/compress.sh

elif [$COM _size-gt $COM _size_new];then

Sed-i "2d"/tmp/compress.sh

echo "DD if=$1 of=$3 bs=1 count= $PACK _size skip=$[script_size+com_size+1]" >>/tmp/compress.sh

Fi

com_size=$ (stat-c%s/tmp/compress.sh)

Fi

DD if=/tmp/compress.sh of=$1 count= $COM _size Bs=1 >/dev/null

DD if=$2 of=$1 count= $SCRIPT _size bs=1 seek= $COM _size >/dev/null

DD if=$3 of=$1 count= $PACK _size bs=1 seek=$[com_size+script_size] >/dev/null

3. Testing

(1) merging apache_2.4.29.tar.gz and install.sh

[email protected] 0517]# LL

Total 10020

-rw-r--r--1 root root 10251674 may 11:11 apache_2.4.29.tar.gz

-rw-r--r--1 root root 2958 may 12:03 install.sh

-rw-r--r--1 root root 1070 may 12:45 package.sh

[email protected] 0517]# bash package.sh apache_2.4.29.tar.sh install.sh apache_2.4.29.tar.gz # Note the parameter order

[email protected] 0517]# LL

Total 20036

-rw-r--r--1 root root 10251674 may 11:11 apache_2.4.29.tar.gz

-rw-r--r--1 root root 10254726 may 00:39 apache_2.4.29.tar.sh

-rw-r--r--1 root root 2958 may 12:03 install.sh

-rw-r--r--1 root root 1070 may 12:45 package.sh

(2) view apache_2.4.29.tar.sh content ( use vim or download to win on Sublime text editor )

The document is composed of three parts:

(a) decompression Section

#!/bin/bash

DD if=apache_2.4.29.tar.sh of=apache_2.4.29.tar.gz Bs=1 count=10251674 skip=3052

(b) part install.sh

(c) garbled part ( This part is apache_2.4.29.tar.gz)

(3) perform apache_2.4.29.tar.sh on the server

[Email protected] ~]# bash apache_2.4.29.tar.sh

[[email protected] ~]#/usr/local/apache/bin/apachectl start

[Email protected] ~]# Curl 127.0.0.1

4. Supplement

(1) The focus is on package.sh scripts,install.sh and apache_2.4.29.tar.gz can be adjusted according to the random.

(2) apache_2.4.29.tar.sh cannot be modified after packing , any character changes may result in script error.

Package multiple files into a single shell

Related Article

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.