summaryrefslogtreecommitdiff
path: root/_linux/scripts/flash_kb.sh
blob: 57d5a92081ba90fb890e2fe14fcf1e92adc4d94f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
set -euo pipefail

FIRMWARE="$1"

if [[ ! -f "$FIRMWARE" ]]; then
  echo "❌ Firmware file not found: $FIRMWARE"
  exit 1
fi

# Ask for sudo upfront
sudo -v
# Keep-alive: update existing sudo timestamp until script finishes
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &

declare -A LABELS=( ["left"]="GLV80LHBOOT" ["right"]="GLV80RHBOOT" )
declare -A MOUNTPOINTS=( ["left"]="/mnt/kb_left" ["right"]="/mnt/kb_right" )

flash_half() {
  local side="$1"
  local label="${LABELS[$side]}"
  local mount_point="${MOUNTPOINTS[$side]}"

  echo ""
  echo "⚙️  Waiting for $side half ($label) to appear in bootloader mode..."

  # Wait until device with correct label appears
  while true; do
    DEV=$(lsblk -o NAME,LABEL,PATH -nr | awk -v lbl="$label" '$2 == lbl {print $3}' || true)
    if [[ -n "$DEV" ]]; then
      echo "✅ Found $side half at $DEV"
      break
    fi
    sleep 1
  done

  sudo mkdir -p "$mount_point"
  echo "📦 Mounting $DEV to $mount_point..."
  sudo mount "$DEV" "$mount_point"

  echo "📤 Copying firmware..."
  sudo cp "$FIRMWARE" "$mount_point"/
  sync

  echo "💾 Unmounting..."
  sudo umount "$mount_point"

  echo "✅ $side half flashed successfully!"
}

flash_half "left"
flash_half "right"

echo ""
echo "🎉 Both halves flashed successfully!"