From 5acef754fe41f32e91dcfac93d3f8cfe85df8bf2 Mon Sep 17 00:00:00 2001 From: Zen Date: Sun, 16 Jan 2022 01:09:55 +0000 Subject: [PATCH] Added 'make preparations' --- Makefile | 3 +- README.md | 6 ++- scripts/prep-rpi-usb.sh | 82 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 3 deletions(-) create mode 100755 scripts/prep-rpi-usb.sh diff --git a/Makefile b/Makefile index 2b88960..3cf5df7 100644 --- a/Makefile +++ b/Makefile @@ -20,5 +20,6 @@ imbuement: @scripts/write-image.sh preparations: - @echo "soon!" + @chmod +x scripts/prep-rpi-usb.sh + @scripts/prep-rpi-usb.sh diff --git a/README.md b/README.md index 0ce7209..d1cfeb9 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ A collection of scripts for working with bare metal. `make it-pretty` is meant to be run on a freshly installed operating system. It installs some utilities that I rely on for maximum developmental efficiency and generally makes the terminal nicer to look at. -`make acquisition` runs a script that downloads an image and confirms it with a sha256 sum. +`make acquisition` runs a script that downloads a file (in this case, an RPI image) and confirms it with a sha256 sum. -`make imbuement` Looks for available USBs attached to the device and writes an image to it. +`make imbuement` looks for available USBs attached to the device and writes an image to it. + +`make preparations` configures some basic settings for use on a fresh RPi installation (SSH, hostname) diff --git a/scripts/prep-rpi-usb.sh b/scripts/prep-rpi-usb.sh new file mode 100755 index 0000000..dd78241 --- /dev/null +++ b/scripts/prep-rpi-usb.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +# Prepares the boot and file system sectors of a Raspberry Pi for on-network use +# Zen, 2022 + +# Font decoration for better a e s t h e t i c +RED="\e[0;91m" +GREEN="\e[0;92m" +BLUE="\e[0;94m" +BOLD="\e[1m" +ULINE="\e[4m" +NC="\e[0m" + +# ------------------- Step 1 - Select USB ------------------- + +echo "Looking for USB devices..." +echo "" +echo -e "${ULINE}Found these!${NC}" +lsblk -pdo NAME,MODEL,TRAN | grep usb > usb-list +i=1 +while read -u 11 line; do + echo -e "${BOLD}$i.${NC} $line" + i=$((i+1)) +done 11> /mnt/cmdline.txt" + ;; +esac +echo "" +echo "Enabling SSH" +sudo touch /mnt/ssh + +sudo umount ${target}1 +sleep 1 + +echo "Done with the boot sector." +echo "" + + +# ------------------- Step 2 - Prepare File System Sector ------------------- + +sudo mkdir -p /mnt +sudo mount ${target}2 /mnt +read -p "Enter a hostname for this device (leave blank to skip): " hostname +if [[ ! -z $hostname ]]; then + sudo bash -c "echo ${hostname} > /etc/hostname" + echo "Hostname configured to $hostname" +fi + +sudo umount ${target}2 +sleep 1 + +echo "Done with the file system, you're ready to go!" +echo ""