[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

dpkg_hurd, a replacement for deb_{install,remove}


deb_{install,remove} worked fine, but had some problems with regard to conf
files etc. Reimplementing dpkg's behaviour in a simple fell script is not
feasible in the short life span of these scripts.

I therefore followed another approach in my new script, dpkg_hurd, which is
heavily based on Jeff's deb_install. It is a all-in-on-place package:

Install a package:  dpkg_hurd -i|--install packagefile.deb
Remove  a package:  dpkg_hurd -r|--remove  packagename
Purge   a package:  dpkg_hurd --purge      packagename

You can also use the options "-s, -S, -l, -L" as under Debian GNU/Linux. The
only thing the script does here is adding "--root=." to the dpkg invocation.
The behaviour in the above cases is a bit more complex.

When installing, the script does build a new Debian package, containing not
the installation scripts, and hands that over to dpkg. When removing, it moves
the installed removal scripts out of the way. Because of the rebuild, you
need thrice the disk space available as the size of the Debian package
itself. This could be optimized by modifying the ar archive directly. I
couldn't figure out how, maybe someone else wants to do it. (Dpkg does add a
special header to the ar archive, which gets mangled when you perform
operations on the archive).

The advantage is that no installation knowledge is builtin the script. It
leaves everything to dpkg, who knows well how to do it. This should solve
all sort of conffile and other problems. A further advantage is that the new
script is simple.

Have fun,

"Rhubarb is no Egyptian god."        Debian GNU/Linux        finger brinkmd@ 
Marcus Brinkmann                   http://www.debian.org    master.debian.org
Marcus.Brinkmann@ruhr-uni-bochum.de                        for public  PGP Key
http://homepage.ruhr-uni-bochum.de/Marcus.Brinkmann/       PGP Key ID 36E7CD09
# Copyright (c) 1998 - This script is hereby placed in the public domain
#                      by Marcus Brinkmann.
# dpkg_hurd - poor man's dpkg.
# Usage - dpkg_hurd -i|--install package_*.deb
#    or - dpkg_hurd -r|--remove package
#    or - dpkg_hurd --purge package
#    or - dpkg_hurd -s|-L package
#    or - dpkg_hurd -l|-S  pattern
# Warning: This script is for bootstrapping a Debian/Gnu Hurd system
#          onto an empty ext2 partition.  The {pre,post}{inst,rem}
#          scripts are not run.
# Change history:
#    19 Dec 1998 - v0.0 <Marcus.Brinkmann@ruhr-uni-bochum.de>
#        Original created by Marcus Brinkmann.
#    22 Dec 1998 - v0.1 Jeff Sheinberg <jeffsh@erols.com>
#        Error checking, automatic update of status file.
#    24 Dec 1998 - v0.2 Jeff Sheinberg <jeffsh@erols.com>
#        Remove by package name, fix bugs in name.list file creation.
#    TODO - add lockfile and trap exit & int, merge with deb_remove.
#    28 Dec 1998 - v0.3 Marcus Brinkmann <brinkmd@debian.org>
#        Extract package name from deb file, not from file name.
#        Rebuild package w/o install scripts and use dpkg directly.
#        Added -r and -p as well as -s,-S,-l,-L options.
#    TODO - fix all those race conditions and use proper tmp dir!

set -u -e

PS4='+$LINENO: '

err ()
    echo "$0: $1" 1>&2
    exit 1

[ -d ./${vld} ] || \
  err "cd is \`$PWD', must be run from a dpkg root directory"
[ -d ./lost+found ] || \
  err "cd is \`$PWD', must be run from a partition root filesystem directory"
[ -L ./usr -a ./ -ef usr/ ] \
  || err "cd is \`$PWD', must be run from a hurd root filesystem directory"

[ "$#" == 2 ] || err "exactly two arguments, an action and a *.deb file or package name is required"

if [ "${1}" == "-i" -o "${1}" == "--install" ] ; then

	name=`dpkg --info ${file} | grep Package - | sed -e "s/ Package: //"`

	[ -f ${file} ] || err "file \`${file}' does not exist"

	# Construct directory hierarchie
	mkdir -m 0755 -p ${ctrl}

	# Extract the files from the .deb archive.
	dpkg-deb --extract ${file} ${ctrl}/..

	# Extract control info and create control files.
	dpkg-deb --control ${file} ${ctrl}

	# Move the package scripts out of the build dir.
	for f in preinst postinst prerm postrm
	  if [ -e ${ctrl}/${f} ] ; then
	     mv ${ctrl}/${f} temp_build/

	# Now repack the file.
	dpkg --build temp_build/${name}

	# Move old prerm and postrm scripts out of the way.
	for f in prerm postrm
	  if [ -e ${vldi}/${name}.${f} ] ; then
	     mv ${vldi}/${name}.${f} ${vldi}/${name}.${f}.backup

	dpkg --root=. --force-architecture --install temp_build/${name}.deb

	# Move new package scripts into dpkg's repository
	for f in preinst postinst prerm postrm
	  if [ -e temp_build/${f} ] ; then
	     mv temp_build/${f} ${vldi}/${name}.${f}
	  if [ -e ${vldi}/${name}.${f}.backup ] ; then
	     rm ${vldi}/${name}.${f}.backup

	# Clean temp directory.
	rm -fR temp_build


if [ "${1}" == "-r" -o "${1}" == "--remove" -o "${1}" == "--purge" ] ; then

	# Move old prerm and postrm scripts out of the way.
	for f in prerm postrm
	  if [ -e ${vldi}/${name}.${f} ] ; then
	     mv ${vldi}/${name}.${f} ${vldi}/${name}.${f}.backup

	dpkg --root=. --force-architecture ${1} ${name}

	for f in prerm postrm
	  if [ -e ${vldi}/${name}.${f}.backup ] ; then
	     rm ${vldi}/${name}.${f}.backup

if [ "${1}" == "-s" -o "${1}" == "-S" -o "${1}" == "-l" -o "${1}" == "-L" ] ; then
	dpkg --root=. "${1}" "${2}"

exit 0	

# deb_hurd - end of file.

Reply to: