Browse Source

Added 'make preparations'

main
Zen 3 years ago
parent
commit
5acef754fe
  1. 3
      Makefile
  2. 6
      README.md
  3. 82
      scripts/prep-rpi-usb.sh

3
Makefile

@ -20,5 +20,6 @@ imbuement:
@scripts/write-image.sh @scripts/write-image.sh
preparations: preparations:
@echo "soon!" @chmod +x scripts/prep-rpi-usb.sh
@scripts/prep-rpi-usb.sh

6
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. `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. 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)

82
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<usb-list
echo ""
read -p "Which one is your Raspberry Pi USB? type a number, or 'c' to cancel: " -n1 usb
echo ""
echo ""
case $usb in
c)
exit
;;
[1-9])
target=$(sed "${usb}q;d" usb-list | awk '{print $1}')
echo -e "Targeting ${GREEN}$target${NC} for configuration."
;;
*)
echo "lol what the heck does $usb mean"
exit
;;
esac
rm usb-list
echo ""
# ------------------- Step 2 - Prepare Boot Sector -------------------
sudo mkdir -p /mnt
sudo mount ${target}1 /mnt
read -p "Do you plan on using this RPi as part of a cluster? (y/n): " -n1 boot
case $boot in
y | Y)
echo "Configuring for clustering..."
sudo bash -c "echo cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory >> /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 ""
Loading…
Cancel
Save