#!/bin/bash #EEPROMHex='eeprom-content.GekkoScience-Compac.hex' # File used for manufacturer brand EEPROMHex='backup/eeprom-content.GekkoScience-Compac-bitshopperde.hex' SerialPrefix='GS-' # Prepended before 8-digit serial number SerialNoFile='last-serialno' # File holds the last allocated serial number if ! [ -e "${SerialNoFile}" ]; then echo "WARNING: Initializing ${SerialNoFile} file (this should only happen ONCE EVER)" >&2 echo '10000000' > "${SerialNoFile}" fi i="$(<"${SerialNoFile}")" for dev in $(lsusb | perl -nle 'm/(\d{3}).*?(\d{3}).*CP210x/ && print "$1/$2"'); do let ++i echo "$i" >"${SerialNoFile}" FullSerial="${SerialPrefix}$i" echo "Programming serial number ${FullSerial} onto device $dev ..." ./cp210x-program -m $dev -w -F "$EEPROMHex" \ --set-serial-number "${FullSerial}" done