Analysis of installation script under iredmail (I) — get_ The directory of all.sh file is Pkgs

Time:2021-11-30

Iredmail is a set of installation script of integrated mail system with postfix as the core, which can achieve the purpose of rapid deployment of mail server.

After the above series of analysis, we enter the step of obtaining the installation package. The author wrote a separate script here, get_ All. Sh, let’s continue to analyze the script

_ROOTDIR=”$(pwd)”
CONF_DIR=”${_ROOTDIR}/../conf”

. ${CONF_DIR}/global
. ${CONF_DIR}/core
. ${CONF_DIR}/iredadmin

Program means to use PWD to obtain the current directory and define it as_ Rootdir, then according to_ Rootdir to obtain the specific location of the conf directory. Thus, global and core ireadmin are introduced

A series of variables about version and about iredadmin are defined in the iredadmin file. It is estimated that they may be used when downloading the file later, as shown in the figure

Then analyze….

check_user root
check_hostname
check_runtime_dir

In my experience, obviously check_ user   check_ hostname check_ runtime_ Dir is a shell function. Let’s analyze it one by one

check_ user   It is defined in the conf / core file. The specific code is as follows:


check_user()
{
 # Check special user privilege to execute this script.
 if [ X"$(id -u)" != X"$(id -u )" ]; then
  ECHO_ERROR "Please run this script as user: ."
  exit 255
 else
  if [ X"$(id -u)" == X"0" ]; then
   export PATH="/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
  else
   :
  fi
 fi
}

id   – u     Obviously, it is to obtain the ID of the login user. When calling the function, check_ user   Root is obviously used to judge whether it is root according to the returned result. If it is not root, an error is returned.

exit    two hundred and fifty-five    For this, please refer to this article,https://www.jb51.net/article/73377.htm

After else, I don’t know whether it’s a little redundant, but the author may decide again whether the login user’s ID is 0 for insurance, so as to set the path value

$path: determines which directories the shell will look for commands or programs. The value of path is a series of directories. When you run a program, Linux will search and compile links in these directories.

The currently set value is much higher than the normal value of / root / bin /. I don’t know whether this step plays any role in later programs. I can’t see it for the time being.

next…

check_ Hostname is used to analyze whether the host name of the server complies with the rules. The code is as follows:


check_hostname()
{
 echo ${HOSTNAME} | grep '\.' &>/dev/null
 [ X"$?" != X"0" ] && \
  ECHO_ERROR "Please configure a fully qualified domain name (FQDN) in /etc/hosts before we go further.\n\nExample:\n\n127.0.0.1 mail.iredmail.org mail localhost\n" && \
  exit 255
}

The program means to use ${hostname} to obtain the host name, if there is no host name in the host name   Judge that the host name is unreasonable, then give an example, and then exit the program.

Shell functions are relatively simple, and then analyze check_ runtime_ Dir, the code is as follows:


check_runtime_dir() {
 [ -d ${RUNTIME_DIR} ] || mkdir -p ${RUNTIME_DIR}

 # Cleanup
 rm -f ${RUNTIME_DIR}/.pkg_install_failed &>/dev/null
}

-d   Determine whether the directory exists

mkdir –p     create directory

Here, you should make a judgment first. There are files that failed to clean up in the directory, and there is no directory to build

After the three functions to check whether the user, host name and status directory exist are executed, it indicates that the installation conditions are suitable. The following code defines the address to download the installation package:

export IREDMAIL_MIRROR=”${IREDMAIL_MIRROR:=http://iredmail.org}”
export PKG_DIR=”${_ROOTDIR}/pkgs”
export PKG_MISC_DIR=”${_ROOTDIR}/misc”
http://iredmail.org  This is the author’s official home page and the address to download the installation package. Because the script supports multiple mainstream Linux, the following code is used to analyze and judge multiple systems. Look at the code


if [ X"${DISTRO}" == X"RHEL" ]; then
 # Special package.
 # command: which.
 export BIN_WHICH='which'
 export PKG_WHICH='which'
 # command: wget.
 export BIN_WGET='wget'
 export PKG_WGET='wget'
elif [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then
 if [ X"${OS_ARCH}" == X"x86_64" ]; then
  export pkg_arch='amd64'
 else
  export pkg_arch="${OS_ARCH}"
 fi
 # Special package.
 # command: which.
 export BIN_WHICH='which'
 export PKG_WHICH="debianutils"
 # command: wget.
 export BIN_WGET='wget'
 export PKG_WGET="wget"
 # command: dpkg-scanpackages.
 export BIN_CREATEREPO="dpkg-scanpackages"
 export PKG_CREATEREPO="dpkg-dev"
fi

The above content is about the analysis of installation script under iredmail (I) — get_ The directory where all.sh file is located is the full description of Pkgs. I hope you like it.