blob: 9fac15304e8348005d579b83a754cfdbd1524e29 [file] [log] [blame]
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00001#!/usr/bin/env bash
Martin Rothf43e51d2016-02-09 12:20:32 -07002
3# This script is used to set up a ubuntu-based live image to be used
4# with coreboot's board_status script. It modifies the system so that
5# board_status can connect over SSH and run cbmem. This script is NOT
6# meant to be run on an installed system, and changes the configuration
7# in ways that would be dangerous to security on an installed system.
8
9# Make sure we're on a ubuntu live image
10if [ ! -e /usr/bin/ubiquity ]; then
11 echo "Error: This doesn't appear to be a ubuntu based live image. Exiting."
12 exit 1
13fi
14
15RED='\033[1;31m'
16GREEN='\033[1;32m'
17NC='\033[0m' # No Color
18
19# shellcheck disable=SC2059
20error ()
21{
22 printf "${RED}ERROR: $1 ${NC}\n" >&2
23 if [ -n "$2" ]; then printf "${RED}Removing $2 ${NC}\n"; rm -rf "./$2"; fi
24 exit 1
25}
26
27# shellcheck disable=SC2059
28status ()
29{
30 printf "${GREEN}${1}${NC}"
31}
32
33# Install and configure the ssh server for the board-status script to connect to.
34status "Installing and configuring ssh server\n"
35sudo rm -f /etc/apt/sources.list
36sudo apt-get update || \
37 error "Could not update packages"
38sudo apt-get install -y openssh-server || \
39 error "Could not install openssh-server"
40sudo sed -i.bak 's/PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config || \
41 error "Could not update sshd.config to allow root login."
42sudo sudo service ssh restart || \
43 error "Could not restart ssh server"
44
45# Set the root password so it can be used to log in
46status "Setting root password to 'coreboot'\n"
47echo -e "root:coreboot" | sudo chpasswd || \
48 error "Could not reset root password"
49
50# Download the coreboot tree
51status "Installing git and clone the coreboot repo\n"
52sudo apt-get install -y git build-essential || \
53 error "Could not install git"
54git clone --depth 1 https://review.coreboot.org/coreboot || \
55 error "Could not download coreboot repository"
56
57# Build and install cbmem
58status "Building and installing cbmem\n"
59make -C coreboot/util/cbmem || \
60 error "Could not build cbmem"
61sudo make -C coreboot/util/cbmem install || \
62 error "Could not instll cbmem"
63sudo cbmem || \
64 error "cbmem did not run correctly"
65rm -rf coreboot
66
67# Identify the ip address that board-status will connect to
68IP_ADDR=$(ifconfig -a | grep 'inet addr' | grep -v '127.0.0.1' | \
69 sed 's|.*inet addr:||' | sed 's|Bcast.*||')
70status "\nAddress or addresses for this board: $IP_ADDR\n"