#!/bin/bash# adjust for cpu # -j 16 gave best result on a hyperthreaded quad core core i7LIMIT=10THREADS="-j 16"KMAP=iso_split_rshiftecho"We need sudo later"sudo ls 2>&1 /dev/nullfunctionwait_bootloader{echo"Waiting for Bootloader..."localSTARTTIME=$(date +"%s")localREMIND=0localEXEC=dfu-programmerlocalTARGET=atmega32u4whiletruedosudo$EXEC$TARGET get > /dev/null 2>&1[$?-eq 0 ]&&breakENDTIME=$(date +"%s")DURATION=$(($ENDTIME-$STARTTIME))if[$REMIND-eq 0 -a$DURATION-gt$LIMIT]thenecho"Did you forget to press the reset button?"REMIND=1fisleep 1done}make cleanmake KEYMAP=${KMAP}${THREADS}if[[$?-eq 0 ]]thenecho"please trigger flashing!"wait_bootloadersudo make KEYMAP=${KMAP} dfu ${THREADS}elseecho"make failed"exit 77fi