fix sed -i invocations
[unleashed-kayak.git] / find-and-install.sh
blob07c2d8e74465df127d6e2a7061d5487fee63dc0b
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.
18 # Capture diskinfo(1M) output in a tempfile.
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"
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))
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 ==> "
54 read choice
56 if [[ $choice == 9 ]]; then
57 DISKLIST=""
58 elif [[ $choice == 8 ]]; then
59 ###DEBUG
60 #echo -n "Old page $page, offset $offset... HIT RETURN!"
61 #read
63 page=$(($page + 1))
64 if [[ $page == $highpage ]]; then
65 page=0
67 offset=$(($page * $onepage + 2))
68 ###DEBUG
69 #echo -n "New page $page, offset $offset... HIT RETURN!"
70 #read
71 elif [[ $choice == 0 ]]; then
72 if [[ $DISKLIST == "" ]]; then
73 echo -n "Press RETURN to go back to the main menu: "
74 read
75 exit
76 else
77 finished=1
79 else
80 if [[ $choice == "" ]]; then
81 continue
83 NEWDISK=`grep -w $choice /tmp/dp.$$ | awk '{print $3}'`
84 if [[ $NEWDISK != "" ]]; then
85 if [[ $DISKLIST == "" ]]; then
86 DISKLIST=$NEWDISK
87 elif [[ `echo $DISKLIST | grep $NEWDISK` == "" ]]; then
88 DISKLIST="$DISKLIST $NEWDISK"
92 rm /tmp/dp.$$
93 done
96 reality_check() {
97 mkfile 64m /tmp/test.$$
98 if [[ $? != 0 ]]; then
99 echo "WARNING: Insufficient space in /tmp for installation..."
100 return 1
102 zpool create $1 /tmp/test.$$
103 if [[ $? != 0 ]]; then
104 echo "Can't test zpool create $1"
105 return 1
107 zpool destroy $1
108 rm -f /tmp/test.$$
109 return 0
112 NEWRPOOL="rpool"
113 until [[ $NEWRPOOL == "" ]]; do
114 RPOOL=$NEWRPOOL
115 echo -n "Enter the root pool name or press RETURN if you want [$RPOOL]: "
116 read NEWRPOOL
117 if [[ $NEWRPOOL != "" ]]; then
118 reality_check $NEWRPOOL
119 if [[ $? != 0 ]]; then
120 NEWRPOOL=$RPOOL
123 done
125 ###DEBUG
126 #echo "Would do this:"
127 #echo " BuildRpool $DISKLIST"
128 . /kayak/install_help.sh
129 . /kayak/disk_help.sh
130 BuildRpoolOnly $DISKLIST
132 rm -f $SCRATCH
134 # Running actual install.
135 /kayak/rpool-install.sh $RPOOL $keyboard_layout