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 # Capture diskinfo(1M) output in a tempfile.
  19 
  20 keyboard_layout=${1:-US-English}
  21 SCRATCH=/tmp/di.$$
  22 diskinfo > $SCRATCH
  23 numdisks=`wc -l $SCRATCH | awk '{print $1}'`
  24 echo "numdisks before $numdisks"
  25 numdisks=$(($numdisks - 1))
  26 echo "numdisks after $numdisks"
  27 
  28 # Number of disks on one page, must be <= 7.
  29 onepage=7
  30 highpage=$(($numdisks / $onepage))
  31 remainder=$(($numdisks % $onepage))
  32 if [[ $remainder != 0 ]]; then
  33     highpage=$(($highpage + 1))
  34 fi
  35 
  36 # Present the list of disks in a pretty manner, and get the user to
  37 # generate a list of one or more disks.  Put them in $DISKLIST...
  38 finished=0
  39 offset=2
  40 page=0
  41 DISKLIST=""
  42 until [[ $finished == 1 ]]; do
  43     clear
  44     echo "root pool disks: [$DISKLIST]"
  45     echo "0 == done, 1-7 == select-disk 8 == next-page, 9 == clear"
  46     echo "--------------------------------------------------------"
  47     head -1 $SCRATCH | awk '{print "#   ",$0}'
  48     echo ""
  49     tail +$offset $SCRATCH | head -$onepage | awk '{print NR,"   ",$0}' \
  50                                                   > /tmp/dp.$$
  51     cat /tmp/dp.$$
  52     echo ""
  53     echo -n "Enter a digit or the disk device name ==> "
  54     read choice
  55 
  56     if [[ $choice == 9 ]]; then
  57         DISKLIST=""
  58     elif [[ $choice == 8 ]]; then
  59         page=$(($page + 1))
  60         if [[ $page == $highpage ]]; then
  61             page=0
  62         fi
  63         offset=$(($page * $onepage + 2))
  64     elif [[ $choice == 0 ]]; then
  65         if [[ $DISKLIST == "" ]]; then
  66             echo -n "Press RETURN to go back to the main menu: "
  67             read
  68             exit
  69         else
  70             finished=1
  71         fi
  72     else
  73         if [[ $choice == "" ]]; then
  74             continue
  75         fi
  76         NEWDISK=`nawk -v choice=$choice '$1 == choice {print $3}' < /tmp/dp.$$`
  77         if [[ $NEWDISK == "" ]]; then
  78             NEWDISK=`nawk -v choice=$choice '$3 == choice {print $3}' < \
  79                 /tmp/dp.$$`
  80         fi
  81         if [[ $NEWDISK != "" ]]; then
  82             if [[ $DISKLIST == "" ]]; then
  83                 DISKLIST=$NEWDISK
  84             elif [[ `echo $DISKLIST | grep $NEWDISK` == "" ]]; then
  85                 DISKLIST="$DISKLIST $NEWDISK"
  86             fi
  87         fi
  88     fi
  89     rm /tmp/dp.$$
  90 done
  91 
  92 
  93 reality_check() {
  94     mkfile 64m /tmp/test.$$
  95     if [[ $? != 0 ]]; then
  96         echo "WARNING: Insufficient space in /tmp for installation..."
  97         return 1
  98     fi
  99     zpool create $1 /tmp/test.$$
 100     if [[ $? != 0 ]]; then
 101         echo "Can't test zpool create $1"
 102         return 1
 103     fi
 104     zpool destroy $1
 105     rm -f /tmp/test.$$
 106     return 0
 107 }
 108 
 109 NEWRPOOL="rpool"
 110 until [[ $NEWRPOOL == "" ]]; do
 111     RPOOL=$NEWRPOOL
 112     echo -n "Enter the root pool name or press RETURN if you want [$RPOOL]: "
 113     read NEWRPOOL
 114     if [[ $NEWRPOOL != "" ]]; then
 115         reality_check $NEWRPOOL
 116         if [[ $? != 0 ]]; then
 117             NEWRPOOL=$RPOOL
 118         fi
 119     fi
 120 done
 121 
 122 . /kayak/install_help.sh
 123 . /kayak/disk_help.sh
 124 BuildRpoolOnly $DISKLIST
 125 
 126 rm -f $SCRATCH
 127 
 128 # Running actual install.
 129 /kayak/rpool-install.sh $RPOOL $keyboard_layout