Skip to content

Instantly share code, notes, and snippets.

@NewbiZ
Created September 9, 2025 05:16
Show Gist options
  • Save NewbiZ/515a0d2fe65362d1e7e7ac9cd2b6a2ec to your computer and use it in GitHub Desktop.
Save NewbiZ/515a0d2fe65362d1e7e7ac9cd2b6a2ec to your computer and use it in GitHub Desktop.
Flash corne
#!/bin/bash
REPO_ARG=(-R newbiz/zmk-config-corne-wireless)
OUT_DIR="/tmp/corne-wireless-firmware"
rm -rf "$OUT_DIR"
mkdir -p "$OUT_DIR"
command -v gh >/dev/null 2>&1 || { echo "gh not found"; exit 1; }
gh auth status >/dev/null 2>&1 || { echo "gh not authenticated"; exit 1; }
# Try to get the latest queued/in_progress run
RUN_INFO="$(
gh run list "${REPO_ARG[@]}" \
--limit 50 \
--json databaseId,status,createdAt,displayTitle \
--jq '
map(select(.status=="queued" or .status=="in_progress"))
| sort_by(.createdAt)
| reverse
| (.[0] // empty)
'
)"
# If none running, pick the most recent completed one
if [[ -z "${RUN_INFO:-}" ]]; then
echo "No job currently running, picking latest completed."
RUN_INFO="$(
gh run list "${REPO_ARG[@]}" \
--limit 1 \
--json databaseId,status,createdAt,displayTitle \
--jq '.[0]'
)"
fi
RUN_ID="$(echo "$RUN_INFO" | jq -r '.databaseId')"
RUN_NAME="$(echo "$RUN_INFO" | jq -r '.displayTitle')"
printf "%s ... " "$RUN_NAME"
# Only watch if it’s still running
RUN_STATUS="$(echo "$RUN_INFO" | jq -r '.status')"
if [[ "$RUN_STATUS" == "queued" || "$RUN_STATUS" == "in_progress" ]]; then
gh run watch "$RUN_ID" "${REPO_ARG[@]}" >/dev/null 2>&1
fi
mkdir -p "$OUT_DIR"
gh run download "$RUN_ID" "${REPO_ARG[@]}" --dir "$OUT_DIR" >/dev/null 2>&1
echo "done"
FIRMWARE_RIGHT="$OUT_DIR/firmware/corne_right nice_view_adapter nice_view-nice_nano_v2-zmk.uf2"
FIRMWARE_LEFT="$OUT_DIR/firmware/corne_left nice_view_adapter nice_view-nice_nano_v2-zmk.uf2"
function wait_umount() {
busy=true
while $busy
do
if mountpoint -q "$1"
then
sudo umount "$1" 2> /dev/null
if [ $? -eq 0 ]
then
busy=false
else
echo -n '.'
sleep 0.3
fi
else
busy=false
fi
done
}
flash_firmware() {
UUID="$1"
FIRMWARE="$2"
DISK="/dev/disk/by-id/$UUID"
MNT="/mnt/$UUID"
until [ -e "$DISK" ]
do
sleep 0.5
done
echo "Keyboard detected."
sleep 1
sudo mkdir -p "$MNT"
sudo mount "$DISK" "$MNT"
echo -n "Flashing $FIRMWARE..."
sudo cp "$FIRMWARE" "$MNT"
wait_umount "$MNT"
sudo rmdir "$MNT"
echo " done"
echo
}
echo "Plug RH 👉 keyboard to flash firmware"
flash_firmware usb-Adafruit_nRF_UF2_4D15613EBC1ECF5A-0:0 "$FIRMWARE_RIGHT"
echo "Plug LH 👈 keyboard to flash firmware"
flash_firmware usb-Adafruit_nRF_UF2_39AAEFB28247E661-0:0 "$FIRMWARE_LEFT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment