You could create a bash script to run nvmflash.sh, but the sudo
part might make some of this “non-obvious”. You could also create a script which does nothing more than tell you how many lsusb
replies are for your hardware.
FYI, the “lsusb -d '0955:'
” checks all NVIDIA devices, but if you were to check for a nano (a dev kit, not sure if you have something different), is “lsusb -d '0955:7020'
”. If you are familiar with the “word count” utility (“wc
” command line), then examine that if you have four lines from “lsusb -d '0955:7020'
”, and pipe it to wc:
lsusb -d '0955:7020' | wc'
…then the occurrence of one line would show three numbers, and the first is the number of lines. If you want four occurrences, then the number should be “4
”. This is more suited to command line, but you could incorporate this into an icon if the icon is set to run in a shell and keep the shell open after running. That same shell could be set to run nvmflash.sh
if the correct number is seen.
Alternatively, you could create a custom version of nvmflash.sh
(I’d keep the original, and maybe create “custom_nvmflash.sh
” in the same directory) to stat the number of found units and proceed if correct.
The real issue with scripting is that it isn’t designed for a GUI popup. You can easily create a script which says “this number of Jetson Nanos are found in recovery mode”, but it isn’t a convenient GUI popup. There are a lot of small notification apps one can use to create a GUI popup. This URL has a discussion of a number of applications for this, the one of which I like is “zenity
” (uses GTK+ dialog), and one which is very primitive is “xmessage
”:
https://stackoverflow.com/questions/7035/how-to-show-a-gui-message-box-from-a-bash-script-in-linux
If you use a custom script which uses something like zenity
in place of stdout
echoes, then it would look very simple and clean to the person clicking the icon. An example from the URL above, modified slightly, and not yet refined (but put on multiple lines for clarity), looking only at the first lsusb
and not caring if it is a Jetson:
zenity \
--info \
--text="<span size=\"large\">First lsusb is \n$(lsusb | head -n 1).\
</span>\n\nCommand line count is \
<b>$(lsusb | head -n 1 | wc | sed -E 's/^[[:space:]]+//g' | cut -d' ' -f1)</b>\
." \
--title="lsusb results" \
--ok-label="Ok" --width=1070
Slightly simplified in terms of programming by means of environment variables, but still the same command:
LISTINGS="$(lsusb | head -n 1)" \
LCOUNT="$(echo ${LISTINGS} | wc | sed -E 's/^[[:space:]]+//g' | cut -d' ' -f1)" \
zenity \
--info \
--text="<span size=\"large\">First lsusb is \n${LISTINGS}.\
</span>\n\nCommand line count is \
<b>${LCOUNT}</b>\
." \
--title="lsusb results" \
--ok-label="Ok" --width=1070
Turning this into a list of all lsusb
results with a given vendor ID and device ID instead of a single line of lsusb
, where “0955:
” is everything NVIDIA, and “7020” is a Nano (be careful that this may not distinguish recovery mode versus just a Nano emulating a network device):
VENDOR='0955:';\
DEVICE='7020';\
IFS=$'\n' read -r -d '' -a LISTINGS < <( lsusb -d ${VENDOR}${DEVICE} && printf '\0' );\
USBCOUNT=${#LISTINGS[@]};\
zenity \
--info \
--text="<span size=\"large\">lsusb for device\n${VENDOR}${DEVICE}.\
</span>\n\nlsusb line count is \
<b>${USBCOUNT}</b>\
." \
--title="lsusb results" \
--ok-label="Ok" --width=1070
The above could easily be modified to verify the right number of Jetsons, and then to run a flash command.