Using Python to implement a Cross-platform Setup program

Source: Internet
Author: User
Tags implement requires

Introduction

When using Unix-like systems, we often use installers (Installer) that end with ". Bin" or ". Run". (for the convenience of the description, here we use "Bin installer" to refer to this installation program.) The Bin installer does not rely on the system release's own package (package) Manager to implement the installation and uninstallation of the application, but rather controls the entire process of installation, which requires the user to perform an uninstall script under the application installation directory when the program is unloaded.

The biggest benefit of the Bin installer is that it can run on a variety of Unix-like platforms and on multiple distributions based on the same core without caring what package managers the system uses. To a certain extent to achieve a cross-platform.

Unfortunately, this installer is not available on the Windows platform. The installer on the Windows platform requires special production. This is caused by the Bin installer itself using Shell scripts common to Unix-like platforms to guide and control the entire installation process.

The good news is that we now have a powerful script-python that can run simultaneously on Unix-like platforms and Windows platforms. With the popularity of Python, more and more system integration began to be done on the basis of Python, so that a large number of Unix-like platforms now deploy Python's operating environment by default. Even without a default installation, users may have Python installed when installing other applications.

So, can we use Python to implement a setup program that can be common to both Unix-like platforms and Windows platforms? How does this installer work? This article will discuss this issue with you and provide a way to solve this problem. In this paper, the cross-platform capability of the installer is discussed, and only the cross-platform features and implementation methods of the installer itself are addressed.

This paper first analyzes the structure and working principle of Bin Installer, and then describes how to implement similar functions using Python, and discusses the limitations of Python implementation and possible solutions.

Procedure for Bin installer execution

The Bin installer provides a number of wizard interfaces at the very beginning of the run, providing users with information about the products being installed and directing the user to enter the configuration information that the installer needs. After the installer has acquired the required configuration information, it enters the specific installation phase.

During the installation phase, the Bin installer first expands the packages that contain configuration information for the libraries and installers on which the installer relies, as well as the user applications that will be installed.

In fact, the process of these packages being expanded is divided into two stages. In the first phase, the installer separates the compressed files of these packages from the installer itself, generating a separate compressed file. Then, in the second phase, use the decompression tool to extract the compressed files and set the desired system environment variables. The most basic is the two variables of PATH and Java_home.

After that, the installer reads the installation configuration, obtains the user-defined installation scripts (pre-install, Post-Install), and executes them in the order in which they are established.

Finally, the installer merges the installed file list and uninstall program templates, as well as user-defined uninstall scripts (Pre-uninstall, Post-uninstall) that are recorded during installation, to build the uninstall program and put it into the user application's installation directory.

Implementation analysis of Bin installation program

So how does the Bin installer control the entire process, and what structure does the installer file itself have? We'll do the analysis next.

The Bin installer itself is actually a Shell script that contains binary data. A simple setup program can consist of a piece of scripting code plus a binary data of a compressed package. Complex may contain multiple segments of binary data.

The basic structure of the document is the following diagram

Diagram 1:bin file structure diagram

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.