Iredmail installation script analysis (1) --- iRedmail. sh, iredmail installation and configuration

Source: Internet
Author: User

Iredmail installation script analysis (1) --- iRedmail. sh, iredmail installation and configuration

Iredmail is a set of installation scripts that integrate the mail system with postfix as the core, which can be used to quickly deploy the mail server. In order to keep yourself from forgetting the shell syntax, you have nothing to worry about and learn his code.

I downloaded his latest version from the official website. After decompression, the structure is as follows:

IRedMail. sh is the Startup File for installation. After bash iRedMail. sh is executed, the installation starts. We can see from this file.

tmprootdir="$(dirname $0)"
 
Dirname is used as follows:
 
(1) full path, for example, aguo @ auto-test: ~> Dirname/home/aguo/insert. SQL
/Home/aguo # obtain the directory where the file is located
 
(2) Only file names, for example, aguo @ auto-test: ~> Dirname Environment

. Indicates that the path is the current directory.

$0 in shell indicates that the name of the currently executed script $ () plays the role of command replacement in shell, so that the value of tmprootdir is the directory of the currently executed script, determine the directory as follows

A command involves three knowledge points, and it seems that learning can deepen your impression.

The second command is as follows:

echo ${tmprootdir} | grep '^/' >/dev/null 2>&1
 
| Pipeline operator. The output of the command on the left of the pipeline operator serves as the input of the command on the right of the pipeline operator. The continuous use of pipelines means that the output of the first command will be used as the input of the second command, and the output of the second command will be used as the input of the Third Command, and so on.
 
Grep '^/' is used to find the Regular Expression of grep starting /.
 
>/dev/null 2>&1  :
 
You can think of/dev/null as a "black hole ". it is very equivalent to writing only files. all content written to it will be lost forever. however, if you try to read content from it, nothing can be read.
 
1 indicates stdout standard output. The default value is 1. Therefore, ">/dev/null" is equivalent to "1>/dev/null"
 
2 indicates stderr standard error
 
& Indicates equivalent, 2> & 1, indicating that 2's output redirection is equivalent to 1
 
Many shell scripts are used. The actual function is not to output any content.

The overall purpose of this command is to find the value of the variable tmprootdir starting with/. The following will be determined based on the status code.

if [ X"$?" == X"0" ]; then    export ROOTDIR="${tmprootdir}"else    export ROOTDIR="$(pwd)"fi
 
 
 
The export command can be used to set or display environment variables. In shell, when a variable is created, it only takes effect in the current shell, and the child process created later does not have the variable. The command export can change a shell variable to an environment variable, and the environment variable can be accessed in the subsequently created sub-process. However, after the sub-process modifies the value of the environment variable, the parent process does not know, because the child process will copy the environment variable of the parent process. Therefore, when the shell exits, the environment variables export in the shell will also disappear.
 
In this case, the value of ROOTDIR will be retained in the subsequent script.
 
[X "$? "= X" 0 "] is used to prevent $? If it is empty, it is set up, but the online materials seldom mention $? The status returned after the command is executed. if the success is 0 and the failure is another value, if else judges the statement according to $? To determine the absolute path of the script. This judgment is for multiple systems. In some systems, the dirname may have an absolute path value, therefore, echo $ {tmprootdir} | grep '^/'>/dev/null 2> & 1. If there is a value, you can directly determine the absolute path of the script; if there is no value, use pwd to obtain it again.

After determining the absolute path of the system where the script is located, you can call some function libraries and global variables. The following code:

cd ${ROOTDIR}export CONF_DIR="${ROOTDIR}/conf"export FUNCTIONS_DIR="${ROOTDIR}/functions"export DIALOG_DIR="${ROOTDIR}/dialog"export PKG_DIR="${ROOTDIR}/pkgs/pkgs"export PKG_MISC_DIR="${ROOTDIR}/pkgs/misc"export SAMPLE_DIR="${ROOTDIR}/samples"export PATCH_DIR="${ROOTDIR}/patches"export TOOLS_DIR="${ROOTDIR}/tools". ${CONF_DIR}/global. ${CONF_DIR}/core

It basically contains all the configuration files and specific variable files to be used after the system. global is the global variable file. core is the core file, which will be analyzed later, from the perspective of syntax, there is no difficulty, only. need to explain

. $ {CONF_DIR}/global introduce all the variables or functions in the script to run, and analyze the specific variables later.

 

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.