| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 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 |
| 10 | if [scip-shell system . . `[`. ! -e /usr/bin/ubiquityscip-shell filesystem . . `/usr/bin/ubiquity`. ]; then |
| 11 | echoscip-shell system . . echo. "Error: This doesn't appear to be a ubuntu based live image. Exiting." |
| 12 | exit 1 |
| 13 | fi |
| 14 | |
| 15 | RED='\033[1;31m' |
| 16 | GREEN='\033[1;32m' |
| 17 | NC='\033[0m' # No Color |
| 18 | |
| 19 | # shellcheck disable=SC2059 |
| 20 | errorscip-shell shell coreboot 25.09+dfsg-1 error(). () |
| 21 | { |
| 22 | printfscip-shell system . . printf. "${RED}ERROR: $1 ${NC}\n" >&2 |
| 23 | if [scip-shell system . . `[`. -n "$2" ]; then printfscip-shell system . . printf. "${RED}Removing $2 ${NC}\n"; rmscip-shell system . . rm. -rf "./$2"; fi |
| 24 | exit 1 |
| 25 | } |
| 26 | |
| 27 | # shellcheck disable=SC2059 |
| 28 | statusscip-shell shell coreboot 25.09+dfsg-1 status(). () |
| 29 | { |
| 30 | printfscip-shell system . . printf. "${GREEN}${1}${NC}" |
| 31 | } |
| 32 | |
| 33 | # Install and configure the ssh server for the board-status script to connect to. |
| 34 | statusscip-shell shell coreboot 25.09+dfsg-1 status(). "Installing and configuring ssh server\n" |
| 35 | sudoscip-shell system . . sudo. rm -f /etc/apt/sources.listscip-shell filesystem . . `/etc/apt/sources.list`. |
| 36 | sudoscip-shell system . . sudo. apt-get update || \ |
| 37 | error "Could not update packages" |
| 38 | sudoscip-shell system . . sudo. apt-get install -y openssh-server || \ |
| 39 | error "Could not install openssh-server" |
| 40 | sudoscip-shell system . . sudo. sed -i.bak 's/PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_configscip-shell filesystem . . `/etc/ssh/sshd_config`. || \ |
| 41 | error "Could not update sshd.config to allow root login." |
| 42 | sudoscip-shell system . . sudo. 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 |
| 46 | statusscip-shell shell coreboot 25.09+dfsg-1 status(). "Setting root password to 'coreboot'\n" |
| 47 | echoscip-shell system . . echo. -e "root:coreboot" | sudoscip-shell system . . sudo. chpasswd || \ |
| 48 | error "Could not reset root password" |
| 49 | |
| 50 | # Download the coreboot tree |
| 51 | statusscip-shell shell coreboot 25.09+dfsg-1 status(). "Installing git and clone the coreboot repo\n" |
| 52 | sudoscip-shell system . . sudo. apt-get install -y git build-essential || \ |
| 53 | error "Could not install git" |
| 54 | gitscip-shell system . . git. clone --depth 1 https://review.coreboot.org/coreboot || \ |
| 55 | error "Could not download coreboot repository" |
| 56 | |
| 57 | # Build and install cbmem |
| 58 | statusscip-shell shell coreboot 25.09+dfsg-1 status(). "Building and installing cbmem\n" |
| 59 | makescip-shell system . . make. -C coreboot/util/cbmem || \ |
| 60 | error "Could not build cbmem" |
| 61 | sudoscip-shell system . . sudo. make -C coreboot/util/cbmem install || \ |
| 62 | error "Could not instll cbmem" |
| 63 | sudoscip-shell system . . sudo. cbmem || \ |
| 64 | error "cbmem did not run correctly" |
| 65 | rmscip-shell system . . rm. -rf coreboot |
| 66 | |
| 67 | # Identify the ip address that board-status will connect to |
| 68 | IP_ADDR=$(ifconfig -a | grepscip-shell system . . grep. 'inet addr' | grepscip-shell system . . grep. -v '127.0.0.1' | \ |
| 69 | sed 's|.*inet addr:||' | sed 's|Bcast.*||') |
| 70 | statusscip-shell shell coreboot 25.09+dfsg-1 status(). "\nAddress or addresses for this board: $IP_ADDR\n" |