Zen
3 years ago
5 changed files with 160 additions and 3 deletions
@ -1,8 +1,24 @@ |
|||||||
# This Makefile exists because it's my favorite way to simplify running groups of commands directly from the command line
|
# This Makefile exists because it's my favorite way to simplify running groups of commands directly from the command line
|
||||||
#
|
#
|
||||||
# Variables
|
# 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: |
it-pretty: |
||||||
@chmod +x init.sh
|
@chmod +x scripts/init.sh
|
||||||
@./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!"
|
||||||
|
|
||||||
|
@ -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 |
||||||
|
|
@ -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<usb-list |
||||||
|
echo "" |
||||||
|
|
||||||
|
read -p "Which USB would you like to write to? type a number, or 'c' to cancel: " -n1 dev |
||||||
|
echo "" |
||||||
|
echo "" |
||||||
|
case $dev in |
||||||
|
c) |
||||||
|
exit |
||||||
|
;; |
||||||
|
[1-9]) |
||||||
|
target=$(sed "${dev}q;d" usb-list | awk '{print $1}') |
||||||
|
echo -e "Writing image to: ${GREEN}$target${NC}" |
||||||
|
;; |
||||||
|
*) |
||||||
|
echo "lol what the heck does $dev mean" |
||||||
|
exit |
||||||
|
;; |
||||||
|
esac |
||||||
|
|
||||||
|
# ------------------- Step 2 - Select Image ------------------- |
||||||
|
|
||||||
|
ls images > 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<img-list |
||||||
|
echo "" |
||||||
|
read -p "Which image do you want to use? type a number, or 'c' to cancel: " -n1 img |
||||||
|
echo "" |
||||||
|
echo "" |
||||||
|
case $img in |
||||||
|
c) |
||||||
|
exit |
||||||
|
;; |
||||||
|
[1-9]) |
||||||
|
image=$(sed "${img}q;d" img-list | awk '{print $1}') |
||||||
|
echo -e "Okay, we're using ${BLUE}$image${NC} as the image file." |
||||||
|
;; |
||||||
|
*) |
||||||
|
echo "lol what the heck does $img mean" |
||||||
|
exit |
||||||
|
;; |
||||||
|
esac |
||||||
|
|
||||||
|
# ------------------- Step 3 - Write Image to USB ------------------- |
||||||
|
|
||||||
|
echo "" |
||||||
|
echo -e "Getting ready to write ${GREEN}$image${NC} to ${BLUE}$target${NC}" |
||||||
|
echo "" |
||||||
|
read -p "Press Enter to continue (ctrl+C to cancel):" |
||||||
|
unzip -p "images/$image" | sudo dd of=$target bs=4M conv=fsync status=progress |
||||||
|
|
||||||
|
# Leaving this line in if I want to debug and not necessarily run dd all the time |
||||||
|
# echo "unzip -p \"images/$image\" | sudo dd of=$target bs=4M conv=fsync status=progress" |
||||||
|
|
||||||
|
|
||||||
|
# ------------------- Step 4 - Cleaning Up ------------------- |
||||||
|
|
||||||
|
rm usb-list |
||||||
|
rm img-list |
||||||
|
echo "" |
||||||
|
echo -e "${BOLD}Congratulations!${NC} Write operation complete." |
||||||
|
echo "You probably want to prepare the USB with 'make preparations' before you use it." |
Loading…
Reference in new issue