Package Users - Short version

Last update: 31 december 2021.

http://www.linuxfromscratch.org/hints/downloads/files/more_control_and_pkg_man.txt documents an interesting way of managing packages. Quotation from the file:

DESCRIPTION:

The idea is to create one pair user:group per package to be installed: a package user. Every package user is part of a secondary "install" group in order to be able to write in directories that are usually owned by the root user. In order to avoid that one package replaces a file or a directory installed by another one, the directories owned by the install group have the sticky attribute for users and groups other than the root user and the install group. For more details, read http://www.linuxfromscratch.org/hints/downloads/files/more_control_and_pkg_man.txt.

The author of this hint also created some scripts really useful if one wishes to use package users on her computer. You can download the archive on http://www.linuxfromscratch.org/hints/downloads/files/ATTACHMENTS/more_control_and_pkg_man/more_control_helpers.tar.bz2.

After you have booted GLLFSC and logged in as root, you can use this package management system by doing the following:

tar xf more_control_helpers.tar.bz2
cd more_control_helpers
rm sbin/{groupadd,useradd}
mkdir -v /etc/pkgusr
cp -Rv etc/* /etc/pkgusr
mkdir -v /usr/lib/pkgusr
cp -Rv lib/* /usr/lib/pkgusr
cp -v bin/* /usr/bin
cp -v sbin/{add_package_user,install_package} /usr/sbin
chown 0:10000 $(cat installdirs.lst)
chown 0:10000 \
    /share/doc \
    /share/gtk-doc/html \
    /share/bash-completion/completions \
    /include/sys \
    /local/lib/perl5/site_perl/5.18.1 \
    /var/run
chmod g+w,o+t $(cat installdirs.lst) \
    /share/man \
    /share/info \
    /share \
    /share/aclocal \
    /etc \
    /var/lib \
    /local/bin \
    /local/lib \
    /local/include \
    /local/share \
    /local/share/* \
    /local/share/man/man* \
    /share/doc \
    /share/gtk-doc/html \
    /share/bash-completion/completions \
    /include/sys \
    /local/lib/perl5/site_perl/5.18.1 \
    /var/run
sed -i.orig '/CREATE_MAIL_SPOOL/s/yes/no/' /etc/default/useradd

Installing a package

Then:

install_package foo

will:

You have to get the source file of the program foo and install it as the user foo. Most of the time, the steps are simple:

su foo
wget http://path-to-source.org/foo-version.tar.gz
tar xf foo-version.tar.gz
cd foo-version
./configure --prefix=
make
make install
cd ..
rm -rf foo-version
rm foo-version.tar.gz
exit 0

Removing a package

To remove the files installed by a package:

find / -user foo | xargs rm

Then remove the package user:

userdel foo

Some automation

I changed the default behaviour of pkgusr in some ways. I removed build, build.conf and .project files under /etc/pkgusr/skel, then created a /etc/pkgusr/skel/build-me.sh with the following content:

# Exit on error:
set -e

wget 
tar xf 
cd 
./configure --prefix=
make install
cd ..
rm -rf 
rm 

exit 0

Then, I replaced the original content of /etc/pkgusr/bash_profile with:

#export PATH=/usr/lib/pkgusr:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/texlive/2013/bin/mips64el-unknown-linux-gnu:/usr/local/bin
export PATH=/usr/lib/pkgusr:/bin:/local/bin

# Make prompt reflect that we are a package user.
export PROMPT_COMMAND='PS1="\[\e[35m\]\A-package \u:\W\[\e[00m\]> "'

# Go to the home directory whenever we su to a package user.
cd

if [[ -f build-me.sh ]]
    then mv build-me.sh build-`whoami`.sh
    if [[ -f /src/recipes-1.6/`whoami`.sh ]]
        then cp /src/recipes-1.6/`whoami` build-`whoami`.sh
    fi
fi

alias less='less -ic'
alias make='make -j4'

To automate this, you can use my recipe for pkgusr.

Finally, I created /root/.bash_profile with the following content:

# Tab-complete package users when using su, finger or pinky
complete -o default -o nospace -A user su finger pinky