[How To] Import: The MidnightBSD Package Management Tools
One of the most tedious tasks in setting up and maintaining a personal computer is installing software applications. The BSD community has historically handled this by providing users a ports system to compile software and later some package management software.
This approach has worked well for power users. The Linux community has built some user friendly package management tools with command line and graphical user interfaces. In minutes, one can install a new web browser or word processor.
When I started the MidnightBSD project, the goal was to bring the benefits of BSD to novice users. Three problems were identified: installing MidnightBSD, managing software, and setting up a graphical user interface. It was clear that package management was essential to solving these problems.
Chris Rienhardt and I started working on these problems in 2007. We planned a new system which required changes to mports, our ports collection, and new tools to manage packages. Chris made the necessary changes to the mports system and started working on a new library to create and manage packages. The system uses SQLite3 to store information about available packages, currently installed software and a list of installed files. By the MidnightBSD 0.3-RELEASE, we had working programs to install and uninstall software from the ports system. The system still lacked a front-end management tool. I decided to develop a tool similar to apt-get, but built around libarchive, libmport, and SQLite3. This new tool will be available in the next release, 0.4 for end users and is available for testing in the development version of MidnightBSD, 0.4-CURRENT.
Every task to be performed starts with mport followed by a command verb and optionally a software package name.
Searching for software, will check package titles and descriptions for matching phrases:
mport search gzip
Learn about the software package, including if it’s currently installed, the version and the license:
mport info gzip
If you know the name of the software package to install:
mport install gzip
Dependencies required by the package are installed automatically.
clean: Clean up old packages and database
list: List installed software
info: Print information about a software package
delete: Delete a software package
deleteall: Delete all software packages currently installed
download: Download a package, but do not install it
install: Install software
search: Search for software
update: Update a single program
upgrade: Update all software installed on the system
To uninstall a package, use
mport delete gzip
note that this does not delete the package file from the system, it only uninstalls the software.
Listing Installed Software?
List all software currently installed on the system:
List installed software that is out of date:
mport list updates
Update all software on the system:
Update a specific package, will download the package if necessary:
mport update gzip
Clean up old packages and compress the database with:
Packages will be removed from /usr/mports/Packages. Consult the mport (1) manual for more information.
Power Users and Developers
In addition to the mport command, power users can write custom scripts or programs to manipulate the package
database. Files used by mport are stored in /var/db/mport. The master.db file contains all of the installed package data while index.db contains the list of available packages from the MidnightBSD package build cluster, magus. Users can open index files with the sqlite3 command line utility and run SQL queries. Installation logs are available in the logs table, and settings for mirrors to download packages from are stored in the settings table. A program to make it easy to run queries is available at /usr/libexec/mport.query.
C, C++ and Objective-C programmers can use libmport to write their own package tools. The source code is available in src/lib/libmport with public functions prefixed with MPORT_PUBLIC_API.
Example output from mport info command
mport info gzip gzip latest: 1.3.13 installed: 1.3.13 license: gpl3 origin: archivers/gzip A compression utility designed to be a replacement for compress
The mports collection makes use of several simple applications written for a specific task. For example, when a package is created using the package target in mports, the program /usr/libexec/mport.create is run to make the package followed by /usr/libexec/mport.install to install the package with the install target. Another useful program is /usr/libexec/mport.init as it creates a fresh master.db in the event that it’s been corrupted or deleted by mistake.
Following the 0.4-RELEASE of MidnightBSD, I plan to write a graphical application to manage package installations. Further improvements to the system may include using xz for index downloads, improving documentation, fastest mirror selection and refining the upgrade logic. While mport and libmport were designed for the MidnightBSD mports collection, it could be used by other BSD projects.
mport is the package management solution for MidnightBSD that allows a user to install, update, and delete software packages. It is easy to use, but provides many extension mechanisms for power users to script or automate installations.
Source: BSD Magazine Vol5, N02