Menu

[r8607]: / trunk / build / create_servicepack.sh  Maximize  Restore  History

Download this file

162 lines (119 with data), 4.6 kB

  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
#!/bin/sh
#-
# Copyright (c) 2011 iXsystems, Inc., All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# Intended for use internally only to make 'service pack' style images.
#
MD1=
MD2=
PREFIX=
cleanup() {
trap - EXIT
for md in $MD1 $MD2; do
umount /dev/$md
mdconfig -d -u $md
done || :
rm -Rf $PREFIX
}
FREENAS_ROOT="$(realpath "$(dirname "$0")/..")"
. "$FREENAS_ROOT/build/nano_env"
. "$FREENAS_ROOT/build/functions.sh"
requires_root
if [ $# != 2 ]; then
cat <<EOF
usage: ${0##*/} release-image new-image
both images needs to be raw and not compressed with xz
EOF
exit 1
fi
RELEASE_IMAGE=$1
NEW_IMAGE=$2
set -e
echo -n "Creating temporary working directory... "
PREFIX=$(mktemp -d servicepack.XXXXXX)
trap cleanup EXIT
echo "Done!"
echo -n "Creating vnode-based mds... "
# Original image
MD1=`mdconfig -a -t vnode -f "$RELEASE_IMAGE"`
# Latest image
MD2=`mdconfig -a -t vnode -f "$NEW_IMAGE"`
echo "Done!"
echo -n "Mounting mds... "
# Trees to mount
rm -rf ${PREFIX}/release ${PREFIX}/patched ${PREFIX}/servicepack
mkdir -p ${PREFIX}/release ${PREFIX}/patched ${PREFIX}/servicepack
# Mount images at mountpoints
mount -o ro /dev/${MD1}s1a ${PREFIX}/release
mount -o ro /dev/${MD2}s1a ${PREFIX}/patched
echo "Done!"
echo -n "Computing SHA256 checksums... "
# Generate sha256 checksums
for dir in release patched; do
cd ${PREFIX}/$dir
find . | sort > ${PREFIX}/$dir.files
find . -type f | sort | xargs sha256 > ${PREFIX}/$dir.sha256
done
comm -23 ${PREFIX}/release.files ${PREFIX}/patched.files > ${PREFIX}/removed.list
comm -13 ${PREFIX}/release.sha256 ${PREFIX}/patched.sha256 | cut -c9- | rev | cut -c69- | rev > ${PREFIX}/changed.list.tmp
grep ^\./conf/base/ ${PREFIX}/changed.list.tmp | cut -c12- | sed -e s/^/./ > ${PREFIX}/changed.list.exclude
comm -23 ${PREFIX}/changed.list.tmp ${PREFIX}/changed.list.exclude > ${PREFIX}/changed.list
rm -f ${PREFIX}/changed.list.tmp ${PREFIX}/changed.list.exclude
echo "Done!"
echo -n "Copying changed files... "
tar cf - -T ${PREFIX}/changed.list | tar xf - -C ${PREFIX}/servicepack
echo "Done!"
echo -n "Generating post-install files... "
mkdir -p ${PREFIX}/servicepack/etc/servicepack
VERSION_FILE=$(find ${PREFIX}/release/etc -name 'version*')
cp $VERSION_FILE ${PREFIX}/servicepack/etc/servicepack/version.expected
POSTINSTALL=${PREFIX}/servicepack/etc/servicepack/post-install
echo '#!/bin/sh' > ${POSTINSTALL}
echo 'mount -uw /' >> ${POSTINSTALL}
echo 'rm -f /etc/servicepack/version.expected' >> ${POSTINSTALL}
sed -e 's/^/rm -rf /' ${PREFIX}/removed.list >> ${POSTINSTALL}
echo '# All changes to firmware volume must be done before this line'
echo 'mount -ur /' >> ${POSTINSTALL}
chmod +x ${POSTINSTALL}
echo "Done!"
echo "Packing the service pack... "
rm -f ${PREFIX}/servicepack.tar.xz
cd ${PREFIX}
tar cf servicepack.tar -C ${PREFIX}/servicepack .
xz -9ve servicepack.tar
echo -n "Unmounting and destroying md devices... "
umount -f ${PREFIX}/release
mdconfig -d -u $MD1
umount -f ${PREFIX}/patched
mdconfig -d -u $MD2
mv "$NEW_IMAGE_TMP" "$NEW_IMAGE"
echo "Done!"
cat <<EOF
All done! If you want to make any changes to the service pack as a
post-install action, change ${POSTINSTALL} then execute:
rm -f ${PREFIX}/servicepack.tar.xz
cd ${PREFIX}
tar --options xz:compression-level=9 -cJpf - -C ${PREFIX}/servicepack.xz .
To re-roll the service pack.
EOF
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.