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
153 lines (127 loc) · 4.72 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
#!/bin/sh
# Don't change these, get set dynamically at upgrade time by trueos-update
PKG_FLAG="%%PKG_FLAG%%"
REALPKGDLCACHE="%%REALPKGDLCACHE%%"
PKGFILENAME="%%PKGFILENAME%%"
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 $?
}
# Set the cache directory
PKG_CFLAG="-C /var/db/trueos-update/.pkgUpdate.conf"
echo "PKG_CACHEDIR: $REALPKGDLCACHE" > /var/db/trueos-update/.pkgUpdate.conf
echo "PKG_DBDIR: /var/db/trueos-update/pkgdb" >> /var/db/trueos-update/.pkgUpdate.conf
# 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
cd ${REALPKGDLCACHE}
find . -type file -print | sort > /tmp/.pkgUpList
while read pkgfile
do
if [ -e '/pkg-add.log' ]; then rm /pkg-add.log; fi
# Get the pkg origin
unset ORIGIN
ORIGIN=$(pkg-static ${PKG_CFLAG} ${PKG_FLAG} info -o -F ${pkgfile} | awk '{print $2}')
# If this is empty
if [ -z "$ORIGIN" ] ; then
echo "Empty ORIGIN for $pkgfile!"
continue
fi
# Skip base packages
if [ "$ORIGIN" = "base" ] ; then continue ; fi
# Is the package already installed?
pkg-static ${PKG_CFLAG} ${PKG_FLAG} info -e ${ORIGIN}
if [ $? -eq 0 ] ; then
echo "Skipping already installed: $ORIGIN"
continue
fi
# Install the package
echo "Installing $pkgfile..."
run_cmd_wtee "pkg-static ${PKG_CFLAG} ${PKG_FLAG} add ${pkgfile}" "/pkg-add.log"
if [ $? -ne 0 ] ; then
echo "Failed installing ${pkgfile}"
cat /pkg-add.log
echo "Failed installing ${pkgfile}" >>/failed-pkg-list
cat /pkg-add.log >>/failed-pkg-list
fi
done < /tmp/.pkgUpList
rm /tmp/.pkgUpList
if [ -e '/pkg-add.log' ]; then rm /pkg-add.log; fi
# Update kernel hints
kldxref /boot/kernel /boot/modules
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/trueos-update/pkgdb /var/db/pkg
# Clean the pkg cache
rm -rf /var/cache/trueos-update
# Save the log files
if [ ! -d "/var/trueos-update" ] ; then
mkdir -p /var/trueos-update
fi
touch /failed-pkg-list
mv /failed-pkg-list /var/trueos-update/
pkg-static info > /var/trueos-update/current-pkg-list
# Build top-level list of pkgs installed
pkg-static query -e '%a = 0' '%o' | grep -v '^base$' | sort > /var/trueos-update/current-user-pkgs
# Update the boot-loader to latest
update_bootloader
exit 0