install vim-core explicitly
[unleashed-kayak.git] / build_image.sh
blobf4fd57bfd63c6a68b3848face539ae6c0f11e1b3
1 #!/bin/bash
4 # This file and its contents are supplied under the terms of the
5 # Common Development and Distribution License ("CDDL"), version 1.0.
6 # You may only use this file in accordance with the terms of version
7 # 1.0 of the CDDL.
9 # A full copy of the text of the CDDL should have accompanied this
10 # source. A copy of the CDDL is also available via the Internet at
11 # http://www.illumos.org/license/CDDL.
15 # Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved.
18 fail() {
19 echo "ERROR: $*"
20 exit 1
23 # NOTE --> The URL needs to be updated with every release.
24 # Change "bloody" to whatever release the current branch is.
25 PUBLISHER=unleashed
26 PKGURL1=${PKGURL1-/usr/nightly/packages/i386/nightly/repo.redist}
27 PKGURL2=${PKGURL2-/ws/oi-userland/i386/repo}
28 : ${GZIP_CMD:=gzip}
29 SRCDIR=$(dirname $0)
30 DIDWORK=0
31 BUILDNUM=${VERSION//r/}
32 if [[ ${SRCDIR:0:1} != "/" ]]; then
33 SRCDIR=`pwd`/$SRCDIR
35 if [[ -z "${1}" ]]; then
36 echo "$0 <zfs pool> [checkpoint]"
37 exit 1
38 else
39 BASE=${1}
40 shift
41 BASEDIR=`zfs get -o value -H mountpoint $BASE`
43 MKFILEDIR=/tmp
44 WORKDIR=$BASEDIR
45 ROOTDIR=$WORKDIR/root
46 if [[ ! -d $ROOTDIR ]]; then
47 zfs create -o compression=off $BASE/root || fail "zfs create failed"
49 SVCCFG_DTD=${ROOTDIR}/usr/share/lib/xml/dtd/service_bundle.dtd.1
50 SVCCFG_REPOSITORY=${ROOTDIR}/etc/svc/repository.db
51 if [[ -f ${PREBUILT_ILLUMOS}/usr/src/cmd/svc/svccfg/svccfg-native ]]; then
52 SVCCFG=${PREBUILT_ILLUMOS}/usr/src/cmd/svc/svccfg/svccfg-native
53 else
54 echo "WARNING -- Not using 'native' svccfg, may hang on build."
55 echo " We recommend a pre-built illumos's svccfg-native."
56 echo " Set PREBUILT_ILLUMOS in your environment to point"
57 echo " to a built illumos-omnios repository."
58 SVCCFG=/usr/sbin/svccfg
60 export WORKDIR ROOTDIR SVCCFG_DTD SVCCFG_REPOSITORY SVCCFG
62 # This was uber-helpful
63 # http://alexeremin.blogspot.com/2008/12/preparing-small-miniroot-with-zfs-and.html
65 PKG=/bin/pkg
67 UNNEEDED_MANIFESTS="application/management/net-snmp.xml
68 application/pkg/pkg-server.xml application/pkg/pkg-mdns.xml
69 system/rmtmpfiles.xml system/mdmonitor.xml
70 system/fm/notify-params.xml system/device/allocate.xml
71 system/device/devices-audio.xml system/auditd.xml
72 system/metasync.xml system/pkgserv.xml system/fcoe_initiator.xml
73 system/metainit.xml system/zonestat.xml
74 system/cron.xml system/rbac.xml system/sac.xml
75 system/auditset.xml system/hotplug.xml
76 system/wusb.xml system/zones.xml
77 system/intrd.xml system/coreadm.xml
78 system/extended-accounting.xml
79 system/scheduler.xml
80 system/logadm-upgrade.xml system/resource-mgmt.xml
81 system/idmap.xml
82 network/ldap/client.xml network/shares/reparsed.xml
83 network/shares/group.xml network/inetd-upgrade.xml
84 network/smb/client.xml network/smb/server.xml
85 network/network-iptun.xml network/ipsec/policy.xml
86 network/ipsec/ipsecalgs.xml network/ipsec/ike.xml
87 network/ipsec/manual-key.xml network/forwarding.xml
88 network/inetd.xml network/npiv_config.xml
89 network/ssl/kssl-proxy.xml network/rpc/metamed.xml
90 network/rpc/mdcomm.xml network/rpc/gss.xml
91 network/rpc/bind.xml network/rpc/keyserv.xml
92 network/rpc/meta.xml network/rpc/metamh.xml
93 network/socket-filter-kssl.xml network/network-netcfg.xml
94 network/nfs/status.xml network/nfs/cbd.xml
95 network/nfs/nlockmgr.xml network/nfs/mapid.xml
96 network/nfs/client.xml network/network-ipqos.xml
97 network/security/ktkt_warn.xml network/security/krb5kdc.xml
98 network/security/kadmin.xml network/network-install.xml
99 network/bridge.xml network/network-initial.xml
100 network/network-ipmgmt.xml network/routing/legacy-routing.xml
101 network/network-service.xml network/network-physical.xml
102 network/network-netmask.xml network/dlmgmt.xml
103 network/network-location.xml network/ibd-post-upgrade.xml
104 network/network-routing-setup.xml network/network-loopback.xml
105 network/dns/client.xml network/dns/install.xml
106 network/dns/multicast.xml platform/i86pc/acpihpd.xml
107 system/hostid.xml system/power.xml system/pfexecd.xml
108 system/consadm.xml system/pools.xml system/console-login.xml
109 system/stmf.xml system/fmd.xml system/utmp.xml
110 system/poold.xml system/dumpadm.xml"
112 SYSTEM="system/boot/real-mode
113 system/boot/loader system/data/hardware-registry
114 system/extended-system-utilities
115 system/file-system/autofs system/file-system/nfs
116 system/file-system/udfs
117 system/flash/fwflash
118 system/fru-id/platform system/fru-id system/ipc
119 system/library/platform system/library/policykit
120 system/library/processor
121 system/library/storage/fibre-channel/hbaapi
122 system/library/storage/fibre-channel/libsun_fc
123 system/library/storage/ima/header-ima
124 system/library/storage/ima
125 system/library/storage/libmpapi
126 system/library/storage/libmpscsi_vhci
127 system/network
128 system/storage/luxadm
129 system/storage/fibre-channel/port-utility"
131 DEBUG_PKGS="developer/debug/mdb system/kernel/dtrace/providers"
133 PARTS="system/core-os system/kernel
134 shell/pipe-viewer editor/vim editor/vim/vim-core web/curl
135 developer/linker openssh
136 diagnostic/diskinfo shell/bash"
138 PKGS="$PARTS $SYSTEM"
140 if [ -n "$DEBUG" ]; then
141 PKGS="$PKGS $DEBUG_PKGS"
142 BIGROOT=1
144 CULL="python package/pkg snmp"
145 RMRF="/var/pkg /usr/share/man /usr/lib/python2.7 /usr/lib/iconv"
147 ID=`id -u`
148 if [[ "$ID" != "0" ]]; then
149 echo "must run as root"
150 exit 1
153 chkpt() {
154 SNAP=`zfs list -H -t snapshot $BASE/root@${1} 2> /dev/null`
155 if [[ "$DIDWORK" -ne "0" ]]; then
156 if [[ -n "$SNAP" ]]; then
157 zfs destroy $BASE/root@${1} || \
158 fail "zfs destroy ${1} failed"
160 zfs snapshot $BASE/root@${1} || fail "zfs snapshot failed"
162 if [[ "${1}" != "begin" ]]; then
163 echo " === Proceeding to phase $1 (zfs @${1}) ==="
164 zfs rollback -r $BASE/root@${1} || fail "zfs rollback failed"
165 else
166 echo " === Proceeding to phase $1 ==="
168 CHKPT=$1
169 DIDWORK=1
172 if [[ -n "$1" ]]; then
173 echo "Explicit checkpoint requested: '$1'"
174 CHKPT=$1
175 chkpt $CHKPT
177 if [[ -z "$CHKPT" ]]; then
178 CHKPT="begin"
181 declare -A keep_list
182 load_keep_list() {
183 for datafile in $*
185 FCNT=0
186 while read file
188 if [[ -n "$file" ]]; then
189 keep_list+=([$file]="x")
190 FCNT=$(($FCNT + 1))
192 done < <(cut -f2- -d/ $datafile)
193 echo " --- keeping $FCNT files from $datafile"
194 done
197 step() {
198 CHKPT=""
199 case "$1" in
201 "begin")
202 zfs destroy -r $BASE/root 2> /dev/null
203 zfs create -o compression=off $BASE/root || fail "zfs create failed"
204 chkpt pkg
207 "pkg")
209 echo "Creating image of $PUBLISHER from $PKGURL1"
210 $PKG image-create -F -p $PUBLISHER=$PKGURL1 $ROOTDIR || fail "image-create"
211 $PKG -R $ROOTDIR change-variant arch=i386 # FIXME hack
212 $PKG -R $ROOTDIR set-publisher -p $PKGURL2 || fail 'userland'
213 $PKG -R $ROOTDIR install $PKGS || fail "install"
214 chkpt fixup
217 "fixup")
219 echo "Fixing up install root"
220 (cp $ROOTDIR/etc/vfstab $WORKDIR/vfstab && \
221 awk '{if($3!="/"){print;}}' $WORKDIR/vfstab > $ROOTDIR/etc/vfstab && \
222 echo "/devices/ramdisk:a - / ufs - no nologging" >> $ROOTDIR/etc/vfstab) || \
223 fail "vfstab / updated"
224 rm $WORKDIR/vfstab
225 cp $ROOTDIR/lib/svc/seed/global.db $ROOTDIR/etc/svc/repository.db
227 sed -i '' 's,PASSREQ=YES,PASSREQ=NO,' $ROOTDIR/etc/default/login
229 ${SVCCFG} import ${ROOTDIR}/lib/svc/manifest/milestone/sysconfig.xml
230 for xml in $UNNEEDED_MANIFESTS; do
231 rm -f ${ROOTDIR}/lib/svc/manifest/$xml && echo " --- tossing $xml"
232 done
233 echo " --- initial manifest import"
234 # See if we can transform manifest-import to use the 'native' svccfg.
235 sed 's/\/usr\/sbin\/svccfg/\$SVCCFG/g' \
236 < ${ROOTDIR}/lib/svc/method/manifest-import \
237 > /tmp/manifest-import.$$
238 chmod 0755 /tmp/manifest-import.$$
239 export SVCCFG
240 /tmp/manifest-import.$$ -f ${ROOTDIR}/etc/svc/repository.db \
241 -d ${ROOTDIR}/lib/svc/manifest
242 /bin/rm -f /tmp/manifest-import.$$
244 ${SVCCFG} -s 'system/boot-archive' setprop 'start/exec=:true'
245 ${SVCCFG} -s 'system/manifest-import' setprop 'start/exec=:true'
246 ${SVCCFG} -s 'system/console-login' setprop 'startd/need_session=true'
247 ${SVCCFG} -s 'system/console-login' setprop 'start/exec="/kayak/takeover-console /kayak/kayak-menu.sh"'
248 echo " --- neutering the manifest import"
249 echo "#!/bin/ksh" > ${ROOTDIR}/lib/svc/method/manifest-import
250 echo "exit 0" >> ${ROOTDIR}/lib/svc/method/manifest-import
251 chmod 555 ${ROOTDIR}/lib/svc/method/manifest-import
252 chkpt cull
255 "cull")
256 if [[ -z "$BIGROOT" ]]; then
257 load_keep_list data/*
258 while read file
260 if [[ -n "$file" && \
261 ${keep_list[$file]} == "" && \
262 -e "$ROOTDIR/$file" && \
263 ! -d $ROOTDIR/$file ]] ; then
264 rm -f $ROOTDIR/$file
266 done < <(cd $ROOTDIR && find ./ | cut -c3-)
267 for path in $RMRF ; do
268 rm -rf ${ROOTDIR}$path && echo " -- tossing $path"
269 done
272 chkpt mkfs
275 "mkfs")
276 size=`/usr/bin/du -ks ${ROOTDIR}|/usr/bin/nawk '{print $1+10240}'`
277 echo " --- making image of size $size"
278 /usr/sbin/mkfile ${size}k $MKFILEDIR/miniroot || fail "mkfile"
279 lofidev=`/usr/sbin/lofiadm -a $MKFILEDIR/miniroot`
280 rlofidev=`echo $lofidev |sed s/lofi/rlofi/`
281 yes | /usr/sbin/newfs -m 0 $rlofidev 2> /dev/null > /dev/null || fail "newfs"
282 chkpt mount
285 "mount")
286 mkdir -p $WORKDIR/mnt
287 /usr/sbin/mount -o nologging $lofidev $WORKDIR/mnt || fail "mount"
288 chkpt copy
291 "copy")
292 pushd $ROOTDIR >/dev/null
293 /usr/bin/find . | /usr/bin/cpio -pdum $WORKDIR/mnt 2> /dev/null > /dev/null || fail "populate root"
294 /usr/sbin/devfsadm -r $WORKDIR/mnt > /dev/null
295 popd >/dev/null
296 mkdir $WORKDIR/mnt/kayak
297 cp $SRCDIR/*.sh $WORKDIR/mnt/kayak/
298 chmod a+x $WORKDIR/mnt/kayak/*.sh
300 if [[ -n "$DEBUG" ]]; then
301 cp $SRCDIR/anon.system $WORKDIR/mnt/etc/system
302 cp $SRCDIR/anon.dtrace.conf $WORKDIR/mnt/kernel/drv/dtrace.conf
304 chkpt umount
307 "umount")
308 /usr/sbin/umount $WORKDIR/mnt || fail "umount"
309 /usr/sbin/lofiadm -d $MKFILEDIR/miniroot || fail "lofiadm delete"
310 chkpt compress
313 "compress")
314 $GZIP_CMD -c -f $MKFILEDIR/miniroot > $WORKDIR/miniroot.gz
315 rm -f $MKFILEDIR/miniroot
316 chmod 644 $WORKDIR/miniroot.gz
317 echo " === Finished ==="
318 ls -l $WORKDIR/miniroot.gz
321 esac
324 while [[ -n "$CHKPT" ]]; do
325 step $CHKPT
326 done