mirror of
https://github.com/Noratrieb/nixos.git
synced 2026-03-14 16:26:05 +01:00
flash
This commit is contained in:
parent
1bf865f4cf
commit
7f399354d0
4 changed files with 71 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ pkgs: {
|
|||
sl = import ./sl { inherit pkgs; };
|
||||
run = import ./run { inherit pkgs; };
|
||||
unpem = import ./unpem { inherit pkgs; };
|
||||
flash-glove80 = import ./flash-glove80 { inherit pkgs; };
|
||||
u = import ./u { inherit pkgs; };
|
||||
x = import ./x { inherit pkgs; };
|
||||
}
|
||||
|
|
|
|||
4
custom-pkgs/flash-glove80/default.nix
Normal file
4
custom-pkgs/flash-glove80/default.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{ pkgs }: pkgs.writeShellApplication {
|
||||
name = "flash-glove80";
|
||||
text = builtins.readFile ./flash.sh;
|
||||
}
|
||||
65
custom-pkgs/flash-glove80/flash.sh
Normal file
65
custom-pkgs/flash-glove80/flash.sh
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# shellcheck disable=SC2012
|
||||
image=$(ls "$HOME"/Downloads/*.uf2 --sort time | head -n1)
|
||||
image_mtime=$(stat "$image" --format "%y")
|
||||
|
||||
echo "flashing $image, last modified $image_mtime"
|
||||
|
||||
read -rp "is this correct? (y/n) "
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "prompting sudo password once to avoid needing to type it again"
|
||||
sudo true
|
||||
|
||||
wait_until_present() {
|
||||
local file="$1"
|
||||
local side_descr="$2"
|
||||
local keys="$3"
|
||||
|
||||
while [ ! -e "$file" ]; do
|
||||
echo "Glove80 $side_descr not connected, re-start it with $keys pressed"
|
||||
sleep 5
|
||||
done
|
||||
|
||||
echo "$side_descr is connected"
|
||||
}
|
||||
|
||||
flash_side() {
|
||||
local disk="$1"
|
||||
local side_descr="$2"
|
||||
|
||||
if [ ! -e "$disk" ]; then
|
||||
echo "$disk is missing, boot the glove80 while pressing PgDn+I"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local mountpoint
|
||||
mountpoint=$(mktemp -d)
|
||||
|
||||
echo "mounting $disk at $mountpoint"
|
||||
sudo mount "$disk" "$mountpoint"
|
||||
echo "copying $image to $side_descr"
|
||||
sudo cp "$image" "$mountpoint/CURRENT.UF2"
|
||||
echo "done flashing $side_descr"
|
||||
}
|
||||
|
||||
wait_and_flash() {
|
||||
local side_shorthand="$1"
|
||||
local side_descr="$2"
|
||||
local keys="$3"
|
||||
|
||||
local disk="/dev/disk/by-label/GLV80${side_shorthand}BOOT"
|
||||
|
||||
wait_until_present "$disk" "$side_descr" "$keys"
|
||||
flash_side "$disk" "$side_descr"
|
||||
}
|
||||
|
||||
wait_and_flash "RH" "right-hand side" "PgDn+I"
|
||||
wait_and_flash "LH" "left-hand side" "Magic+E"
|
||||
|
||||
echo "done flashing!"
|
||||
Loading…
Add table
Add a link
Reference in a new issue