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

Re: deb_{install,remove}



Marcus Brinkmann writes:
 >  
 > > I have some plans for the deb_{install,remove} scripts that I sent
 > > to you yesterday,
 > > 
 > >     1) I plan to have deb_remove accept a package name or a .deb
 > > file as its only argument, and remove the package's files
 > > according to the dpkg/info/package-name.list file or the tar
 > > listing from the .deb file, respectively.  Quite a mouthful for
 > > such a simple idea.
 > 
 > Yeah, I know my two argument thing was only a quick hack :)
 >  
 > >     2) Merge the install & remove scripts into one file, which
 > > then uses the name that it was called with to figure out what to
 > > do.  The current user interface would then remain as it is, with
 > > symlinks of each name pointing to the unified script file.
 > 
 > Please consider taking an argument option. "-i" for install and "-r" for
                                              ^^^^^^^^^^^^^^^^^^^^^^^^
Will do when I do the merge, right now I am too tired.

 > removal.
 > 
 > And don't spent too much time on it. Although appreciated, I hope we can
 > soon use a native dpkg on the Hurd. :)

The latest versions of deb_{install,remove} are attached to this
email.  I hope I got most of the bugs out.  I had some fun when I
removed mount, login, reboot, umount from my running system.

I am a devotee of Foghorn Leghorn, who "keeps his feathers
numbered for just such an emergency".

Cheers,

-- 
Jeff Sheinberg  <jeffsh@erols.com>

-------------------cut---------------------
#!/bin/sh
#
# Copyright (c) 1998 - This script is hereby placed in the public domain
#                      by Marcus Brinkmann.
#
# deb_install - poor man's dpkg install.
#
# Usage - deb_install package_*.deb
#
# 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.
#

set -u -e

PS4='+$LINENO: '

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

vld="var/lib/dpkg"
vldi="${vld}/info"
[ -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"

[ "$#" == 1 ] || err "exactly one argument, a *.deb file is required"
file="${1}"
name="${file%%_*}"
name="${name##*/}"

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

# Extract the files from the .deb archive.
[ -e ${vldi}/${name}.list ] && err "package \`${name}' is already installed"
dpkg-deb --extract ${file} .

# Create `name.list' file from tar listing:
#    1. remove object of symlink -e 's/ -> .*$//'
#    2. remove trailing "/"      -e 's/\(.*\)\/$/\1/'
#    3. add leading "/"          -e 's/^/\//'
dpkg-deb --contents ${file} | colrm 1 49 | \
  sed -e 's/ -> .*$//' -e 's/\(.*\)\/$/\1/' -e 's/^/\//'  >${vldi}/${name}.list

# Extract control info and create control files.
dpkg-deb --control ${file} ${vldi}
if [ -e ${vldi}/preinst ] ; then
     mv ${vldi}/preinst  ${vldi}/${name}.preinst
fi
if [ -e ${vldi}/postinst ] ; then
     mv ${vldi}/postinst ${vldi}/${name}.postinst
fi
if [ -e ${vldi}/prerm ] ; then
     mv ${vldi}/prerm    ${vldi}/${name}.prerm
fi
if [ -e ${vldi}/postrm ] ; then
     mv ${vldi}/postrm   ${vldi}/${name}.postrm
fi
if [ -e ${vldi}/shlibs ] ; then
     mv ${vldi}/shlibs   ${vldi}/${name}.shlibs
fi

# Replace `Architecture' record with `Status' record.
cat ${vldi}/control | \
  sed -e 's/^Architecture: .*$/Status: hold ok installed/' >>${vld}/status
echo  >>${vld}/status
rm      ${vldi}/control

exit 0

# deb_install - end of file.
-------------------cut---------------------

-------------------cut---------------------
#!/bin/sh
#
# Copyright (c) 1998 - This script is hereby placed in the public domain
#                      by Jeff Sheinberg.
#
# deb_remove - poor man's dpkg remove.
#
# Usage - deb_remove package | package_*.deb
#
# 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:
#    22 Dec 1998 - v0.0 Jeff Sheinberg <jeffsh@erols.com>
#        Original created by Jeff Sheinberg.
#    24 Dec 1998 - v0.1 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.
#

set -u -e

PS4='+$LINENO: '

msg ()
{
    echo -e "$@" 1>&2
}

err ()
{
    msg "$0: $1"
    exit 1
}

warn ()
{
    msg "$0: $1"
}

delete_file ()
{
    local path

    while read -r path; do
        path=".${path}"
        if   [ -L "${path}" ]; then
            rm    "${path}"
        elif [ -d "${path}" ]; then
            find  "${path}" -maxdepth 0 -empty -exec rmdir '{}' \;
        elif [ -e "${path}" ]; then
            rm    "${path}"
        fi
    done
}

rm_ifexist ()
{
    if [ -e "${1}" ]; then
        rm  "${1}"
    fi
}

vld="var/lib/dpkg"
vldi="${vld}/info"
[ -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"

[ "$#" == 1 ] || \
  err "exactly one argument, a package name or *.deb file is required"
file="${1}"
name="${file%%_*}"
name="${name##*/}"

# Determine if called with package name or .deb file.
if [ "${file%.deb}.deb" == "${file}" ]; then
    deb_file=yes
    [ -f "${file}" ] || err "file \`${file}' does not exist"
else
    deb_file=no
    [ -f ${vldi}/${name}.list ] || warn "package \`${name}' does not seem to be installed\n...removing any leftover fragments anyway."
fi

# Delete status file records, then remove any leftover control file.
if [ -f ${vld}/status -a -s ${vld}/status ]; then
    cp  ${vld}/status  ${vld}/status.bak
    sed -e "/^Package: ${name}\$/,/^\$/d"  ${vld}/status.bak  >${vld}/status
fi
rm_ifexist ${vldi}/control

# Remove remaining info files.
rm_ifexist ${vldi}/${name}.shlibs
rm_ifexist ${vldi}/shlibs
rm_ifexist ${vldi}/${name}.postrm
rm_ifexist ${vldi}/postrm 
rm_ifexist ${vldi}/${name}.prerm
rm_ifexist ${vldi}/prerm
rm_ifexist ${vldi}/${name}.postinst
rm_ifexist ${vldi}/postinst
rm_ifexist ${vldi}/${name}.preinst
rm_ifexist ${vldi}/preinst

# Use ${name}.list or .deb file tar listing to remove files, in reverse
# name order.  Creating `name.list' file listing from tar listing:
#    1. remove object of symlink -e 's/ -> .*$//'
#    2. remove trailing "/"      -e 's/\(.*\)\/$/\1/'
#    3. add leading "/"          -e 's/^/\//'
if [ ${deb_file} = yes ]; then
    dpkg-deb --contents ${file} | colrm 1 49 | \
      sed -e 's/ -> .*$//' -e 's/\(.*\)\/$/\1/' -e 's/^/\//' | \
      tac | delete_file
elif [ -f ${vldi}/${name}.list ]; then
      tac ${vldi}/${name}.list | delete_file
fi
rm_ifexist ${vldi}/${name}.list

# Replace ./usr if it was removed.
[ -e ./usr ] || ln -s . usr

exit 0

# deb_remove - end of file.
-------------------cut---------------------


Reply to: