Iredmail Installation Script analysis (i)---get_all.sh file directory is Pkgs_linux Shell

Source: Internet
Author: User
Tags fully qualified domain name

Iredmail is a set of postfix-Core integrated messaging system installation scripts that can be used to quickly deploy mail servers.

After a series of analyses above, enter the steps to obtain the installation package, the author wrote a separate script here, get_all.sh, we continue to analyze this script

_rootdir= "$ (PWD)"
Conf_dir= "${_rootdir}/. /conf "

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

The program means to use PWD to get the current directory, defined as _rootdir, then according to _rootdir, get the specific location of the Conf directory. Thus introducing global, core ireadmin

The Iredadmin file defines a series of variables about the version and about Iredadmin that might be used when downloading files later, as shown in

Then analyze ....

Check_user Root
Check_hostname
Check_runtime_dir

According to my experience, obviously check_user check_hostname check_runtime_dir are shell functions, and we're going to analyze

Check_user is defined in the Conf/core file, and the specific code is as follows:

Check_user ()
{
 # Check special user privilege to execute this script.
 If [x "$ (id-u)"!= X "$ (id-u ${1})"]; Then
  echo_error "Please run this script as user: ${1}."
  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 is obviously getting the ID of the logged-on user, when the function is invoked, Check_user root, which is clearly judged by the return result as root, and if not root, returns an error.

Exit 255 about this, we refer to this article, http://www.jb51.net/article/73377.htm

Else after the judgment does not know whether a bit superfluous, but the author may be for insurance, again to determine whether the login user ID is 0, thereby setting the value of the path

$PATH: determines which directories the shell will look for commands or programs, and the PATH value is a series of directories that Linux searches for and compiles links to when you run a program.

The current set of this value, more than normal/root/bin/, do not know whether this step in the following procedures in the role of what, temporarily do not look out.

Then...

Check_hostname is the analysis of whether the server host name conforms to the rules, the code is as follows:

Check_hostname ()
{
 echo ${hostname} | grep ' \. ' &>/dev/null
 [x ' $]!= x "0"] && \
  echo_er ROR "Configure a fully qualified domain name (FQDN) in/etc/hosts before we go further.\n\nexample:\n\n127.0.0.1 ma il.iredmail.org mail localhost\n "&& \
  exit 255
}"

The program means using ${hostname} to obtain the hostname, if it is not in the host name. To judge the host name is unreasonable, then give an example, and then exit the program.

Shell functions are relatively simple, then analyze the Check_runtime_dir, the code is as follows:

Check_runtime_dir () {
 [D ${runtime_dir}] | | mkdir-p ${runtime_dir}

 # Cleanup rm-f ${runtime_dir}/.pkg_i
 nstall_failed &>/dev/null
}

-D to determine if the directory exists

Mkdir–p Build Directory

This should be the first judgment, the directory exists cleanup failed files, there is no build directory

Three functions to check the user, host name, status directory exists after the completion of the implementation, the installation conditions are appropriate, the next code defines the download installation package address:

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 homepage and is also the address of the download installation package. Because the script supports a number of mainstream Linux, the following code is for multiple systems to analyze and judge, 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"]; the n
 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 is the article about the Iredmail installation script analysis (i)---get_all.sh file directory for pkgs all the narration, I hope you like.

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.