File: dpkg-hurd

package info (click to toggle)
crosshurd 1.7.39
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 168 kB
  • ctags: 1
  • sloc: sh: 421; makefile: 1
file content (171 lines) | stat: -rwxr-xr-x 5,111 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/sh
#
# 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 [options]
#    or dpkg-hurd --unpack package_*.deb [options]
#    or dpkg-hurd -r|--remove package [options]
#    or dpkg-hurd --purge package [options]
#    or dpkg-hurd -s|-L package
#    or dpkg-hurd -l|-S  [pattern]
#
#    [options] are passed through to dpkp. A good example is
#              "--force-depends".
#
# 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.
#
# Note:    The action must be the first argument, the package the second.
#          Multiple packages can't be processed at one command line.
#
# 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.
#     1 Jan 1999 - v0.3.1 Marcus Brinkmann <brinkmd@debian.org>
#                  Added the possibility to add options.
#                - v0.3.2 Fixed typo in grep (Package: instead Package)
#    15 Apr 1999 - v0.3.3 Make it a bit more verbose (Pavel Roskin)
#                  Specify admindir explicitely to make it work on
#                  non-Debian systems. (patch by Pavel Roskin)
#    TODO - fix all those race conditions and use proper tmp dir!
#                - v0.3.3 Minor fix by Matthew Vernon <mcv21@cam.ac.uk>
#                  No longer expects the /usr -> / symlink
#    27 May 1999 - v1.0.1 More patches by Pavel Roskin for compatibility.
#                  Make use of case instead -o to test.
#                  Add --force-not-root.
#     1 Jun 1999 - v1.0.2 Patch by Kalle Olavi Niemitalo to make it work
#                  with packages which Contain the string "Package" in
#                  the description.
#     7 Sep 1999 - v1.0.3 Add --force-bad-path. Suggested by Espy.

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 where lost+found resides"
#[ -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"

case ${1} in
"-i"|"--install"|"--unpack")

	action="${1}"
	file="${2}"
	name=`dpkg --info ${file} | grep '^ Package:' - | sed -e "s/ Package: //"`

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

	# Construct directory hierarchie
	ctrl=temp_build/${name}/DEBIAN
	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
	do
	  if [ -e ${ctrl}/${f} ] ; then
	     mv ${ctrl}/${f} temp_build/
	  fi 
	done

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

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

	shift
	shift
	dpkg --root=. --admindir=${vld} --force-architecture --force-not-root --force-bad-path ${action} ${@-} temp_build/${name}.deb

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

	# Clean temp directory.
	rm -fR temp_build
	exit 0
	;;
esac

case ${1} in
"-r"|"--remove"|"--purge")

	action="${1}"
	name="${2}"

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

	shift
	shift

	dpkg --root=. --admindir=${vld} --force-architecture --force-not-root --force-bad-path ${action} ${@-} ${name}

	for f in prerm postrm
	do
	  if [ -e ${vldi}/${name}.${f}.backup ] ; then
	     rm ${vldi}/${name}.${f}.backup
	  fi
	done
	exit 0
	;;
esac
	
case ${1} in
"-s"|"-S"|"-l"|"-L")
	dpkg --root=. --admindir=${vld} "${@}"
	exit 0
	;;
esac


# dpkg-hurd - end of file.