diff --git a/update.sh b/update.sh old mode 100644 new mode 100755 index 6a48254..063169d --- a/update.sh +++ b/update.sh @@ -1,18 +1,37 @@ -#!/bin/sh +#!/usr/bin/env bash -echo "put the nice!nano into bootloader, flashing in 5 seconds..." -sleep 5 -echo "flashing..." +if [ $EUID != 0 ]; then + sudo "$0" "$@" + exit $? +fi -export GH_TOKEN=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 # Read-only access to artifacts -gh run download --dir .tmp/ --repo NikodemMarek/zmk-config -n firmware +FIRMWARE_ZIP=$1 +if [ ! -f $FIRMWARE_ZIP ]; then + echo "please provide a firmware zip file" + exit 1 +fi -mkdir .tmp/nicenano/ -sudo mount /dev/sda .tmp/nicenano/ +FIRMWARE_DIR=$(mktemp -d) +echo "unpacking firmware to: $FIRMWARE_DIR" +unzip $FIRMWARE_ZIP -d $FIRMWARE_DIR -sudo rm -f .tmp/nicenano/CURRENT.UF2 -sudo cp $(find .tmp -name *left*) .tmp/nicenano/CURRENT.UF2 +FIRMWARE_FILE=$(find $FIRMWARE_DIR -name *left*) +if [ ! -f $FIRMWARE_FILE ]; then + echo "could not find firmware file" + exit 1 +fi +echo "found firmware file: $FIRMWARE_FILE" -sudo umount .tmp/nicenano/ +echo "put the nice!nano into bootloader, flashing in 5 seconds..." +sleep 5 + +echo "mounting nice!nano..." +MOUNT_DIR=$(mktemp -d) +sudo mount /dev/sda $MOUNT_DIR + +echo "flashing firmware..." +sudo cp -f $FIRMWARE_FILE $MOUNT_DIR/CURRENT.UF2 +sleep 5 -rm -rf .tmp/* +echo "unmounting nice!nano..." +sudo umount $MOUNT_DIR