From 2007322162363403949c2b1a57c4f16ed683e2e4 Mon Sep 17 00:00:00 2001 From: Deividas Petraitis Date: Thu, 25 Apr 2024 11:27:35 +0300 Subject: [PATCH] Introduce side parameter in the flash.sh script. --- scripts/flash.sh | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/scripts/flash.sh b/scripts/flash.sh index 5dabbe9..1d1b435 100755 --- a/scripts/flash.sh +++ b/scripts/flash.sh @@ -1,25 +1,48 @@ #!/bin/sh +# Function to display help message +display_help() { + echo "Usage: $0 [side]" + echo "Mounts the nice!nano MCU for flashing the specified side (left or right) of the keyboard." + echo "Example: $0 left" + exit 1 +} + # Check if the script is run as root -if [[ $UID != 0 ]]; then - echo "Please run this script with sudo:" - echo "sudo $0 $*" +if [[ $EUID -ne 0 ]]; then + echo "Please run this script as root" exit 1 fi +# Check if argument is provided +if [ $# -eq 0 ]; then + echo "Error: No side specified" + display_help +fi + +# Check if the argument is valid +if [ "$1" != "left" ] && [ "$1" != "right" ]; then + echo "Error: Invalid side specified" + display_help +fi + # Give some time to the user to mount the device. sleep 5 # Create a mount point mkdir -p /media/usb -# Right -sudo mount /dev/disk/by-id/usb-Adafruit_nRF_UF2_97A391CF144F945C-0:0 /media/usb -sudo cp ./build/right/zephyr/zmk.uf2 /media/usb/ +# Mount the USB drive based on the specified side +if [ "$1" == "left" ]; then + sudo mount /dev/disk/by-id/usb-Adafruit_nRF_UF2_38F4230B63B3DA6E-0:0 /media/usb + sudo cp build/left/zephyr/zmk.uf2 /media/usb/ +elif [ "$1" == "right" ]; then + sudo mount /dev/disk/by-id/usb-Adafruit_nRF_UF2_97A391CF144F945C-0:0 /media/usb + sudo cp build/right/zephyr/zmk.uf2 /media/usb/ +fi -# Left -# sudo mount /dev/disk/by-id/usb-Adafruit_nRF_UF2_38F4230B63B3DA6E-0:0 /media/usb -# sudo cp build/left/zephyr/zmk.uf2 /media/usb/ +# End message +echo "Flashing to $1 side completed." -# sudo cp build/reset/zephyr/zmk.uf2 /media/usb -# sudo cp ~/Downloads/zmk_clear.uf2 /media/usb +# Exit script +exit 0