distro.sh 6.03 KB
Newer Older
1
#!/bin/bash
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
###############################################################################
# Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of ARM nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#################################################################################
31

32
33
source $PWD/../sgi/sgi_common_util.sh

34
35
36
installer_image=""
disk_size=""
mode=""
37
38
39
40
platform_dir=""
network=false
extra_param=""

41
42
43
44
45
46
# List of all the supported platforms.
declare -A platforms_sgi
platforms_sgi[sgi575]=1
declare -A platforms_rdinfra
platforms_rdinfra[rdn1edge]=1
platforms_rdinfra[rde1edge]=1
47
platforms_rdinfra[rdv1]=1
48
platforms_rdinfra[rdv1mc]=1
49
platforms_rdinfra[rdn2]=1
50
platforms_rdinfra[rdn2cfg1]=1
51
52
53

install ()
{
54
	disk_name="$PWD/$RANDOM.satadisk"
55
56
57
58
59
60

	# 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 ..."

61
	pushd $platform_dir
62
	source ./run_model.sh -v $installer_image -d $disk_name -n $network -a "$extra_param"
63
64
65
66
67
68
69
}

# 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 ()
{
70
71
72
73
74
75
76
77
	# 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
78
		source ./run_model.sh -d $disk_image -n $network -a "$extra_param"
79
80
81
		exit 0
	fi

82
83
84
85
86
87
88
89
90
91
92
93
94
	# 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 ..."
95
			available_images=$PWD/$available_images
96
			pushd $platform_dir
97
			source ./run_model.sh -d $available_images -n $network -a "$extra_param"
98
99
100
101
102
103
104
105
106
107
108
109
110
111
			;;
		*)
			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
}

112
113
114
115
116
117
118
119
120
121
122
123
__print_examples()
{
	echo "Example 1: ./distro.sh -p $1 -i Fedora-Server-dvd-aarch64-27-1.6.iso -s 16"
	echo "  Installs Fedora 27 on to a 16 GB disk."
	echo ""
	echo "Example 2: ./distro.sh -p $1"
	echo "  Finds an available installed disk image and boots from it."
	echo ""
	echo "Example 3: ./distro.sh -p $1 -d fedora27.satadisk"
	echo "  Boot from an existing installed disk image"
}

124
125
126
print_usage ()
{
	echo ""
127
	echo "Install or boot linux distribution."
128
	echo "Usage: ./distro.sh -p <platform> -i <image> -s <disk size> [-d <disk image>] [-n <true|false>] [-a \"model params\"]"
129
	echo ""
130
	echo "Supported command line parameters:"
131
	echo "  -p   platform name (mandatory)"
132
133
134
135
136
137
138
	echo "  -i   Image, takes a path to an iso installer image (mandatory for installation)"
	echo "  -s   Disk size in GB (mandatory for installation)"
	echo "  -d   Disk image with previously installed distro, used for"
	echo "       disambiguation if there are more than one installed"
	echo "       concurrently."
	echo "  -n   Enable network: true or false (default: false)"
	echo "  -a   Additional model parameters, if any"
139
	echo ""
140
141
	__print_supported_platforms_$refinfra
	__print_examples_$refinfra
142
143
144
	echo ""
}

145
while getopts "p:i:s:d:n:a:h" opt; do
146
	case $opt in
147
148
149
		p)
			platform=$OPTARG
			;;
150
151
152
153
154
155
156
157
158
		i)
			installer_image=$OPTARG
			;;
		s)
			disk_size=$OPTARG
			;;
		d)
			disk_image=$OPTARG
			;;
159
160
161
162
163
164
		n)
			network=$OPTARG
			;;
		a)
			extra_param=$OPTARG
			;;
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
		*)
			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

189
#Ensure that the platform is supported
190
__parse_params_validate
191
192
193

platform_dir="platforms/$platform"

194
195
196
197
198
199
200
201
202
203
204
205
case $mode in
	install)
		install
		;;
	boot)
		boot
		;;
	*)
		echo "Unknown mode"
		exit 1
		;;
esac