Saturday, November 22, 2008

Custom tools package builder script

The custom_tools_builder script follows the standard method of building a package in linux from scratch:

Change directory to the /sources directory.
Download the package.
Check the md5sum to avoid rogue or defective software.
Download any required patches.
Run tar -tf on the package to determine the unpacked directory name.
Remove the unpacked directory name if it exists (to ensure clean sources.)
Run tar -xf on the package to extract it.
Change directory to the unpacked directory name.
Run the commands from the BOOK.
If the build finished successfully the unpacked sources are no longer needed.
Change directory to .. (up one level -- you should again be in the /sources directory.)
Run rm -r on the unpacked directory name.

Since at least one of the commands from the BOOK must be run as root or sudo (especially "make install"), people sometimes run all the above steps as root or sudo.

The pkg_builder function performs the above steps based on the PKG_FILE, URL, MD5, and commands found in the CUSTOM_TOOLS_SCRIPT. That information is supplied by you from the BOOK. Even for packages not in the BOOK, you can do your best to fill in the information appropriately. Even though writing the CUSTOM_TOOLS_SCRIPTs is a little extra work, it can provide benefits in the long run. The scripts are based on the format of the template file in the jhalfs/custom directory although jhalfs if not required for building with the custom_tools_builder.

Sometimes a package does not build with the results you desire, and if that happens, the commands must be modified and the package rebuilt. Other times, the order in which packages are built may need to be modified to get the desired results. Once a package is built so that it performs as desired, you may want the necessary information documented for a future build.

In addition to running the pkg_builder function, the custom_tools_builder script generates some useful information that should be saved to a log file. The recommendation is to have a log directory and to give the log file the same name as the CUSTOM_TOOLS_SCRIPT. It is recommended to put a comment beginning with "# PACKAGE NAME:" in the custom tools script with the package name and version because it may be useful later.

Here is an example run:
pkg="custom/config/1011-pkg-config"
logfile="logs/$(basename $pkg)"
sh custom_tools_builder ${pkg} 2>&1 | tee $logfile

The data collected in the log file includes all output of all steps (including errors), the amount of time the script ran, and files that were installed or updated.

The logfile ends with a file listing.

You could see the list of files installed/updated with:
sed -e '1,/^FILE LISTING/d' $logfile \
| awk '{if ($4!~/d/) {print $2}}'

Do not use that list to delete files if the list contains any files in the /etc directory!

Do not use that list to delete files if there are other packages that depend on the package!

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Click blog title for the latest post