/
upgrade
executable file
·341 lines (319 loc) · 9.79 KB
/
upgrade
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/bin/ksh
#
# upgrade to a new version of Tribblix
#
# the current upgrade is from m18 (or earlier) to m19
# which crosses the loader boundary - grub is kept by default,
# but m20 will be new-loader only
#
ZAPLIBDIR="/usr/lib/zap"
CFGDIR="/etc/zap"
BEADM="/sbin/beadm"
ZFSCMD="/usr/sbin/zfs"
DOIT=""
ACTIVATE="false"
#
# The general strategy here is:
# beadm create newver
# beadm mount newver /a
# update zap on the new be
# (in the new context) zap update-overlay -a
# beadm activate newver
# init 6
#
#
# The package TRIBzap-upgrade supplies the files
# /etc/zap/version.list
# /etc/zap/version.current
#
VLISTFILE="${CFGDIR}/version.list"
VINSTFILE="${CFGDIR}/version.current"
if [ ! -f "${VLISTFILE}" ]; then
echo "ERROR: upgrade capability not present"
exit 1
fi
if [ ! -f "${VINSTFILE}" ]; then
echo "ERROR: upgrade capability not present"
exit 1
fi
if [ ! -f "${BEADM}" ]; then
echo "ERROR: upgrade capability not present, beadm missing"
exit 1
fi
show_available() {
INSTVER=`cat $VINSTFILE`
/usr/bin/awk -F'|' '{print $1,$2,$3}' $VLISTFILE | while read nver nurl ntext
do
if [ "X$nver" = "X$INSTVER" ]; then
echo "${nver}: (current)"
else
echo "${nver}: $ntext"
fi
done
}
validate() {
INSTVER=`cat $VINSTFILE`
/usr/bin/awk -F'|' '{print $1,$2}' $VLISTFILE | while read nver nurl
do
if [ "X$1" = "X$INSTVER" ]; then
echo "ERROR: $1 is the current version"
exit 1
elif [ "X$nver" = "X$1" ]; then
echo "$nurl"
return
fi
done
echo "ERROR: unrecognized version $1"
exit 1
}
bail() {
echo $1
exit 1
}
case $# in
0)
echo "Usage: zap upgrade [-n] [-B] new_version | list | current"
exit 1
;;
esac
case $1 in
'list')
show_available
exit 0
;;
'current')
cat $VINSTFILE
exit 0
;;
esac
while getopts "nB" opt; do
case $opt in
n)
DOIT="echo"
;;
B)
ACTIVATE="true"
;;
esac
done
shift $((OPTIND - 1))
#
# Beyond here is an upgrade, either real or dry-run
#
echo $*
NEWVER="$1"
#
# validate the requested version, and get the corresponding URL
#
NEWURL=$(validate $NEWVER) || bail "$NEWURL"
#
# find the current BE and matching FS dataset
#
OLDBE=`$BEADM list -H | awk -F\; '{if ($3=="NR") print $1}'`
OLDDS=`$BEADM list -Ha | awk -F\; '{if ($3=="NR") print $2}'`
if [ -z "$OLDBE" ]; then
echo "ERROR: Unable to find current BE name"
exit 1
fi
#
# find a BE name that is unused
#
BENAME="$NEWVER"
$BEADM list $BENAME > /dev/null 2>&1
BESTATUS=$?
BENUM=0
while [ $BESTATUS -eq 0 ]
do
BENUM=$(($BENUM+1))
BENAME="${NEWVER}-${BENUM}"
$BEADM list $BENAME > /dev/null 2>&1
BESTATUS=$?
done
WCLIENT=/usr/bin/curl
WARGS="-f -s -o"
if [ ! -x $WCLIENT ]; then
WCLIENT=/usr/bin/wget
WARGS="-q -O"
fi
NPKG=${NEWURL##*/}
CACHE_DIR=`${ZAPLIBDIR}/zap-cfg cache-dir`
$DOIT ${WCLIENT} ${WARGS} ${CACHE_DIR}/${NPKG} $NEWURL
$DOIT $BEADM create $BENAME
ALTROOT="/a"
BENUM=0
while [ -d $ALTROOT ]
do
BENUM=$(($BENUM+1))
ALTROOT="/a.${BENUM}"
done
#
# and the ZFS dataset it corresponds to
# -a could return multiple lines, one with a dataset and possibly
# multiple snapshots; match the dataset by looking for a /
#
NEWDS=`$BEADM list -Ha $BENAME | awk -F\; '{if ($2~/\//) print $2}'`
echo New BE will be called $BENAME
echo Backed by dataset $NEWDS
echo And will be driven from $NEWURL
#
# update zap in the new BE
#
$DOIT mkdir $ALTROOT
$DOIT $BEADM mount $BENAME $ALTROOT
$DOIT zap uninstall -R $ALTROOT TRIBzap
$DOIT ${ZAPLIBDIR}/instzap -R $ALTROOT ${CACHE_DIR}/${NPKG} TRIBzap
#
# must refresh the overlays and catalog, as contents and dependencies
# may have changed
#
$DOIT /usr/bin/zap -C ${ALTROOT} refresh-overlays
#
# first we must update SUNWcsd
#
$DOIT /usr/bin/zap -C ${ALTROOT} update SUNWcsd
#
# replace the critical state files from the running system
# the assumption here is that SUNWcsd installs blank files
#
$DOIT /usr/bin/cp -p /etc/devlink.tab ${ALTROOT}/etc/devlink.tab
$DOIT /usr/bin/cp -p /etc/driver_classes ${ALTROOT}/etc/driver_classes
$DOIT /usr/bin/cp -p /etc/driver_aliases ${ALTROOT}/etc/driver_aliases
$DOIT /usr/bin/cp -p /etc/iu.ap ${ALTROOT}/etc/iu.ap
$DOIT /usr/bin/cp -p /etc/minor_perm ${ALTROOT}/etc/minor_perm
$DOIT /usr/bin/cp -p /etc/name_to_major ${ALTROOT}/etc/name_to_major
$DOIT /usr/bin/cp -p /etc/path_to_inst ${ALTROOT}/etc/path_to_inst
$DOIT /usr/bin/cp -p /etc/security/device_policy ${ALTROOT}/etc/security/device_policy
$DOIT /usr/bin/cp -p /etc/security/extra_privs ${ALTROOT}/etc/security/extra_privs
#
# remove any obsoleted packages
#
if [ -f ${ALTROOT}/usr/share/zap/deprecated.pkgs ]; then
echo "Removing obsoleted packages"
for oldpkg in `cat ${ALTROOT}/usr/share/zap/deprecated.pkgs`
do
$DOIT /usr/bin/zap uninstall -R ${ALTROOT} ${oldpkg}
done
fi
#
# remove any obsoleted overlays
# note this just removes any metadata, any constituent packages
# needing removal must be listed in deprecated.pkgs
#
if [ -f ${ALTROOT}/usr/share/zap/deprecated.ovl ]; then
echo "Removing obsoleted overlays"
for oldovl in `cat ${ALTROOT}/usr/share/zap/deprecated.ovl`
do
$DOIT /usr/bin/rm -f ${ALTROOT}/var/sadm/overlays/${oldovl}.pkgs
$DOIT /usr/bin/rm -f ${ALTROOT}/var/sadm/overlays/${oldovl}.ovl
$DOIT /usr/bin/rm -f ${ALTROOT}/var/sadm/overlays/${oldovl}.pkgs.bak
$DOIT /usr/bin/rm -f ${ALTROOT}/var/sadm/overlays/${oldovl}.ovl.bak
$DOIT /usr/bin/rm -f ${ALTROOT}/var/sadm/overlays/installed/${oldovl}
done
fi
#
# now update the remaining overlays
#
$DOIT /usr/bin/zap -C ${ALTROOT} update-overlay -a
#
# do it again, because the overlay structure might have changed and
# we need to be sure that any newly added overlays get updated too
#
$DOIT /usr/bin/zap -C ${ALTROOT} update-overlay -a
#
# this is a manual hack for m19 and the new loader
# we need to be absolutely sure that the loader and
# agpgart packages get installed
#
$DOIT /usr/bin/zap -C ${ALTROOT} install TRIBsys-boot-loader
$DOIT /usr/bin/zap -C ${ALTROOT} install TRIBdrv-graphics-agpgart
#
# FIXME and any isolated packages?
#
# shut down pkgserv otherwise the BE cannot be unmounted
#
$DOIT /usr/bin/pkgadm sync -R ${ALTROOT} -q
#
# refresh common administratively modified files
#
$DOIT /usr/bin/cp -p /etc/passwd ${ALTROOT}/etc/passwd
$DOIT /usr/bin/cp -p /etc/shadow ${ALTROOT}/etc/shadow
$DOIT /usr/bin/cp -p /etc/group ${ALTROOT}/etc/group
$DOIT /usr/bin/cp -p /etc/logadm.conf ${ALTROOT}/etc/logadm.conf
$DOIT /usr/bin/cp -p /etc/dumpadm.conf ${ALTROOT}/etc/dumpadm.conf
$DOIT /usr/bin/cp -p /etc/coreadm.conf ${ALTROOT}/etc/coreadm.conf
$DOIT /usr/bin/cp -p /etc/syslog.conf ${ALTROOT}/etc/syslog.conf
$DOIT /usr/bin/cp -p /etc/nsswitch.conf ${ALTROOT}/etc/nsswitch.conf
$DOIT /usr/bin/cp -p /etc/user_attr ${ALTROOT}/etc/user_attr
$DOIT /usr/bin/cp -p /etc/resolv.conf ${ALTROOT}/etc/resolv.conf
$DOIT /usr/bin/cp -p /etc/inet/hosts ${ALTROOT}/etc/inet/hosts
$DOIT /usr/bin/cp -p /etc/inet/netmasks ${ALTROOT}/etc/inet/netmasks
$DOIT /usr/bin/cp -p /etc/inet/networks ${ALTROOT}/etc/inet/networks
$DOIT /usr/bin/cp -p /etc/inet/protocols ${ALTROOT}/etc/inet/protocols
$DOIT /usr/bin/cp -p /etc/inet/services ${ALTROOT}/etc/inet/services
$DOIT /usr/bin/cp -p /etc/inet/inetd.conf ${ALTROOT}/etc/inet/inetd.conf
$DOIT /usr/bin/cp -p /etc/inet/ipsecalgs ${ALTROOT}/etc/inet/ipsecalgs
$DOIT /usr/bin/cp -p /etc/inet/ipaddrsel.conf ${ALTROOT}/etc/inet/ipaddrsel.conf
$DOIT /usr/bin/cp -p /etc/inet/secret/ike.preshared ${ALTROOT}/etc/inet/secret/ike.preshared
$DOIT /usr/bin/cp -p /etc/zones/index ${ALTROOT}/etc/zones/index.pre-upgrade
$DOIT /usr/bin/cp -p /etc/default/init ${ALTROOT}/etc/default/init
$DOIT /usr/bin/cp -p /etc/ipadm/ipadm.conf ${ALTROOT}/etc/ipadm/ipadm.conf
$DOIT /usr/bin/cp -p /etc/dladm/* ${ALTROOT}/etc/dladm
grep /swap /etc/vfstab >> ${ALTROOT}/etc/vfstab
#
# FIXME: these 2 often get mangled, need fixing properly
#
$DOIT /usr/bin/cp -p /etc/minor_perm ${ALTROOT}/etc/minor_perm
$DOIT /usr/bin/cp -p /etc/name_to_major ${ALTROOT}/etc/name_to_major
#
# if there is a zonelib hierarchy for sparse root zones, it needs
# to be cleaned out (at this point zones aren't supported but at
# least cleaning out zonelib will ensure that any newly created
# zones will work)
#
if [ -d ${ALTROOT}/zonelib/lib/svc ]; then
$DOIT /usr/bin/rm -fr ${ALTROOT}/zonelib/lib
$DOIT /usr/bin/mkdir -p ${ALTROOT}/zonelib/lib
fi
#
# FIXME - bootloader switch
#
# Originally, the upgrade script forced grub as the bootloader on
# upgrade. This is clearly wrong now that new installs start with the
# new loader, as we would then force a switch to the old grub.
# Therefore, we no longer force anything. However, that still leaves
# systems that were installed with loader but then had grub forced
# on upgrade, which will then be switched at the *next* upgrade.
# We need to check for that and undo the grub selection in that case.
#
#
# need to update the boot archive
#
$DOIT /usr/sbin/bootadm update-archive -R $ALTROOT
$DOIT $BEADM unmount $BENAME
$DOIT rmdir $ALTROOT
#
# activation is optional
# observation indicates that beadm might leave the old dataset mountable
# on /, which the system tries to do at boot, which fails then causing the
# whole boot to fail, so override that just in case it's wrong. The correct
# setting for canmount is 'noauto' but some older Tribblix installs didn't
# set it that way
#
echo "Upgrade complete"
$DOIT $ZFSCMD set canmount=noauto $OLDDS
$DOIT $ZFSCMD set canmount=noauto $NEWDS
$DOIT $ZFSCMD set mountpoint=/ $OLDDS
$DOIT $ZFSCMD set mountpoint=/ $NEWDS
if [ "X${ACTIVATE}" = "Xtrue" ]; then
echo "Activating new BE"
$DOIT $BEADM activate $BENAME
$DOIT init 6
else
echo ""
echo "====================================================="
echo "|| To switch to the newly upgraded version, issue ||"
echo "|| the following commands: ||"
printf "|| beadm activate %-31s||\n" $BENAME
echo "|| init 6 ||"
echo "====================================================="
fi