1 #!/usr/bin/bash
   2 
   3 #
   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.
   8 #
   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.
  12 #
  13 
  14 #
  15 # Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved.
  16 #
  17 
  18 #
  19 # Build an ISO installer using the Kayak tools.
  20 #
  21 
  22 if [[ `id -u` != "0" ]]; then
  23         echo "You must be root to run this script."
  24         exit 1
  25 fi
  26 
  27 if [[ -z $BUILDSEND_MP ]]; then
  28         echo "Using /rpool/kayak_image for BUILDSEND_MP"
  29         BUILDSEND_MP=/rpool/kayak_image
  30 fi
  31 
  32 if [[ -z $VERSION ]]; then
  33         VERSION=`grep OmniOS $BUILDSEND_MP/root/etc/release | awk '{print $3}'`
  34         echo "Using $VERSION..."
  35 fi
  36 
  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=$BUILDSEND_MP/${VERSION}.iso
  47 ZFS_IMG=$BUILDSEND_MP/kayak_${VERSION}.zfs.bz2
  48 
  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
  55 
  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
  70 
  71 #
  72 # Put additional goodies into the boot-archive on $MNT, which is
  73 # what'll be / (via ramdisk) once one boots the ISO.
  74 # 
  75 
  76 # The full ZFS image (also already-created) for actual installation.
  77 cp $ZFS_IMG $MNT/root/.
  78 
  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
  94 
  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
 100 
 101 # Refresh the devices on the miniroot.
 102 devfsadm -r $MNT
 103 
 104 #
 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.
 109 #
 110 from_one_to_other() {
 111     dir=$1
 112     if [[ -z $PREBUILT_ILLUMOS || ! -d $PREBUILT_ILLUMOS/proto/root_i386/$dir ]]
 113     then
 114         FROMDIR=/
 115     else
 116         FROMDIR=$PREBUILT_ILLUMOS/proto/root_i386
 117     fi
 118 
 119     shift
 120     tar -cf - -C $FROMDIR/$dir ${@:-.} | tar -xf - -C $MNT/$dir
 121 }
 122 
 123 # Add from_one_to_other for any directory {file|subdir file|subdir ...} you need
 124 from_one_to_other usr/share/lib/zoneinfo
 125 from_one_to_other usr/share/lib/keytables
 126 from_one_to_other usr/share/lib/terminfo
 127 from_one_to_other usr/gnu/share/terminfo
 128 from_one_to_other usr/sbin ping
 129 from_one_to_other usr/bin netstat
 130 
 131 # Remind people this is the installer.
 132 cat <<EOF > $PROTO/boot/loader.conf.local
 133 loader_menu_title="Welcome to the OmniOS installer"
 134 autoboot_delay=5
 135 EOF
 136 
 137 #
 138 # Okay, we've populated the new ISO miniroot.  Close it up and install it
 139 # on $PROTO as the boot archive.
 140 #
 141 umount $MNT
 142 lofiadm -d $LOFI_PATH
 143 cp $UFS_LOFI $PROTO/platform/i86pc/amd64/boot_archive
 144 digest -a sha1 $UFS_LOFI > $PROTO/platform/i86pc/amd64/boot_archive.hash
 145 rm -rf $PROTO/{usr,bin,sbin,lib,kernel}
 146 du -sh $PROTO/.
 147 
 148 # And finally, burn the ISO.
 149 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
 150 
 151 rm -rf $PROTO $UFS_LOFI
 152 echo "$DST_ISO is ready"
 153 ls -lt $DST_ISO