From d635763430bc626aec8d844b01b2e5ad8ad54605 Mon Sep 17 00:00:00 2001 From: Zen Date: Sun, 16 Jan 2022 00:36:50 +0000 Subject: [PATCH] Added scripts for getting and writing images --- Makefile | 22 ++++++++-- README.md | 4 ++ scripts/get-image.sh | 47 ++++++++++++++++++++ init.sh => scripts/init.sh | 0 scripts/write-image.sh | 90 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 160 insertions(+), 3 deletions(-) create mode 100755 scripts/get-image.sh rename init.sh => scripts/init.sh (100%) create mode 100755 scripts/write-image.sh diff --git a/Makefile b/Makefile index 6b3d335..2b88960 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,24 @@ # This Makefile exists because it's my favorite way to simplify running groups of commands directly from the command line # # Variables -NOTHING = yet +IMAGE := raspios_lite_arm64.zip +DOWNLOAD_LINK := https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2021-11-08/2021-10-30-raspios-bullseye-arm64-lite.zip it-pretty: - @chmod +x init.sh - @./init.sh + @chmod +x scripts/init.sh + @scripts/init.sh + +it-autonomous: + @echo "soon!" + +acquisition: + @chmod +x scripts/get-image.sh + @scripts/get-image.sh + +imbuement: + @chmod +x scripts/write-image.sh + @scripts/write-image.sh + +preparations: + @echo "soon!" + diff --git a/README.md b/README.md index 8a7bc2e..0ce7209 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,7 @@ A collection of scripts for working with bare metal. ## Commands `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 imbuement` Looks for available USBs attached to the device and writes an image to it. diff --git a/scripts/get-image.sh b/scripts/get-image.sh new file mode 100755 index 0000000..c73ef14 --- /dev/null +++ b/scripts/get-image.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# Script for automatically downloading and checking the sha256sum of a RPi image + +# Variables +DOWNLOAD_LINK=https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2021-11-08/2021-10-30-raspios-bullseye-arm64-lite.zip +IMAGE=2021-10-30-raspios-bullseye-arm64-lite.zip + +mkdir -p images + +if [[ -e images/$IMAGE ]]; then + echo "Image has already been downloaded." +else + echo "Downloading Raspberry Pi OS for arm64 architecture" + curl -o images/$IMAGE $DOWNLOAD_LINK +fi + +echo "Getting sha256sum and comparing..." +cd images +curl -so image.sha256 $DOWNLOAD_LINK.sha256 +sha256sum $IMAGE > computed.sha256 +diff image.sha256 computed.sha256 + +if [[ $? -eq 0 ]]; then + echo "Image is healthy!" +else + echo "Bad sha256sum :( deleting image" + rm ../images/$IMAGE +fi + +rm *.sha256 +cd .. + +#ifeq ($(WRITABLE_BLOCK),) +## NOTE: This is not fully functional yet, not sure why +#@read -p "Remove your flash drive, and press enter to continue" +#@lsblk -pdo NAME,TRAN > current-blocks +#@read -p "Insert your writeable drive, and press enter to continue" +#@lsblk -pdo NAME,TRAN | diff current-blocks - | grep usb | awk '{print $$2}' > block.txt +#@export BLOCK=`cat block.txt` +#$(error No USB detected, wait a moment after plugging in and try again) +#else +# @read -p "the memory block to be modified is $(WRITABLE_BLOCK), ensure this is the drive you wish to write to and press enter to continue" +# @unzip -p $(IMAGE) | sudo dd of=$(WRITABLE_BLOCK) bs=4M conv=fsync status=progress +# @rm block.txt current-blocks +# endif + diff --git a/init.sh b/scripts/init.sh similarity index 100% rename from init.sh rename to scripts/init.sh diff --git a/scripts/write-image.sh b/scripts/write-image.sh new file mode 100755 index 0000000..be57455 --- /dev/null +++ b/scripts/write-image.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +# Script for writing a supplied image file to a data storage device (just usb drives for now) +# 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 img-list +i=1 +echo "" +echo -e "${ULINE}Images${NC}" +while read -u 11 line; do + echo -e "${BOLD}$i.${NC} $line" + i=$((i+1)) +done 11