source: trunk/packs/build/sunpkg/build-package @ 20527

Revision 20527, 10.2 KB checked in by rbasch, 21 years ago (diff)
Add a hack to ensure that we install /usr/athena/lib/charset.alias only from the MIT-libiconv package.
  • Property svn:executable set to *
Line 
1#!/bin/sh
2
3# Build a standard Athena package into a Solaris package.
4
5usage="build-package [-s srcdir] [-d destdir] [-v version] [-r release]"
6usage="$usage source pkgname"
7
8sourcedir=/mit/source
9destdir=/build
10
11while getopts s:d:v:r: opt; do
12  case "$opt" in
13  s)
14    sourcedir="$OPTARG"
15    ;;
16  d)
17    destdir="$OPTARG"
18    ;;
19  v)
20    version="$OPTARG"
21    ;;
22  r)
23    release="$OPTARG"
24    ;;
25  \?)
26    echo "$usage" 1>&2
27    exit 1
28    ;;
29  esac
30done
31shift `expr $OPTIND - 1`
32
33if [ $# -ne 2 ]; then
34  echo "$usage" 1>&2
35  exit 1
36fi
37
38athena_dir=$1
39# Sun package names cannot contain underscore, so we change those to
40# hyphen.
41package_name=`echo $2 | tr '_' '-'`
42
43# XXX sigh.
44if [ third/krb5/src/appl = "$athena_dir" ]; then
45  athena_dir=third/krb5
46fi
47
48. $sourcedir/packs/build/version
49if [ "${version+set}" != set ]; then
50  version=$major.$minor
51fi
52if [ "${release+set}" != set ]; then
53  release="${ATHENA_PATCH_VERSION-$patch}"
54fi
55pkg_version=$version.$release
56
57source_name=$package_name-$pkg_version
58pkgdir=$destdir/PKG/$pkg_version
59
60# Check that we are where we ought to be, and set up the environment.
61case `uname -s` in
62SunOS)
63  OS=solaris
64  PATH=/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/usr/ucb:/usr/openwin/bin
65  arch=sparc
66  ;;
67*)
68  echo "build-package must be run on a Solaris machine" 1>&2
69  exit 1
70  ;;
71esac
72PATH=/usr/athena/bin:$PATH
73export PATH OS
74
75
76echo "==== create top-level build directories"
77
78mkdir -p \
79  $destdir/BUILD \
80  $destdir/INSTALL \
81  $pkgdir \
82  $destdir/athtools
83
84
85echo "==== prepare sources"
86
87# Copy in the sources.
88rm -rf $destdir/BUILD/$source_name
89mkdir $destdir/BUILD/$source_name
90cd $destdir/BUILD
91(cd $sourcedir/$athena_dir; tar cf - .) | (cd $source_name; tar xfpo -)
92
93
94echo "==== build package objects from source"
95
96rm -rf $destdir/INSTALL/$source_name
97mkdir $destdir/INSTALL/$source_name
98
99# Hack: create any needed directory symlinks in the target, so that
100# package files that are installed under those directories end up
101# living in the right place.
102mkdir -p $destdir/INSTALL/$source_name/usr/bin
103ln -s ./usr/bin $destdir/INSTALL/$source_name/bin
104
105for op in dist prepare all install ; do
106  (cd $source_name && \
107      $sourcedir/packs/build/do.sh -s $sourcedir \
108      -d $destdir/INSTALL/$source_name $op) || exit 1
109done
110
111# Install any "extra" files (config files, etc.) that belong to this package.
112if [ -f $sourcedir/packs/build/sunpkg/extra/$package_name ]; then
113  echo "==== build \"extra\" package objects"
114  (cd $source_name && \
115     sh -e $sourcedir/packs/build/sunpkg/extra/$package_name \
116       $sourcedir $destdir/INSTALL/$source_name) || exit 1
117fi
118
119# Hack: clean up any symlinks created above in the target, and the
120# directories they link to (if empty).
121rmdir -p $destdir/INSTALL/$source_name/usr/bin > /dev/null 2>&1
122rm $destdir/INSTALL/$source_name/bin
123
124# Do not install any info dir file generated by the build.  The dir
125# file will be managed by putting info files into their own class
126# below.
127rm -f $destdir/INSTALL/$source_name/usr/athena/info/dir
128
129# Hack: only install the charset.alias file belonging to the libiconv
130# package; otherwise, the last package installed which generated the
131# file will install its own (possibly abbreviated) version.  (The
132# libcharset mechanism assumes that the build target file is shared
133# between packages).
134if [ "$package_name" != MIT-libiconv ]; then
135  rm -f $destdir/INSTALL/$source_name/usr/athena/lib/charset.alias
136fi
137
138# Copy the built package into athtools now.
139echo "==== save tools"
140(cd $destdir/INSTALL/$source_name; tar cf - .) | \
141  (cd $destdir/athtools; tar xfp - .)
142
143echo "==== create the package prototype"
144
145# Generate the prototype file.  The awk hack changes the mode, owner,
146# and group fields for all directories which properly belong to the
147# OS, to indicate that they should be left unchanged when the package
148# is installed (implying that those directories will already exist).
149# Otherwise, those values will get reset to whatever gets generated
150# here.
151# Also, change all files in /usr/athena/info to class info, whose
152# action scripts will update the info dir file.
153prototype=/tmp/prototype$$
154rm -f $prototype
155(cd $destdir/INSTALL/$source_name && pkgproto . | nawk '{
156    if ($1 == "d" && ($3 !~ "/athena(/|$)" &&
157                      $3 !~ "^usr/afsws(/|$)" &&
158                      $3 !~ "^usr/gcc(/|$)" &&
159                      $3 !~ "^usr/prototype_user(/|$)" &&
160                      $3 !~ "^usr/vice(/|$)"))
161      print $1, $2, $3, "?", "?", "?";
162    else if ($1 == "f" && $3 ~ "^usr/athena/info/")
163      print "f", "info", $3, $4, $5, $6;
164    else
165      print $0;
166  }' > $prototype) || exit 1
167
168# If this package has a filter for editing the prototype, run it.
169if [ -f $sourcedir/packs/build/sunpkg/prototype/$package_name ]; then
170  echo "==== edit the generated prototype"
171  sh -e $sourcedir/packs/build/sunpkg/prototype/$package_name < $prototype \
172    > $prototype.new
173  if [ -s $prototype.new ]; then
174    if cmp -s $prototype $prototype.new ; then
175      echo "Warning: prototype filter for $package_name made no changes"
176    else
177      mv $prototype.new $prototype
178    fi
179  else
180    echo "prototype filter failed for $package_name"
181    exit 1
182  fi
183fi
184
185echo "==== create pkginfo"
186
187# Create the pkginfo file.
188pkginfo_source=$sourcedir/packs/build/sunpkg/pkginfo/$package_name
189
190# Prepend the pkginfo stub from the source tree.
191# The stub must contain settings for PKG and NAME; others are defaulted
192# as follows.
193cp $pkginfo_source $destdir/INSTALL/$source_name/pkginfo
194
195grep -q '^ARCH=' $pkginfo_source || \
196  echo "ARCH=$arch" >> $destdir/INSTALL/$source_name/pkginfo
197
198grep -q '^VERSION=' $pkginfo_source || \
199  echo "VERSION=$pkg_version" >> $destdir/INSTALL/$source_name/pkginfo
200
201grep -q '^CATEGORY=' $pkginfo_source || \
202  echo "CATEGORY=system" >> $destdir/INSTALL/$source_name/pkginfo
203
204grep -q '^BASEDIR=' $pkginfo_source || \
205  echo "BASEDIR=/" >> $destdir/INSTALL/$source_name/pkginfo
206
207# Get the CLASSES setting.  The order here defines the order in which
208# the class is processed at install time.  If the stub does not set
209# CLASSES, we find all classes specified in the prototype.
210# "none" is the default class, and must be listed in pkginfo. 
211grep -q '^CLASSES=' $pkginfo_source || {
212  # Find the non-default classes in the prototype.  Note that the following
213  # assumes that the prototype does not contain a "part number" field.
214  classes=`awk '$1 != "i" && $2 != "none" { print $2; }' $prototype | sort -u`
215  # Always list class "none" first.
216  echo CLASSES=none $classes >> $destdir/INSTALL/$source_name/pkginfo
217}
218
219# The following three settings are used in creating a compressed
220# archive for the "none" class in the package, speeding install time.
221# We assume that no package requires any other kind of processing for
222# this default class.
223
224# At install time, do not check for files in the package's reloc directory.
225grep -q '^PKG_SRC_NOVERIFY=' $pkginfo_source || \
226  echo "PKG_SRC_NOVERIFY=none" >> $destdir/INSTALL/$source_name/pkginfo
227
228# Do a "quick" verify after installation, i.e. skip the checksum check.
229grep -q '^PKG_DST_QKVERIFY=' $pkginfo_source || \
230  echo "PKG_DST_QKVERIFY=none" >> $destdir/INSTALL/$source_name/pkginfo
231
232# Pass package location and destination paths to the class action script,
233# instead of source/destination path pairs.
234grep -q '^PKG_CAS_PASSRELATIVE=' $pkginfo_source || \
235  echo "PKG_CAS_PASSRELATIVE=none" >> $destdir/INSTALL/$source_name/pkginfo
236
237echo "i pkginfo" >> $prototype
238
239echo "==== add other package files"
240
241# Add any other package files to the prototype.
242
243# If this package has a copyright file, copy it in.  The copyright is
244# apparently displayed only at install time by pkgadd.
245if [ -f $sourcedir/packs/build/sunpkg/copyright/$package_name ]; then
246  cp $sourcedir/packs/build/sunpkg/copyright/$package_name \
247    $destdir/INSTALL/$source_name/copyright
248  echo "i copyright" >> $prototype
249fi
250
251# Create the depend file; every package depends on MIT-base, except
252# MIT-base itself.
253if [ "$package_name" = MIT-base ]; then
254  rm -f $destdir/INSTALL/$source_name/depend
255else
256  echo "P MIT-base  A few base files needed by any Athena package" \
257    > $destdir/INSTALL/$source_name/depend
258fi
259if [ -f $sourcedir/packs/build/sunpkg/depend/$package_name ]; then
260  # Append this package's other dependencies.
261  cat $sourcedir/packs/build/sunpkg/depend/$package_name \
262    >> $destdir/INSTALL/$source_name/depend
263fi
264
265if [ -f $destdir/INSTALL/$source_name/depend ]; then
266  echo "i depend" >> $prototype
267fi
268
269# Copy in any procedure scripts (postinstall, etc.)
270for proc in checkinstall preinstall postinstall preremove postremove ; do
271  if [ -f $sourcedir/packs/build/sunpkg/$proc/$package_name ]; then
272    cp $sourcedir/packs/build/sunpkg/$proc/$package_name \
273      $destdir/INSTALL/$source_name/$proc
274    echo "i $proc" >> $prototype
275  fi
276done
277
278# Copy in the class action scripts.  Every package should have at
279# least class "none".
280classes=`grep '^CLASSES=' $destdir/INSTALL/$source_name/pkginfo | \
281            sed -e 's|^CLASSES=||'`
282for class in $classes ; do
283  for type in i r ; do
284    if [ -f $sourcedir/packs/build/sunpkg/class/$type.$class ]; then
285      cp $sourcedir/packs/build/sunpkg/class/$type.$class \
286        $destdir/INSTALL/$source_name
287      echo "i $type.$class" >> $prototype
288    fi
289  done
290done
291
292# We have completed the prototype, so copy it in.
293cp $prototype $destdir/INSTALL/$source_name/prototype
294
295
296echo "==== generate the installable package"
297
298# Make the package.
299rm -rf $pkgdir/$package_name
300(cd $destdir/INSTALL/$source_name && \
301  pkgmk -d $pkgdir -b $destdir/INSTALL/$source_name) || exit 1
302
303echo "==== build a compressed archive of the package files"
304
305# Build a compressed cpio archive of the package's files in class "none".
306filelist=/tmp/filelist$$
307mkdir -p $pkgdir/$package_name/archive
308rm -rf $filelist
309awk '(($2 == "f" || $2 == "v" || $2 == "e") && $3 == "none") { print $4; }' \
310  $pkgdir/$package_name/pkgmap > $filelist
311if [ -s $filelist ]; then
312  (cd $pkgdir/$package_name/reloc && cpio -oc -C 512 < $filelist) | \
313    bzip2 -c > $pkgdir/$package_name/archive/none.bz2 || exit 1
314  if [ ! -s $pkgdir/$package_name/archive/none.bz2 ]; then
315    echo "Failed to create compressed archive" 1>&2
316    exit 1
317  fi
318  # The archived files are no longer needed in the package reloc directory.
319  (cd $pkgdir/$package_name/reloc && cat $filelist | xargs rm -f)
320fi
321
322# Clean up.
323rm -f $prototype
324rm -f $filelist
325
326exit 0
Note: See TracBrowser for help on using the repository browser.