This repository has been archived by the owner on Dec 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdoPkgUp.sh
260 lines (223 loc) · 8.69 KB
/
doPkgUp.sh
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
#!/bin/sh
# Don't change these, get set dynamically at upgrade time by pc-updatemanager
PKG_FLAG="%%PKG_FLAG%%"
REALPKGDLCACHE="%%REALPKGDLCACHE%%"
PKGFILENAME="%%PKGFILENAME%%"
SYSBASEFILENAME="%%SYSBASEFILENAME%%"
SYSBASEORIGIN="%%SYSBASEORIGIN%%"
# Files to overwrite in /etc with upgrades
ETC_DISTUPGRADE="./etc/rc ./etc/rc.shutdown ./etc/rc.devd ./etc/devd.conf ./etc/defaults/rc.conf ./etc/auto_master /etc/autofs"
# Default OpenRC Services to enable
OPENRC_BOOT_SERV="abi adjkerntz bootmisc cron devd dumpon fsck hostid hostname localmount loopback modules motd network newsyslog nisdomain"
OPENRC_BOOT_SERV="${OPENRC_BOOT_SERV} root routing savecore staticroute swap syscons sysctl syslogd urandom zfs zvol "
OPENRC_DEFAULT_SERV="local netmount"
OPENRC_SHUTDOWN_SERV="savecache"
OPENRC_NONET_SERV="local"
export OPENRC_BOOT_SERV OPENRC_DEFAULT_SERV OPENRC_SHUTDOWN_SERV OPENRC_NONET_SERV
update_bootloader()
{
local ROOTPOOL=`mount | grep 'on / ' | cut -d '/' -f 1`
if [ -z "$ROOTPOOL" ] ; then return ; fi
# Thow the new boot-loader on each disk
for disk in $(sysctl -n kern.disks); do
# Why CD's show up in kern.disks? Dunno...
echo $disk | grep -q "^cd[0-9]"
if [ $? -eq 0 ] ; then continue ; fi
# Check if the disk has a gptid on the second "p2" partition
gptid=$(gpart list $disk | grep rawuuid | sed -n 2p | awk '{print $2}')
# If we didn't find a gptid for this disk / partition, set to a bogus name so we dont match
if [ -z "$gptid" ] ; then gptid="bogusdisknamenotused" ; fi
# Does this disk exist in freenas-boot?
zpool status ${ROOTPOOL} | grep -q -e " ${disk}p" -e " gptid/$gptid "
if [ $? -ne 0 ] ; then continue ; fi
if gpart show ${disk} | grep -q freebsd-boot; then
echo "Updating to latest GPT/BIOS bootloader..."
part=$(gpart show ${disk} | grep " freebsd-boot " | awk '{print $3}')
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i ${part} /dev/${disk}
elif gpart show ${disk} | grep -q " efi "; then
if [ ! -d "/boot/efi" ] ; then
mkdir -p /boot/efi
fi
part=$(gpart show ${disk} | grep " efi " | awk '{print $3}')
if mount -t msdosfs /dev/${disk}p${part} /boot/efi; then
echo "Updating to latest EFI bootloader..."
# If they are using rEFInd and we have a bootx64-trueos.efi
if [ -e "/boot/efi/efi/boot/bootx64-trueos.efi" ] ; then
cp /boot/boot1.efi /boot/efi/efi/boot/bootx64-trueos.efi
else
cp /boot/boot1.efi /boot/efi/efi/boot/bootx64.efi
fi
umount -f /boot/efi
fi
fi
done
}
## Try to get error status of first command in pipeline ##
run_cmd_wtee()
{
((((${1} 2>&1 ; echo $? >&3 ) | tee -a ${2} >&4 ) 3>&1) | (read xs; exit $xs)) 4>&1
return $?
}
# Copy over the trueos pkg fingerprints
rm -rf /etc/pkg/trueos-fingerprints.previous 2>/dev/null
mv /etc/pkg/trueos-fingerprints /etc/pkg/trueos-fingerprints.previous 2>/dev/null
cp -r /usr/local/etc/pkg/fingerprints/trueos /etc/pkg/trueos-fingerprints
# Set the cache directory
PKG_CFLAG="-C /var/db/pc-updatemanager/.pkgUpdate.conf"
echo "PKG_CACHEDIR: $REALPKGDLCACHE" > /var/db/pc-updatemanager/.pkgUpdate.conf
echo "PKG_DBDIR: /var/db/pc-updatemanager/pkgdb" >> /var/db/pc-updatemanager/.pkgUpdate.conf
# Cleanup the old pkgs
echo "Removing old packages... Please wait..."
pkg-static ${PKG_CFLAG} ${PKG_FLAG} unlock -ay
# Bad PKG, bad!
pkg-static ${PKG_CFLAG} ${PKG_FLAG} delete -y javavmwrapper-2.5_1 2>/dev/null >/dev/null
pkg-static ${PKG_CFLAG} ${PKG_FLAG} delete -y javavmwrapper-2.5_2 2>/dev/null >/dev/null
# Since we cant remove pkgs via repository, this will have to do
pkg-static query -e '%n !~ FreeBSD-*' %o | grep -v 'ports-mgmt/pkg' | xargs pkg-static ${PKG_CFLAG} ${PKG_FLAG} delete -fy
if [ $? -ne 0 ] ; then
echo "WARNING: Failed removing old packages..."
fi
tar xvpf ${REALPKGDLCACHE}/${PKGFILENAME} -C / /usr/local/sbin/pkg-static >/dev/null 2>/dev/null
sleep 2
# Copy back the saved fingerprints
mkdir -p /usr/local/etc/pkg/fingerprints >/dev/null 2>/dev/null
cp -r /etc/pkg/trueos-fingerprints /usr/local/etc/pkg/fingerprints/trueos
echo "Installing pkg from local cache..."
echo "/usr/local/sbin/pkg-static ${PKG_CFLAG} ${PKG_FLAG} install -U -y -f ports-mgmt/pkg"
/usr/local/sbin/pkg-static ${PKG_CFLAG} ${PKG_FLAG} install -U -y -f ports-mgmt/pkg
if [ $? -ne 0 ] ; then
# If we fail to install pkgng, try updating first
echo "Installing pkg from file..."
echo "/usr/local/sbin/pkg-static ${PKG_CFLAG} ${PKG_FLAG} add -f ${REALPKGDLCACHE}/${PKGFILENAME}"
/usr/local/sbin/pkg-static ${PKG_CFLAG} ${PKG_FLAG} add -f ${REALPKGDLCACHE}/${PKGFILENAME}
if [ $? -ne 0 ] ; then
echo "FAILED INSTALLING ports-mgmt/pkg"
exit 1
fi
fi
cd ${REALPKGDLCACHE}
# And now we re-install pkg without -U flag
# Sucks that we have to do this, but -U won't allow upgrading local
# on-disk database schema also
#pkg \${PKG_CFLAG} ${PKG_FLAG} install -f -y ports-mgmt/pkg
# Need to export this before installing pkgs, some scripts may try to be interactive
PACKAGE_BUILDING="YES"
export PACKAGE_BUILDING
# Cleanup the old /compat/linux for left-overs
umount /compat/linux/proc >/dev/null 2>/dev/null
umount /compat/linux/sys >/dev/null 2>/dev/null
rm -rf /compat/linux
mkdir -p /compat/linux/proc
mkdir -p /compat/linux/sys
mkdir -p /compat/linux/usr
mkdir -p /compat/linux/dev
mkdir -p /compat/linux/run
ln -s /usr/home /compat/linux/usr/home
# Make sure the various openrc dirs exist
mkdir -p /etc/runlevels 2>/dev/null
mkdir -p /etc/runlevels/boot 2>/dev/null
mkdir -p /etc/runlevels/default 2>/dev/null
mkdir -p /etc/runlevels/nonetwork 2>/dev/null
mkdir -p /etc/runlevels/shutdown 2>/dev/null
mkdir -p /etc/runlevels/sysinit 2>/dev/null
mkdir -p /libexec/rc/init.d 2>/dev/null
while read pkgLine
do
pkgOrigin="`echo $pkgLine | cut -d ' ' -f 1`"
pkgName="`echo $pkgLine | cut -d ' ' -f 2`"
if [ ! -e "${pkgName}" ] ; then
echo "No such package: ${pkgName}"
echo "No such package: ${pkgName}" >>/removed-pkg-list
continue
fi
echo "Installing $pkgOrigin... ${pkgName}"
run_cmd_wtee "pkg-static ${PKG_CFLAG} ${PKG_FLAG} add -f ${pkgName}" "/pkg-add.log"
if [ $? -ne 0 ] ; then
echo "Failed installing ${pkgOrigin}"
cat /pkg-add.log
echo "Failed installing ${pkgOrigin}" >>/failed-pkg-list
cat /pkg-add.log >>/failed-pkg-list
fi
done < /install-pkg-list
rm /pkg-add.log
echo "Installing $SYSBASEORIGIN... $SYSBASEFILENAME"
run_cmd_wtee "pkg-static ${PKG_CFLAG} ${PKG_FLAG} add -f $SYSBASEFILENAME" "/pkg-add.log"
if [ $? -ne 0 ] ; then
echo "FAILED INSTALL: ${SYSBASEORIGIN}"
sleep 10
exit 1
fi
# Verify the base package was installed
echo "pkg-static info -q ${SYSBASEORIGIN}"
pkg-static info -q ${SYSBASEORIGIN}
if [ $? -ne 0 ] ; then
echo "FAILED INFO: ${SYSBASEORIGIN}"
sleep 10
exit 1
fi
# Lock the TrueOS base package
pkg-static ${PKG_CFLAG} ${PKG_FLAG} lock -y ${SYSBASEORIGIN}
if [ $? -ne 0 ] ; then
echo "FAILED LOCK: ${SYSBASEORIGIN}"
sleep 10
exit 1
fi
# Update kernel hints
kldxref /boot/kernel /boot/modules
if [ -e "/etc/init.d" ] ; then
# Update some of the etc files from make distribution
echo "Extracting distribution files..."
tar xvpf ${REALPKGDLCACHE}/fbsd-distrib.txz -C / ${ETC_DISTUPGRADE}
if [ $? -ne 0 ] ; then
echo "Warning: Failed extracting distribution upgrade files"
fi
# Enable OpenRC Services
for serv in ${OPENRC_BOOT_SERV}
do
rc-update add $serv boot
done
for serv in ${OPENRC_DEFAULT_SERV}
do
rc-update add $serv default
done
for serv in ${OPENRC_SHUTDOWN_SERV}
do
rc-update add $serv shutdown
done
for serv in ${OPENRC_NONET_SERV}
do
rc-update add $serv nonetwork
done
# Determine if we need to do first-time rc -> openrc migration
if [ ! -e /var/migrate-rc-openrc ] ; then
echo "Running OpenRC Migration..."
/usr/local/bin/migrate_rc_openrc
touch /var/migrate_rc_openrc
fi
fi
echo "Moving updated pkg repo..."
rm -rf /var/db/pkg.preUpgrade 2>/dev/null
mv /var/db/pkg /var/db/pkg.preUpgrade
mv /var/db/pc-updatemanager/pkgdb /var/db/pkg
# Save the log files
if [ ! -d "/usr/local/log/pc-updatemanager" ] ; then
mkdir -p /usr/local/log/pc-updatemanager
fi
touch /install-pkg-list
touch /previous-pkg-list
touch /removed-pkg-list
touch /failed-pkg-list
mv /install-pkg-list /usr/local/log/pc-updatemanager/
mv /previous-pkg-list /usr/local/log/pc-updatemanager/
mv /removed-pkg-list /usr/local/log/pc-updatemanager/
mv /failed-pkg-list /usr/local/log/pc-updatemanager/
pkg-static info > /usr/local/log/pc-updatemanager/current-pkg-list
# Update the boot-loader to latest
update_bootloader
echo "Updating pkgng config..."
if [ -e "/var/db/trueos-pkg-ipfs-next" ] ; then
mv /var/db/trueos-pkg-ipfs-next /var/db/trueos-pkg-ipfs
fi
/usr/local/bin/pc-updatemanager syncconf
if [ $? -ne 0 ] ; then exit 1; fi
exit 0