distro_boot.sh 4.35 KB
Newer Older
1
2
3
4
5
#!/bin/bash

installer_image=""
disk_size=""
mode=""
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
platform_dir=""
network=false
extra_param=""

declare -A sgi_platforms
sgi_platforms[sgi575]=1

__print_supported_sgi_platforms()
{
	echo "Supported platforms are -"
	for plat in "${!sgi_platforms[@]}" ;
		do
			printf "\t $plat \n"
		done
	echo
}
22
23
24

install ()
{
25
	disk_name="$PWD/$RANDOM.satadisk"
26
27
28
29
30
31

	# Create a disk of $disk_size GB
	dd if=/dev/zero of=$disk_name bs=1G count=$disk_size

	echo "Created $disk_name of size $disk_size GB, proceeding to install $installer_image ..."

32
33
	pushd $platform_dir
	./run_model.sh -v $installer_image -d $disk_name -n $network -a "$extra_param"
34
35
36
37
38
39
40
}

# This script allows a user to create a virtual satadisk and install either
# Fedora 27 or Debian 9.3 on to it or boot an existing install.

boot ()
{
41
42
43
44
45
46
47
48
49
50
51
52
	# Check if a installed sata disk image is supplied. If yes, boot from it.
	if [ ! -z "$disk_image" ] ; then
		dir_name="$(dirname $disk_image)"
		if [ $dir_name == "." ] ; then
			disk_image="$PWD/$disk_image"
		fi
		echo "Proceeding to boot supplied disk image name: $disk_image ..."
		pushd $platform_dir
		./run_model.sh -d $disk_image -n $network -a "$extra_param"
		exit 0
	fi

53
54
55
56
57
58
59
60
61
62
63
64
65
	# If $disk_image is not specified, see if there are more than one
	# .satadisk files, if so, prompt the user to pick one with -d.
	# If there is exactly one available, boot it. If there are none, prompt
	# the user to install with -i/-s

	available_images=$(find . -name "*.satadisk")
	num_available_images=$(echo $available_images | wc -w)

	case $num_available_images in
		1)
			# In the case of exactly one, the list of images will
			# be the image name so just use it
			echo "Found $available_images, proceeding to boot ..."
66
			available_images=$PWD/$available_images
67
68
			pushd $platform_dir
			./run_model.sh -d $available_images -n $network -a "$extra_param"
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
			;;
		*)
			if [[ -z "$disk_image" ]]; then
				echo "Found several available images:"
				echo ""
				echo $available_images | sed 's/\.\///g' | tr ' ' '\n'
				echo ""
				echo "Please choose one using distro_boot -d [disk_image]"
				echo ""
			fi
			;;
	esac
}

print_usage ()
{
	echo "distro_boot:"
	echo ""
	echo " Install or boot Linux distos on System Guidance Models."
	echo ""
89
90
	echo "distro_boot -p [platform] -i [image] -s [disk size] -d [ disk image]"
	echo "	-p - SGI platform name"
91
92
93
94
95
	echo "	-i - Image, takes a path to an iso installer image"
	echo "	-s - Disk size in GB."
	echo "	-d - Disk image with previously installed distro, used for"
	echo "	     disambiguation if there are more than one installed"
	echo "	     concurrently"
96
97
	echo "  -n - Enable network: true or (default)false"
	echo "  -a - Additional model parameters, if any"
98
99
100
101
102
103
104
105
	echo ""
	echo " distro_boot must be called either with both -i and -s options or"
	echo " with neither, please see examples below"
	echo ""
	echo "Examples:"
	echo ""
	echo "	Install Fedora 27 on to a 16 GB disk"
	echo ""
106
	echo "		distro_boot -p sgi575 -i Fedora-Server-dvd-aarch64-27-1.6.iso -s 16"
107
108
109
	echo ""
	echo "	Boot existing single install"
	echo ""
110
	echo "		distro_boot -p sgi575"
111
112
113
	echo ""
	echo "	Boot existing install from a set of intalled disks"
	echo ""
114
	echo "		distro_boot -p sgi575 -d bluepeter.satadisk"
115
116
117
	echo ""
}

118
while getopts "p:i:s:d:n:a:h" opt; do
119
	case $opt in
120
121
122
		p)
			platform=$OPTARG
			;;
123
124
125
126
127
128
129
130
131
		i)
			installer_image=$OPTARG
			;;
		s)
			disk_size=$OPTARG
			;;
		d)
			disk_image=$OPTARG
			;;
132
133
134
135
136
137
		n)
			network=$OPTARG
			;;
		a)
			extra_param=$OPTARG
			;;
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
		*)
			print_usage
			exit 1
			;;
	esac
done


# Either an installer and a disk size is specified or neither.
# If they are specified, create a new disk and boot the model with those params
# if not, check for an existing .satadisk file and use that to boot from
# otherwise throw an error

if [[ ! -z $disk_size ]] && [[ ! -z $installer_image ]]; then
	mode="install"
elif [[ -z $disk_size ]] && [[ -z $installer_image ]]; then

	# There is no need to separate the boot from single / multiple images
	# at this stage, we can handle that in boot()
	mode="boot"
else
	print_usage
	exit 1
fi

163
164
165
166
167
168
169
170
171
172
173
174
175
#Ensure that the platform is supported
if [ -z "$platform" ] ; then
	print_usage
	exit 1
fi
if [ -z "${sgi_platforms[$platform]}" ] ; then
	echo "[ERROR] Could not deduce the selected platform."
	__print_supported_sgi_platforms
	exit 1
fi

platform_dir="platforms/$platform"

176
177
178
179
180
181
182
183
184
185
186
187
case $mode in
	install)
		install
		;;
	boot)
		boot
		;;
	*)
		echo "Unknown mode"
		exit 1
		;;
esac