Wednesday, November 25, 2015

Source management tool

Recently I got Linux From Scratch book in my hands and I've built my own distribution. It was a great experience and I've learned a lot about core Linux system. Either way one simple question came to my mind: how can I manage all those packages from source archives?

This topic is mentioned in the book where a few methods are briefly described. Based on this knowledge, I've created a simple package manager.

The idea was that, all packages will install some new files. So you can simply find all files installed by some package, and store the list for later use (e.g. when you'll need to upgrade some package).

Following script should be run after make install command. It will find all new files (created within last 3 minutes) and store them in repository ($HOME/sources/_pkg.info)

cat $HOME/bin/makepkg:
#!/bin/bash
###########################################
# Year:     2015
# About:    Simple source management tool
# Author:   krisko
###########################################
 
# search packages not older than X minutes
MIN=3
# get current path
CDIR=$(pwd)
# get current date
DATE=$(date +%Y%m%d-%H%M)

read -p "Save package info for '${CDIR##*/}'? (Y/n) " yesno
[[ $yesno == n ]] && read -p "Enter package name: " CDIR

# after package install, get newly installed files list
# save log in file called the same as current directory
find $HOME/pkgs -mmin -$MIN > $HOME/sources/_pkg.info/${CDIR##*/}_$DATE.pkg

# find all files & links
find $HOME/pkgs -type f -o -type l > $HOME/sources/_pkg.info/_pkg_filelist

read -p "List new files? (Y/n) " yesno
[[ $yesno == n ]] && exit 0

# grep package files from current dir files list (does not include directories)
while read pkgfile; do 
    grep -o ^${pkgfile}$ $HOME/sources/_pkg.info/_pkg_filelist; 
done <$HOME/sources/_pkg.info/${CDIR##*/}_$DATE.pkg


####################################################
# TODO/ChangeLog # Author            # Description
####################################################
# 1.0.0 20151022 # krisko            # Genesis
####################################################
In the following example, we will install xsel from the source code:

  1. tar xf xsel-1.2.0.tar.gz
  2. cd xsel-1.2.0
  3. ./configure --prefix=/home/krisko/pkgs
  4. make
  5. make install
  6. makepkg
- /home/krisko/pkgs is the default location, for new installations (this is also set in the script)
- makepkg command will create a file /home/krisko/sources/_pkg.info/xsel-1.2.0_20151023-0948.pkg
- this file will contain list of all files installed by xsel package, thus making it easy to identify, which files belong to this package.


No comments:

Post a Comment