fix sed -i invocations
[unleashed-kayak.git] / build_iso.sh
blob5f98f488520459a6be9069b4cf4b7cc4a3c94921
1 #!/usr/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.
19 # Build an ISO installer using the Kayak tools.
22 if [[ `id -u` != "0" ]]; then
23 echo "You must be root to run this script."
24 exit 1
27 if [[ -z $BUILDSEND_MP ]]; then
28 echo "Using /rpool/kayak_image for BUILDSEND_MP"
29 BUILDSEND_MP=/rpool/kayak_image
32 if [[ -z $VERSION ]]; then
33 VERSION=`grep OmniOS $BUILDSEND_MP/root/etc/release | awk '{print $3}'`
34 echo "Using $VERSION..."
37 # Many of these depend on sufficient space in /tmp by default. Please
38 # modify as you deem appropriate.
39 PROTO=/tmp/proto
40 KAYAK_ROOTBALL=$BUILDSEND_MP/miniroot.gz
41 KAYAK_ROOT=/tmp/miniroot.$$
42 KR_FILE=/tmp/kr.$$
43 MNT=/mnt
44 UFS_LOFI=/tmp/boot_archive
45 LOFI_SIZE=600M
46 DST_ISO=/tmp/${VERSION}.iso
47 ZFS_IMG=$BUILDSEND_MP/*.bz2
49 # Create a UFS lofi file and mount the UFS filesystem in $MNT. This will
50 # form the boot_archive for the ISO.
51 mkfile $LOFI_SIZE $UFS_LOFI
52 LOFI_PATH=`lofiadm -a $UFS_LOFI`
53 echo 'y' | newfs $LOFI_PATH
54 mount $LOFI_PATH $MNT
56 # Clone the already-created Kayak miniroot and copy it into both $MNT, and
57 # into a now-created $PROTO. $PROTO will form the directory that gets
58 # sprayed onto the ISO.
59 gunzip -c $KAYAK_ROOTBALL > $KR_FILE
60 LOFI_RPATH=`lofiadm -a $KR_FILE`
61 mkdir $KAYAK_ROOT
62 mount $LOFI_RPATH $KAYAK_ROOT
63 tar -cf - -C $KAYAK_ROOT . | tar -xf - -C $MNT
64 mkdir $PROTO
65 tar -cf - -C $KAYAK_ROOT . | tar -xf - -C $PROTO
66 umount $KAYAK_ROOT
67 rmdir $KAYAK_ROOT
68 lofiadm -d $LOFI_RPATH
69 rm $KR_FILE
72 # Put additional goodies into the boot-archive on $MNT, which is
73 # what'll be / (via ramdisk) once one boots the ISO.
76 # The full ZFS image (also already-created) for actual installation.
77 cp $ZFS_IMG $MNT/root/.
79 # A cheesy way to get the boot menu to appear at boot time.
80 cp -p ./takeover-console $MNT/kayak/.
81 cat <<EOF > $MNT/root/.bashrc
82 export PATH=/usr/bin:/usr/sbin:/sbin
83 export HOME=/root
84 EOF
85 # Have initialboot muck with the console login service to make an interactive
86 # installer get invoked.
87 cat <<EOF > $MNT/.initialboot
88 /usr/sbin/svccfg -s console-login:default setprop startd/need_session = boolean: true
89 /usr/sbin/svcadm refresh console-login:default
90 /usr/sbin/svcadm restart console-login:default
91 EOF
92 cat <<EOF > $MNT/lib/svc/method/console-login
93 #!/bin/bash
95 # CHEESY way to get the kayak-menu running w/o interference.
96 export TERM=sun-color
97 /kayak/takeover-console /kayak/kayak-menu.sh
98 EOF
99 chmod 0755 $MNT/lib/svc/method/console-login
101 # Refresh the devices on the miniroot.
102 devfsadm -r $MNT
105 # The ISO's miniroot is going to be larger than the PXE miniroot. To that
106 # end, some files not listed in the exception list do need to show up on
107 # the miniroot. Use PREBUILT_ILLUMOS if available, or the current system
108 # if not.
110 from_one_to_other() {
111 tar -cf - -C $ZIROOT/$1 . | tar -xf - -C $MNT/$1
114 if [[ -z $PREBUILT_ILLUMOS ]]; then
115 ZIROOT=/
116 else
117 ZIROOT=$PREBUILT_ILLUMOS/proto/root_i386
120 # Add from_one_to_other for any directory you need.
121 from_one_to_other usr/share/lib/zoneinfo
122 from_one_to_other usr/share/lib/keytables
124 # Gross hack to create a version of /usr/bin/digest that doesn't need
125 # to have all of the crypto framework libraries. sha1sum is available,
126 # and we can use it.
127 cat <<EOF > $MNT/usr/bin/digest
128 #!/bin/bash
130 # FOR NOW, assume we're only ever going to be invoked by create_ramdisk,
131 # which uses "digest -a sha1 <one-filename>".
133 usage() {
134 echo "Usage:" > /dev/stderr
135 echo " digest -l | [-v] -a <algorithm> [file...]" > /dev/stderr
136 exit 2
139 if [[ \$1 != "-a" || \$2 != "sha1" ]]; then
140 usage
143 sha1sum \$3 | awk '{print $1}'
144 exit 0
146 chmod 0755 $MNT/usr/bin/digest
148 # Remind people this is the installer.
149 #sed 's/OmniOS/the OmniOS installer/g' < $PROTO/boot/defaults/loader.conf > /tmp/loader.conf.$$
150 #mv /tmp/loader.conf.$$ $PROTO/boot/defaults/loader.conf
151 cat <<EOF > $PROTO/boot/loader.conf.local
152 loader_menu_title="Welcome to the OmniOS installer"
153 autoboot_delay=5
157 # Okay, we've populated the new ISO miniroot. Close it up and install it
158 # on $PROTO as the boot archive.
160 umount $MNT
161 lofiadm -d $LOFI_PATH
162 cp $UFS_LOFI $PROTO/platform/i86pc/amd64/boot_archive
163 digest -a sha1 $UFS_LOFI > $PROTO/platform/i86pc/amd64/boot_archive.hash
164 rm -rf $PROTO/{usr,bin,sbin,lib,kernel}
165 du -sh $PROTO/.
167 # And finally, burn the ISO.
168 mkisofs -o $DST_ISO -b boot/cdboot -c .catalog -no-emul-boot -boot-load-size 4 -boot-info-table -N -l -R -U -allow-multidot -no-iso-translate -cache-inodes -d -D -V OmniOS $PROTO
170 rm -rf $PROTO $UFS_LOFI
171 echo "$DST_ISO is ready"
172 ls -lt $DST_ISO