source: trunk/packs/build/sunpkg/install-srvd.sh @ 20596

Revision 20596, 6.5 KB checked in by rbasch, 21 years ago (diff)
Run pkg-prune after updating an existing package, to remove old files.
Line 
1#!/bin/sh
2
3# $Id: install-srvd.sh,v 1.5 2004-07-30 20:54:51 rbasch Exp $
4
5# This script installs packages for a new release into the srvd,
6# running pkgadd with the srvd as the target root, and copying
7# the new packages into the srvd package directory for the new
8# version.  For a patch release, it also invokes link-pkgs to
9# create the links to old packages in the new package directory.
10# Finally, it creates the .order-version file in the new package
11# directory.
12
13prog=$0
14maybe=
15init_dest=false
16newver=
17pkgsrc=
18source=/mit/source
19srvd=/.srvd
20srvd_ro=/srvd
21
22usage="Usage: $prog [-n] [-d destdir] [-N] [-p pkgsrc] [-s srcdir]"
23usage="$usage [new_version [old_version]]"
24while getopts d:Nnp:s: opt; do
25  case "$opt" in
26  d)
27    srvd=$OPTARG
28    ;;
29  N)
30    init_dest=true
31    ;;
32  n)
33    maybe=echo
34    ;;
35  p)
36    pkgsrc=$OPTARG
37    ;;
38  s)
39    source=$OPTARG
40    ;;
41  \?)
42    echo "$usage" 1>&2
43    exit 1
44    ;;
45  esac
46done
47shift `expr "$OPTIND" - 1`
48
49# The new and old version numbers are optional command line arguments.
50# If the old version is not given, it defaults to the version found
51# in /srvd/.rvdinfo (read-only), unless the new version is given and
52# has a patch number of 0.  If the new version is not given, it defaults
53# to one greater than the old patch number.
54newver=$1
55oldver=$2
56new_patch=
57if [ -n "$newver" ]; then
58  eval `echo $newver | nawk -F. '{ printf("major=%d; minor=%d; new_patch=%d\n",
59                                          $1, $2, $3); }'`
60  if [ "$new_patch" = 0 -a -n "$oldver" ]; then
61    echo "Patch level 0 cannot have an old version" 1>&2
62    echo "$usage" 1>&2
63    exit 1
64  fi
65fi
66if  [ -z "$oldver" -a "$new_patch" != 0 ]; then
67  oldver=`awk '{ ver = $5; } END { print ver; }' "$srvd_ro/.rvdinfo"`
68  if [ -z "$oldver" ]; then
69    echo "Cannot get old version from $srvd_ro/.rvdinfo" 1>&2
70    echo "$usage" 1>&2
71    exit 1
72  fi
73fi
74if [ -z "$newver" ]; then
75  newver=`echo $oldver | awk -F. '{ print $1 "." $2 "." ($3 + 1); }'`
76fi
77
78echo "The new version is $newver."
79if [ -n "$oldver" ]; then
80  echo "The old version is $oldver."
81fi
82
83: ${pkgsrc:="/build/PKG/$newver"}
84
85if [ ! -d "$pkgsrc" ]; then
86  echo "$pkgsrc is not a valid directory" 1>&2
87  exit 1
88fi
89
90if [ -n "$oldver" -a "$init_dest" = true -a ! -d "$srvd/pkg/$oldver" ]; then
91  echo "$srvd/pkg/$oldver is not a valid directory" 1>&2
92  exit 1
93fi
94
95pkgdest="$srvd/pkg/$newver"
96pkg_order="$source/packs/update/os/solaris/pkg-order.pl"
97pkg_prune="$source/packs/update/os/solaris/pkg-prune.sh"
98
99# Create a pkgadd admin file for installing packages non-interactively.
100admin=/tmp/admin$$
101rm -rf "$admin"
102cat > "$admin" << 'EOF'
103mail=
104instance=overwrite
105partial=nocheck
106runlevel=nocheck
107idepend=nocheck
108rdepend=nocheck
109space=nocheck
110setuid=nocheck
111conflict=nocheck
112action=nocheck
113basedir=default
114EOF
115
116# Get the packages in the package source directory, in install order.
117pkgs=`perl $pkg_order -d "$pkgsrc"`
118if [ -z "$pkgs" ]; then
119  echo "There are no packages in $pkgsrc" 1>&2
120  exit 1
121fi
122
123# pkgadd will create $srvd/var if necessary, but does not chown it,
124# causing complaints on packages with /var in the pkgmap.  Make sure
125# it is owned by root.
126$maybe mkdir -p "$srvd/var" || exit 1
127$maybe chown root "$srvd/var" || exit 1
128
129if [ "$init_dest" = true ]; then
130  $maybe rm -rf "$pkgdest"
131elif [ ! -d "$pkgdest" ]; then
132  # If the srvd package directory does not yet exist, we want to create
133  # symlinks back to the packages in the old version.
134  init_dest=true
135fi
136$maybe mkdir -p "$pkgdest" || exit 1
137
138# Set up /bin and /usr/vice symlinks if necessary.
139if [ ! -h "$srvd/bin" ]; then
140  $maybe ln -s ./usr/bin "$srvd/bin"
141fi
142if [ ! -h "$srvd/usr/vice" ]; then
143  $maybe mkdir -p "$srvd/usr"
144  $maybe chown root "$srvd/usr"
145  $maybe ln -s ../var/usr/vice "$srvd/usr/vice"
146fi
147
148# For each package in the list, install it in the srvd root, and copy
149# it into the srvd pkg directory for the new version.
150for pkg in $pkgs ; do
151  if [ ! -f "$pkgsrc/$pkg/pkginfo" ]; then
152    echo "$pkg is not a valid package in $pkgsrc" 1>&2
153  elif pkginfo -q -c MITdontinstall -d "$pkgsrc" "$pkg" ; then
154    echo "Skipping uninstallable package $pkg"
155  elif [ "$init_dest" = false ] &&
156      cmp -s "$pkgsrc/$pkg/pkginfo" "$pkgdest/$pkg/pkginfo" ; then
157    echo "Skipping $pkg (already installed)"
158  else
159    echo "$pkg"
160
161    # Create OS directories ahead of time to avoid pkgadd complaints
162    # about them being owned by an unknown (AFS) uid.
163    pkgmap="$pkgsrc/$pkg/pkgmap"
164    for dir in `awk '{ if ($2 == "d" && $6 == "?") print $4; }' $pkgmap` ; do
165      if [ ! -d "$srvd/$dir" ]; then
166        $maybe mkdir -p "$srvd/$dir"
167        $maybe chown root "$srvd/$dir"
168      fi
169    done
170
171    # Note whether this is an update of an existing package.
172    if pkginfo -q -R "$srvd" ; then
173      update=true
174    else
175      update=false
176    fi
177
178    # Install the package.
179    $maybe pkgadd -R "$srvd" -a "$admin" -n -d "$pkgsrc" "$pkg"
180    status=$?
181    case $status in
182    1|3|5)
183      echo "pkgadd failed for $pkg (status $status)" 1>&2
184      exit 1
185      ;;
186    esac
187
188    # If we updated an existing version of the package, remove any old
189    # files that are not present in the new version.
190    if [ $update = true ]; then
191      $maybe sh $pkg_prune -R "$srvd" -d "$pkgsrc" "$pkg"
192    fi
193
194    # Nuke any previous version of the package in the srvd pkg directory.
195    # pkgtrans has an overwrite option, but it does not work well with
196    # symlinks.
197    $maybe rm -rf "$pkgdest/$pkg"
198    $maybe pkgtrans "$pkgsrc" "$pkgdest" "$pkg" || exit 1
199  fi
200done
201
202# Make links back to the packages in the old (current) release which
203# are not being replaced in the new version.
204if [ -n "$oldver" -a "$init_dest" = true ]; then
205  echo "Making links to existing packages ..."
206  $maybe perl $source/packs/build/sunpkg/link-pkgs.pl -d "$srvd/pkg" \
207    "$newver" "$oldver" || exit 1
208fi
209
210# Create the .order-version, stats, and .rvdinfo files.
211if [ -z "$maybe" ]; then
212  tmporder=/tmp/order$$
213  rm -rf $tmporder
214  perl "$pkg_order" -v -d "$pkgdest" > $tmporder
215  # Strip out uninstallable and srvd-only packages.
216  for pkg in `pkginfo -c MITdontinstall,MITsrvd -d "$pkgdest" | \
217    awk '{ print $2; }'`
218  do
219    grep -v "^$pkg " $tmporder > $tmporder.new
220    mv $tmporder.new $tmporder
221  done
222  cp $tmporder "$pkgdest/.order-version"
223  rm -f $tmporder
224
225  # Generate a new stats file.
226  echo "Generating the stats file ..."
227  rm -f "$pkgdest/.stats"
228  pkgs=`awk '{ print $1; }' "$pkgdest/.order-version"`
229  perl $source/packs/build/sunpkg/gen-stats.pl -d "$pkgdest" $pkgs \
230    > "$pkgdest/.stats" || exit 1
231
232  # Create .rvdinfo.
233  rm -f "$srvd/.rvdinfo"
234  echo "Athena RVD (sun4) Version $newver `date`" > "$srvd/.rvdinfo"
235  chmod 444 "$srvd/.rvdinfo"
236fi
237
238rm -f "$admin"
Note: See TracBrowser for help on using the repository browser.